EaselJSのMatrex2D.scale()メソッドの演算に誤りがある [Edit]

EaselJSのMatrix2D.scale()メソッドの演算に誤りがあるようです。デフォルト(単位行列)のMatrix2Dオブジェクトを90度回転してみます。すると、Matrex2D.scale()メソッドで拡大も縮小もできなくなります。

The calculation of Matrix2D.scale() method in the EaselJS library might be incorrect. Try to rotate the identity matrix of Matrix2D object by 90 degrees. Then it cannot be enlarged nor reduced with the Matrix2D.scale() method anymore.

たとえば、以下のコードはオブジェクト(myBitmap)を90度回転します。すると、Matrix2D.scale()メソッドを呼出しても、Matrix2Dオブジェクトに変化が加わらなくなります。したがって、オブジェクトは拡大しません(図001)。

For example, the code below rotate an object (myBitmap) by 90 degrees by the Matrix2D.rotate() method. Then the Matrix2D.scale() method call will not have no effect to the Matrix2D object. It will not enlarge the object (figure 001).


var matrix = new createjs.Matrix2D();
matrix.rotate(Math.PI / 2);
// [Matrix2D (a=6.123233995736766e-17 b=1 c=-1 d=6.123233995736766e-17 tx=0 ty=0)]
matrix.scale(2, 2);  // no effect.
// [Matrix2D (a=1.2246467991473532e-16 b=1 c=-1 d=1.2246467991473532e-16 tx=0 ty=0)]
matrix.decompose(myBitmap);

図001■オブジェクトは90度回転しても拡大しない
Example of Sound classExample of Sound class
figure 001: An object is rotated by 90 degree but is not enlarged.

単位行列を90度回転すると、成分値は以下のようになります。

After 90 degrees rotation of the identity matrix, its factors will come to be as follows:

a=0 b=1 c=-1 d=0 tx=0 ty=0

ところが、Matrix2D.scale()メソッドの実装をみると、成分bとcについては演算が行われていません。そのため、変換行列は変わらないのです。

However, the implementation of the Matrix2D.scale() method does not calculate factors b and c. Therefore, the matrix will not be changed.

当面は、Matrix2D.scale()メソッドの替わりにMatrix2D.prependTransform()を用いることが考えられます。ご参考までに、テストコードをjsdo.itに掲げました。この問題についてさらに詳しくは「EaselJSのMatrix2D.scale()メソッドを他の変換の後に呼出すと正しく伸縮されない」をお読みください。

For the time being, the Matrix2D.prependTransform() method would be better to use as alternative of the Matrix2D.scale(). My test code is uploaded to jsdo.it for your reference.


// matrix.scale(2, 2);
matrix.prependTransform(0, 0, 2, 2);

コメント

この記事にコメントを書く

記事に対するテクニカルな質問はご遠慮ください(利用規約)。

その他の記事