mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-20 18:10:03 -04:00
Implement proper index independent argument list reading of basic types.
Implemented for Point, Size, Rectangle and Color.
This commit is contained in:
parent
6f2ff18fa1
commit
30374ae3b4
13 changed files with 260 additions and 190 deletions
src/basic
|
@ -128,24 +128,20 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
|
|||
* @param {Point} [center] The center for the scaling transformation
|
||||
* @return {Matrix} This affine transform
|
||||
*/
|
||||
scale: function(/* scale | */ hor, ver, center) {
|
||||
if (arguments.length < 2 || typeof ver === 'object') {
|
||||
// hor is the single scale parameter, representing both hor and ver
|
||||
// Read center first from argument 1, then set ver = hor (thus
|
||||
// modifing the content of argument 1!)
|
||||
center = Point.read(arguments, 1);
|
||||
ver = hor;
|
||||
} else {
|
||||
center = Point.read(arguments, 2);
|
||||
}
|
||||
if (center)
|
||||
this.translate(center);
|
||||
this._a *= hor;
|
||||
this._c *= hor;
|
||||
this._b *= ver;
|
||||
this._d *= ver;
|
||||
if (center)
|
||||
this.translate(center.negate());
|
||||
scale: function(scale, center) {
|
||||
// Do not modify scale, center, since that would arguments of which
|
||||
// we're reading from!
|
||||
var _scale = Point.read(arguments),
|
||||
_center = Point.read(arguments);
|
||||
// TODO: Isn't center always set this way??
|
||||
if (_center)
|
||||
this.translate(_center);
|
||||
this._a *= _scale.x;
|
||||
this._c *= _scale.x;
|
||||
this._b *= _scale.y;
|
||||
this._d *= _scale.y;
|
||||
if (_center)
|
||||
this.translate(_center.negate());
|
||||
return this;
|
||||
},
|
||||
|
||||
|
@ -168,7 +164,8 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
|
|||
*/
|
||||
translate: function(point) {
|
||||
point = Point.read(arguments);
|
||||
var x = point.x, y = point.y;
|
||||
var x = point.x,
|
||||
y = point.y;
|
||||
this._tx += x * this._a + y * this._b;
|
||||
this._ty += x * this._c + y * this._d;
|
||||
return this;
|
||||
|
@ -219,24 +216,21 @@ var Matrix = this.Matrix = Base.extend(/** @lends Matrix# */{
|
|||
* @param {Point} [center] The center for the shear transformation
|
||||
* @return {Matrix} This affine transform
|
||||
*/
|
||||
shear: function(/* point | */ hor, ver, center) {
|
||||
// See #scale() for explanation of this:
|
||||
if (arguments.length < 2 || typeof ver === 'object') {
|
||||
center = Point.read(arguments, 1);
|
||||
ver = hor;
|
||||
} else {
|
||||
center = Point.read(arguments, 2);
|
||||
}
|
||||
if (center)
|
||||
this.translate(center);
|
||||
shear: function(point, center) {
|
||||
// Do not modify point, center, since that would arguments of which
|
||||
// we're reading from!
|
||||
var _point = Point.read(arguments),
|
||||
_center = Point.read(arguments);
|
||||
if (_center)
|
||||
this.translate(_center);
|
||||
var a = this._a,
|
||||
c = this._c;
|
||||
this._a += ver * this._b;
|
||||
this._c += ver * this._d;
|
||||
this._b += hor * a;
|
||||
this._d += hor * c;
|
||||
if (center)
|
||||
this.translate(center.negate());
|
||||
this._a += _point.y * this._b;
|
||||
this._c += _point.y * this._d;
|
||||
this._b += _point.x * a;
|
||||
this._d += _point.x * c;
|
||||
if (_center)
|
||||
this.translate(_center.negate());
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue