Clean up Matrix constructor.

This commit is contained in:
Jürg Lehni 2011-07-25 09:15:35 +01:00
parent 68ba8e25e4
commit 2c1fdc0744

View file

@ -52,24 +52,25 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
* @param {Number} m02 The m02 coordinate of the transform. * @param {Number} m02 The m02 coordinate of the transform.
* @param {Number} m12 The m12 coordinate of the transform. * @param {Number} m12 The m12 coordinate of the transform.
*/ */
initialize: function(m00, m10, m01, m11, m02, m12) { initialize: function(arg) {
var ok = true; var count = arguments.length,
if (arguments.length == 6) { ok = true;
this.set(m00, m10, m01, m11, m02, m12); if (count == 6) {
} else if (arguments.length == 1) { this.set.apply(this, arguments);
if (m00 instanceof Matrix) { } else if (count == 1) {
this.set(m00._m00, m00._m10, m00._m01, if (arg instanceof Matrix) {
m00._m11, m00._m02, m00._m12); this.set(arg._m00, arg._m10, arg._m01,
} else if (Array.isArray(m00)) { arg._m11, arg._m02, arg._m12);
this.set.apply(this, m00); } else if (Array.isArray(arg)) {
this.set.apply(this, arg);
} else { } else {
ok = false; ok = false;
} }
} else if (arguments.length > 0) { } else if (count == 0) {
ok = false;
} else {
this._m00 = this._m11 = 1; this._m00 = this._m11 = 1;
this._m10 = this._m01 = this._m02 = this._m12 = 0; this._m10 = this._m01 = this._m02 = this._m12 = 0;
} else {
ok = false;
} }
if (!ok) if (!ok)
throw new Error('Unsupported matrix parameters'); throw new Error('Unsupported matrix parameters');