Rename internal Matrix transform parameters to (a, c, b, d, tx, ty), expoes values through Matrix#getValues() and improve documentation.

This commit is contained in:
Jürg Lehni 2011-07-31 15:26:09 +01:00
parent b14a294430
commit 42c9f91279

View file

@ -32,8 +32,8 @@
* by considering them to be a column vector and multiplying the coordinate * by considering them to be a column vector and multiplying the coordinate
* vector by the matrix according to the following process: * vector by the matrix according to the following process:
* <pre> * <pre>
* [ x ] [ m00 m01 m02 ] [ x ] [ m00 * x + m01 * y + m02 ] * [ x ] [ a b tx ] [ x ] [ a * x + b * y + tx ]
* [ y ] = [ m10 m11 m12 ] [ y ] = [ m10 * x + m11 * y + m12 ] * [ y ] = [ c d ty ] [ y ] = [ c * x + d * y + ty ]
* [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ] * [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ]
* </pre> * </pre>
* *
@ -45,12 +45,12 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
/** /**
* Creates a 2D affine transform. * Creates a 2D affine transform.
* *
* @param {Number} m00 The m00 coordinate of the transform. * @param {Number} a The scaleX coordinate of the transform
* @param {Number} m10 The m10 coordinate of the transform. * @param {Number} c The shearY coordinate of the transform
* @param {Number} m01 The m01 coordinate of the transform. * @param {Number} b The shearX coordinate of the transform
* @param {Number} m11 The m11 coordinate of the transform. * @param {Number} d The scaleY coordinate of the transform
* @param {Number} m02 The m02 coordinate of the transform. * @param {Number} tx The translateX coordinate of the transform
* @param {Number} m12 The m12 coordinate of the transform. * @param {Number} ty The translateY coordinate of the transform
*/ */
initialize: function(arg) { initialize: function(arg) {
var count = arguments.length, var count = arguments.length,
@ -59,16 +59,15 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
this.set.apply(this, arguments); this.set.apply(this, arguments);
} else if (count == 1) { } else if (count == 1) {
if (arg instanceof Matrix) { if (arg instanceof Matrix) {
this.set(arg._m00, arg._m10, arg._m01, this.set(arg._a, arg._c, arg._b, arg._d, arg._tx, arg._ty);
arg._m11, arg._m02, arg._m12);
} else if (Array.isArray(arg)) { } else if (Array.isArray(arg)) {
this.set.apply(this, arg); this.set.apply(this, arg);
} else { } else {
ok = false; ok = false;
} }
} else if (count == 0) { } else if (count == 0) {
this._m00 = this._m11 = 1; this._a = this._d = 1;
this._m10 = this._m01 = this._m02 = this._m12 = 0; this._c = this._b = this._tx = this._ty = 0;
} else { } else {
ok = false; ok = false;
} }
@ -80,28 +79,28 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
* @return {Matrix} A copy of this transform. * @return {Matrix} A copy of this transform.
*/ */
clone: function() { clone: function() {
return Matrix.create(this._m00, this._m10, this._m01, return Matrix.create(this._a, this._c, this._b, this._d,
this._m11, this._m02, this._m12); this._tx, this._ty);
}, },
/** /**
* Sets this transform to the matrix specified by the 6 values. * Sets this transform to the matrix specified by the 6 values.
* *
* @param {Number} m00 The m00 coordinate of the transform. * @param {Number} a The scaleX coordinate of the transform
* @param {Number} m10 The m10 coordinate of the transform. * @param {Number} c The shearY coordinate of the transform
* @param {Number} m01 The m01 coordinate of the transform. * @param {Number} b The shearX coordinate of the transform
* @param {Number} m11 The m11 coordinate of the transform. * @param {Number} d The scaleY coordinate of the transform
* @param {Number} m02 The m02 coordinate of the transform. * @param {Number} tx The translateX coordinate of the transform
* @param {Number} m12 The m12 coordinate of the transform. * @param {Number} ty The translateY coordinate of the transform
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
set: function(m00, m10, m01, m11, m02, m12) { set: function(a, c, b, d, tx, ty) {
this._m00 = m00; this._a = a;
this._m10 = m10; this._c = c;
this._m01 = m01; this._b = b;
this._m11 = m11; this._d = d;
this._m02 = m02; this._tx = tx;
this._m12 = m12; this._ty = ty;
return this; return this;
}, },
@ -110,21 +109,19 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
* *
* @name Matrix#scale * @name Matrix#scale
* @function * @function
* @param {Number} scale The scaling factor. * @param {Number} scale The scaling factor
* @param {Point} [center] The center for the scaling * @param {Point} [center] The center for the scaling transformation
* transformation. * @return {Matrix} This affine transform
* @return {Matrix} This affine transform.
*/ */
/** /**
* Concatentates this transform with a scaling transformation. * Concatentates this transform with a scaling transformation.
* *
* @name Matrix#scale * @name Matrix#scale
* @function * @function
* @param {Number} hor The horizontal scaling factor. * @param {Number} hor The horizontal scaling factor
* @param {Number} ver The vertical scaling factor. * @param {Number} ver The vertical scaling factor
* @param {Point} [center] The center for the scaling * @param {Point} [center] The center for the scaling transformation
* transformation. * @return {Matrix} This affine transform
* @return {Matrix} This affine transform.
*/ */
scale: function(hor, ver /* | scale */, center) { scale: function(hor, ver /* | scale */, center) {
if (arguments.length < 2 || typeof ver === 'object') { if (arguments.length < 2 || typeof ver === 'object') {
@ -138,10 +135,10 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
} }
if (center) if (center)
this.translate(center); this.translate(center);
this._m00 *= hor; this._a *= hor;
this._m10 *= hor; this._c *= hor;
this._m01 *= ver; this._b *= ver;
this._m11 *= ver; this._d *= ver;
if (center) if (center)
this.translate(center.negate()); this.translate(center.negate());
return this; return this;
@ -152,23 +149,23 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
* *
* @name Matrix#translate * @name Matrix#translate
* @function * @function
* @param {Point} point The vector to translate by. * @param {Point} point The vector to translate by
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
/** /**
* Concatentates this transform with a translate transformation. * Concatentates this transform with a translate transformation.
* *
* @name Matrix#translate * @name Matrix#translate
* @function * @function
* @param {Number} dx The distance to translate in the x direction. * @param {Number} dx The distance to translate in the x direction
* @param {Number} dy The distance to translate in the y direction. * @param {Number} dy The distance to translate in the y direction
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
translate: function(point) { translate: function(point) {
point = Point.read(arguments); point = Point.read(arguments);
var x = point.x, y = point.y; var x = point.x, y = point.y;
this._m02 += x * this._m00 + y * this._m01; this._tx += x * this._a + y * this._b;
this._m12 += x * this._m10 + y * this._m11; this._ty += x * this._c + y * this._d;
return this; return this;
}, },
@ -178,9 +175,9 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
* *
* @name Matrix#rotate * @name Matrix#rotate
* @function * @function
* @param {Number} angle The angle of rotation measured in degrees. * @param {Number} angle The angle of rotation measured in degrees
* @param {Point} center The anchor point to rotate around. * @param {Point} center The anchor point to rotate around
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
/** /**
* Concatentates this transform with a rotation transformation around an * Concatentates this transform with a rotation transformation around an
@ -188,10 +185,10 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
* *
* @name Matrix#rotate * @name Matrix#rotate
* @function * @function
* @param {Number} angle The angle of rotation measured in degrees. * @param {Number} angle The angle of rotation measured in degrees
* @param {Number} x The x coordinate of the anchor point. * @param {Number} x The x coordinate of the anchor point
* @param {Number} y The y coordinate of the anchor point. * @param {Number} y The y coordinate of the anchor point
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
rotate: function(angle, center) { rotate: function(angle, center) {
return this.concatenate( return this.concatenate(
@ -203,19 +200,19 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
* *
* @name Matrix#shear * @name Matrix#shear
* @function * @function
* @param {Point} point The shear factor in x and y direction. * @param {Point} point The shear factor in x and y direction
* @param {Point} [center] The center for the shear transformation. * @param {Point} [center] The center for the shear transformation
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
/** /**
* Concatentates this transform with a shear transformation. * Concatentates this transform with a shear transformation.
* *
* @name Matrix#shear * @name Matrix#shear
* @function * @function
* @param {Number} hor The horizontal shear factor. * @param {Number} hor The horizontal shear factor
* @param {Number} ver The vertical shear factor. * @param {Number} ver The vertical shear factor
* @param {Point} [center] The center for the shear transformation. * @param {Point} [center] The center for the shear transformation
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
shear: function(hor, ver, center) { shear: function(hor, ver, center) {
// See #scale() for explanation of this: // See #scale() for explanation of this:
@ -227,12 +224,12 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
} }
if (center) if (center)
this.translate(center); this.translate(center);
var m00 = this._m00; var a = this._a,
var m10 = this._m10; c = this._c;
this._m00 += ver * this._m01; this._a += ver * this._b;
this._m10 += ver * this._m11; this._c += ver * this._d;
this._m01 += hor * m00; this._b += hor * a;
this._m11 += hor * m10; this._d += hor * c;
if (center) if (center)
this.translate(center.negate()); this.translate(center.negate());
return this; return this;
@ -243,96 +240,104 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
*/ */
toString: function() { toString: function() {
var format = Base.formatNumber; var format = Base.formatNumber;
return '[[' + [format(this._m00), format(this._m01), return '[[' + [format(this._a), format(this._b),
format(this._m02)].join(', ') + '], [' format(this._tx)].join(', ') + '], ['
+ [format(this._m10), format(this._m11), + [format(this._c), format(this._d),
format(this._m12)].join(', ') + ']]'; format(this._ty)].join(', ') + ']]';
}, },
/** /**
* The scaling factor in the x-direction (m00). * The scaling factor in the x-direction ({@code a}).
* *
* @name Matrix#scaleX * @name Matrix#scaleX
* @type Number * @type Number
*/ */
/** /**
* The scaling factor in the y-direction (m11). * The scaling factor in the y-direction ({@code d}).
* *
* @name Matrix#scaleY * @name Matrix#scaleY
* @type Number * @type Number
*/ */
/** /**
* The translation in the x-direction (m02). * @return {Number} The shear factor in the x-direction ({@code b}).
*
* @name Matrix#translateX
* @type Number
*/
/**
* The translation in the y-direction (m12).
*
* @name Matrix#translateY
* @type Number
*/
/**
* @return {Number} The shear factor in the x-direction (m01).
* *
* @name Matrix#shearX * @name Matrix#shearX
* @type Number * @type Number
*/ */
/** /**
* @return {Number} The shear factor in the y-direction (m10). * @return {Number} The shear factor in the y-direction ({@code c}).
* *
* @name Matrix#shearY * @name Matrix#shearY
* @type Number * @type Number
*/ */
/**
* The translation in the x-direction ({@code tx}).
*
* @name Matrix#translateX
* @type Number
*/
/**
* The translation in the y-direction ({@code ty}).
*
* @name Matrix#translateY
* @type Number
*/
/**
* The transform values as an array, in the same sequence as they are passed
* to {@link #initialize(a, c, b, d, tx, ty)}.
*
* @type Number[]
* @bean
*/
getValues: function() {
return [ this._a, this._c, this._b, this._d, this._tx, this._ty ];
},
/** /**
* Concatenates an affine transform to this transform. * Concatenates an affine transform to this transform.
* *
* @param {Matrix} mx The transform to concatenate. * @param {Matrix} mx The transform to concatenate
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
concatenate: function(mx) { concatenate: function(mx) {
var m0 = this._m00, var a = this._a,
m1 = this._m01; b = this._b,
this._m00 = mx._m00 * m0 + mx._m10 * m1; c = this._c,
this._m01 = mx._m01 * m0 + mx._m11 * m1; d = this._d;
this._m02 += mx._m02 * m0 + mx._m12 * m1; this._a = mx._a * a + mx._c * b;
this._b = mx._b * a + mx._d * b;
m0 = this._m10; this._tx += mx._tx * a + mx._ty * b;
m1 = this._m11; this._c = mx._a * c + mx._c * d;
this._m10 = mx._m00 * m0 + mx._m10 * m1; this._d = mx._b * c + mx._d * d;
this._m11 = mx._m01 * m0 + mx._m11 * m1; this._ty += mx._tx * c + mx._ty * d;
this._m12 += mx._m02 * m0 + mx._m12 * m1;
return this; return this;
}, },
/** /**
* Pre-concatenates an affine transform to this transform. * Pre-concatenates an affine transform to this transform.
* *
* @param {Matrix} mx The transform to preconcatenate. * @param {Matrix} mx The transform to preconcatenate
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
preConcatenate: function(mx) { preConcatenate: function(mx) {
var m0 = this._m00, var a = this._a,
m1 = this._m10; b = this._b,
this._m00 = mx._m00 * m0 + mx._m01 * m1; c = this._c,
this._m10 = mx._m10 * m0 + mx._m11 * m1; d = this._d,
tx = this._tx,
m0 = this._m01; ty = this._ty;
m1 = this._m11; this._a = mx._a * a + mx._b * c;
this._m01 = mx._m00 * m0 + mx._m01 * m1; this._c = mx._c * a + mx._d * c;
this._m11 = mx._m10 * m0 + mx._m11 * m1; this._b = mx._a * b + mx._b * d;
this._d = mx._c * b + mx._d * d;
m0 = this._m02; this._tx = mx._a * tx + mx._b * ty + mx._tx;
m1 = this._m12; this._ty = mx._c * tx + mx._d * ty + mx._ty;
this._m02 = mx._m00 * m0 + mx._m01 * m1 + mx._m02;
this._m12 = mx._m10 * m0 + mx._m11 * m1 + mx._m12;
return this; return this;
}, },
@ -341,16 +346,15 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
* the result. If an array is transformed, the the result is stored into a * the result. If an array is transformed, the the result is stored into a
* destination array. * destination array.
* *
* @param {Point} point The point to be transformed. * @param {Point} point The point to be transformed
*
* @param {Number[]} src The array containing the source points * @param {Number[]} src The array containing the source points
* as x, y value pairs. * as x, y value pairs
* @param {Number} srcOff The offset to the first point to be transformed. * @param {Number} srcOff The offset to the first point to be transformed
* @param {Number[]} dst The array into which to store the transformed * @param {Number[]} dst The array into which to store the transformed
* point pairs. * point pairs
* @param {Number} dstOff The offset of the location of the first * @param {Number} dstOff The offset of the location of the first
* transformed point in the destination array. * transformed point in the destination array
* @param {Number} numPts The number of points to tranform. * @param {Number} numPts The number of points to tranform
*/ */
transform: function(/* point | */ src, srcOff, dst, dstOff, numPts) { transform: function(/* point | */ src, srcOff, dst, dstOff, numPts) {
return arguments.length < 5 return arguments.length < 5
@ -369,8 +373,8 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
if (!dest) if (!dest)
dest = new Point(Point.dont); dest = new Point(Point.dont);
return dest.set( return dest.set(
x * this._m00 + y * this._m01 + this._m02, x * this._a + y * this._b + this._tx,
x * this._m10 + y * this._m11 + this._m12, x * this._c + y * this._d + this._ty,
dontNotify dontNotify
); );
}, },
@ -381,8 +385,8 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
while (i < srcEnd) { while (i < srcEnd) {
var x = src[i++]; var x = src[i++];
var y = src[i++]; var y = src[i++];
dst[j++] = x * this._m00 + y * this._m01 + this._m02; dst[j++] = x * this._a + y * this._b + this._tx;
dst[j++] = x * this._m10 + y * this._m11 + this._m12; dst[j++] = x * this._c + y * this._d + this._ty;
} }
return dst; return dst;
}, },
@ -418,60 +422,61 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
}, },
/** /**
* @return {Number} The determinant of this transform. * @return {Number} The determinant of this transform
*/ */
getDeterminant: function() { getDeterminant: function() {
return this._m00 * this._m11 - this._m01 * this._m10; return this._a * this._d - this._b * this._c;
}, },
getTranslation: function() { getTranslation: function() {
return new Point(this._m02, this._m12); return new Point(this._tx, this._ty);
}, },
getScaling: function() { getScaling: function() {
var hor = Math.sqrt(this._m00 * this._m00 + this._m10 * this._m10), var hor = Math.sqrt(this._a * this._a + this._c * this._c),
ver = Math.sqrt(this._m01 * this._m01 + this._m11 * this._m11); ver = Math.sqrt(this._b * this._b + this._d * this._d);
return new Point(this._m00 < 0 ? -hor : hor, this._m01 < 0 ? -ver : ver); return new Point(this._a < 0 ? -hor : hor, this._b < 0 ? -ver : ver);
}, },
/** /**
* @return {Number} The rotation angle of the matrix. If a non-uniform * Returns the rotation angle of the matrix. If a non-uniform
* rotation is applied as a result of a shear() or scale() command, * rotation is applied as a result of a shear() or scale() command,
* undefined is returned, as the resulting transformation cannot be * undefined is returned, as the resulting transformation cannot be
* expressed in one rotation angle. * expressed in one rotation angle
* @return {Number} The rotation angle of the matrix
*/ */
getRotation: function() { getRotation: function() {
var angle1 = -Math.atan2(this._m01, this._m11), var angle1 = -Math.atan2(this._b, this._d),
angle2 = Math.atan2(this._m10, this._m00); angle2 = Math.atan2(this._c, this._a);
return Math.abs(angle1 - angle2) < Numerical.TOLERANCE return Math.abs(angle1 - angle2) < Numerical.TOLERANCE
? angle1 * 180 / Math.PI : undefined; ? angle1 * 180 / Math.PI : undefined;
}, },
/** /**
* @return {Boolean} Whether this transform is the identity transform. * @return {Boolean} Whether this transform is the identity transform
*/ */
isIdentity: function() { isIdentity: function() {
return this._m00 == 1 && this._m10 == 0 && this._m01 == 0 && return this._a == 1 && this._c == 0 && this._b == 0 && this._d == 1
this._m11 == 1 && this._m02 == 0 && this._m12 == 0; && this._tx == 0 && this._ty == 0;
}, },
/** /**
* Returns whether the transform is invertible. A transform is not * Returns whether the transform is invertible. A transform is not
* invertible if the determinant is 0 or any value is non-finite or NaN. * invertible if the determinant is 0 or any value is non-finite or NaN.
* *
* @return {Boolean} Whether the transform is invertible. * @return {Boolean} Whether the transform is invertible
*/ */
isInvertible: function() { isInvertible: function() {
var det = this.getDeterminant(); var det = this.getDeterminant();
return isFinite(det) && det != 0 && isFinite(this._m02) return isFinite(det) && det != 0 && isFinite(this._tx)
&& isFinite(this._m12); && isFinite(this._ty);
}, },
/** /**
* Checks whether the matrix is singular or not. Singular matrices cannot be * Checks whether the matrix is singular or not. Singular matrices cannot be
* inverted. * inverted.
* *
* @return {Boolean} Whether the matrix is singular. * @return {Boolean} Whether the matrix is singular
*/ */
isSingular: function() { isSingular: function() {
return !this.isInvertible(); return !this.isInvertible();
@ -483,33 +488,33 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
* returned. * returned.
* *
* @return {Matrix} The inverted matrix, or {@code null }, if the matrix is * @return {Matrix} The inverted matrix, or {@code null }, if the matrix is
* singular. * singular
*/ */
createInverse: function() { createInverse: function() {
var det = this.getDeterminant(); var det = this.getDeterminant();
if (isFinite(det) && det != 0 && isFinite(this._m02) if (isFinite(det) && det != 0 && isFinite(this._tx)
&& isFinite(this._m12)) { && isFinite(this._ty)) {
return Matrix.create( return Matrix.create(
this._m11 / det, this._d / det,
-this._m10 / det, -this._c / det,
-this._m01 / det, -this._b / det,
this._m00 / det, this._a / det,
(this._m01 * this._m12 - this._m11 * this._m02) / det, (this._b * this._ty - this._d * this._tx) / det,
(this._m10 * this._m02 - this._m00 * this._m12) / det); (this._c * this._tx - this._a * this._ty) / det);
} }
return null; return null;
}, },
createShiftless: function() { createShiftless: function() {
return Matrix.create(this._m00, this._m10, this._m01, this._m11, 0, 0); return Matrix.create(this._a, this._c, this._b, this._d, 0, 0);
}, },
/** /**
* Sets this transform to a scaling transformation. * Sets this transform to a scaling transformation.
* *
* @param {Number} hor The horizontal scaling factor. * @param {Number} hor The horizontal scaling factor
* @param {Number} ver The vertical scaling factor. * @param {Number} ver The vertical scaling factor
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
setToScale: function(hor, ver) { setToScale: function(hor, ver) {
return this.set(hor, 0, 0, ver, 0, 0); return this.set(hor, 0, 0, ver, 0, 0);
@ -518,9 +523,9 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
/** /**
* Sets this transform to a translation transformation. * Sets this transform to a translation transformation.
* *
* @param {Number} dx The distance to translate in the x direction. * @param {Number} dx The distance to translate in the x direction
* @param {Number} dy The distance to translate in the y direction. * @param {Number} dy The distance to translate in the y direction
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
setToTranslation: function(delta) { setToTranslation: function(delta) {
delta = Point.read(arguments); delta = Point.read(arguments);
@ -530,9 +535,9 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
/** /**
* Sets this transform to a shearing transformation. * Sets this transform to a shearing transformation.
* *
* @param {Number} hor The horizontal shear factor. * @param {Number} hor The horizontal shear factor
* @param {Number} ver The vertical shear factor. * @param {Number} ver The vertical shear factor
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
setToShear: function(hor, ver) { setToShear: function(hor, ver) {
return this.set(1, ver, hor, 1, 0, 0); return this.set(1, ver, hor, 1, 0, 0);
@ -541,10 +546,10 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
/** /**
* Sets this transform to a rotation transformation. * Sets this transform to a rotation transformation.
* *
* @param {Number} angle The angle of rotation measured in degrees. * @param {Number} angle The angle of rotation measured in degrees
* @param {Number} x The x coordinate of the anchor point. * @param {Number} x The x coordinate of the anchor point
* @param {Number} y The y coordinate of the anchor point. * @param {Number} y The y coordinate of the anchor point
* @return {Matrix} This affine transform. * @return {Matrix} This affine transform
*/ */
setToRotation: function(angle, center) { setToRotation: function(angle, center) {
center = Point.read(arguments, 1); center = Point.read(arguments, 1);
@ -566,25 +571,23 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
*/ */
applyToContext: function(ctx, reset) { applyToContext: function(ctx, reset) {
ctx[reset ? 'setTransform' : 'transform']( ctx[reset ? 'setTransform' : 'transform'](
this._m00, this._m10, this._m01, this._a, this._c, this._b, this._d, this._tx, this._ty);
this._m11, this._m02, this._m12
);
return this; return this;
}, },
statics: /** @lends Matrix */{ statics: /** @lends Matrix */{
// See Point.create() // See Point.create()
create: function(m00, m10, m01, m11, m02, m12) { create: function(a, c, b, d, tx, ty) {
return new Matrix(Matrix.dont).set(m00, m10, m01, m11, m02, m12); return new Matrix(Matrix.dont).set(a, c, b, d, tx, ty);
}, },
/** /**
* Creates a transform representing a scaling transformation. * Creates a transform representing a scaling transformation.
* *
* @param {Number} hor The horizontal scaling factor. * @param {Number} hor The horizontal scaling factor
* @param {Number} ver The vertical scaling factor. * @param {Number} ver The vertical scaling factor
* @return {Matrix} A transform representing a scaling * @return {Matrix} A transform representing a scaling
* transformation. * transformation
*/ */
getScaleInstance: function(hor, ver) { getScaleInstance: function(hor, ver) {
var mx = new Matrix(); var mx = new Matrix();
@ -594,10 +597,10 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
/** /**
* Creates a transform representing a translation transformation. * Creates a transform representing a translation transformation.
* *
* @param {Number} dx The distance to translate in the x direction. * @param {Number} dx The distance to translate in the x direction
* @param {Number} dy The distance to translate in the y direction. * @param {Number} dy The distance to translate in the y direction
* @return {Matrix} A transform representing a translation * @return {Matrix} A transform representing a translation
* transformation. * transformation
*/ */
getTranslateInstance: function(delta) { getTranslateInstance: function(delta) {
var mx = new Matrix(); var mx = new Matrix();
@ -607,9 +610,9 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
/** /**
* Creates a transform representing a shearing transformation. * Creates a transform representing a shearing transformation.
* *
* @param {Number} hor The horizontal shear factor. * @param {Number} hor The horizontal shear factor
* @param {Number} ver The vertical shear factor. * @param {Number} ver The vertical shear factor
* @return {Matrix} A transform representing a shearing transformation. * @return {Matrix} A transform representing a shearing transformation
*/ */
getShearInstance: function(hor, ver, center) { getShearInstance: function(hor, ver, center) {
var mx = new Matrix(); var mx = new Matrix();
@ -619,10 +622,10 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
/** /**
* Creates a transform representing a rotation transformation. * Creates a transform representing a rotation transformation.
* *
* @param {Number} angle The angle of rotation measured in degrees. * @param {Number} angle The angle of rotation measured in degrees
* @param {Number} x The x coordinate of the anchor point. * @param {Number} x The x coordinate of the anchor point
* @param {Number} y The y coordinate of the anchor point. * @param {Number} y The y coordinate of the anchor point
* @return {Matrix} A transform representing a rotation transformation. * @return {Matrix} A transform representing a rotation transformation
*/ */
getRotateInstance: function(angle, center) { getRotateInstance: function(angle, center) {
var mx = new Matrix(); var mx = new Matrix();
@ -631,12 +634,12 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
} }
}, new function() { }, new function() {
return Base.each({ return Base.each({
scaleX: '_m00', scaleX: '_a',
scaleY: '_m11', scaleY: '_d',
translateX: '_m02', translateX: '_tx',
translateY: '_m12', translateY: '_ty',
shearX: '_m01', shearX: '_b',
shearY: '_m10' shearY: '_c'
}, function(prop, name) { }, function(prop, name) {
name = Base.capitalize(name); name = Base.capitalize(name);
this['get' + name] = function() { this['get' + name] = function() {