mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Add support for single-parameter calls to scale() and shear(), both in Matrix and Item (supporting optional center parameter too).
This commit is contained in:
parent
99bde74a10
commit
b0b9594f1e
3 changed files with 27 additions and 8 deletions
|
@ -95,10 +95,15 @@ var Matrix = Base.extend({
|
|||
* @return {Matrix} This affine transform.
|
||||
*/
|
||||
scale: function(sx, sy /* | scale */, center) {
|
||||
// TODO: Make single scale parameter work with center points!
|
||||
// Check arguments.length and typeof arguments[1], if object, assume
|
||||
// scale
|
||||
center = Point.read(arguments, 2);
|
||||
if (arguments.length < 2 || typeof sy == 'object') {
|
||||
// sx is the single scale parameter, representing both sx and sy
|
||||
// Read center first from argument 1, then set sy = sx (thus
|
||||
// modifing the content of argument 1!)
|
||||
center = Point.read(arguments, 1);
|
||||
sy = sx;
|
||||
} else {
|
||||
center = Point.read(arguments, 2);
|
||||
}
|
||||
if (center)
|
||||
this.translate(center);
|
||||
this._m00 *= sx;
|
||||
|
@ -150,7 +155,13 @@ var Matrix = Base.extend({
|
|||
* @return {Matrix} This affine transform.
|
||||
*/
|
||||
shear: function(shx, shy, center) {
|
||||
center = Point.read(arguments, 2);
|
||||
// See #scale() for explanation of this:
|
||||
if (arguments.length < 2 || typeof shy == 'object') {
|
||||
center = Point.read(arguments, 1);
|
||||
sy = sx;
|
||||
} else {
|
||||
center = Point.read(arguments, 2);
|
||||
}
|
||||
if (center)
|
||||
this.translate(center);
|
||||
var m00 = this._m00;
|
||||
|
|
|
@ -507,8 +507,11 @@ Item = Base.extend({
|
|||
* @see Matrix#scale(double, double, Point center)
|
||||
*/
|
||||
scale: function(sx, sy /* | scale */, center) {
|
||||
// TODO: Make single scale parameter work, and still pass center
|
||||
// or position
|
||||
// See Matrix#scale for explanation of this:
|
||||
if (arguments.length < 2 || typeof sy == 'object') {
|
||||
center = sy;
|
||||
sy = sx;
|
||||
}
|
||||
this.transform(new Matrix().scale(sx, sy, center || this.position));
|
||||
},
|
||||
|
||||
|
@ -535,6 +538,11 @@ Item = Base.extend({
|
|||
*/
|
||||
shear: function(shx, shy, center) {
|
||||
// TODO: Add support for center back to Scriptographer too!
|
||||
// See Matrix#scale for explanation of this:
|
||||
if (arguments.length < 2 || typeof sy == 'object') {
|
||||
center = shy;
|
||||
shy = shx;
|
||||
}
|
||||
this.transform(new Matrix().shear(shx, shy, center || this.position));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@ test('path.bounds', function() {
|
|||
comparePoints(path.position, { x: 192.66016, y: 349.13184 });
|
||||
|
||||
// Scale the path by 0.5 and check bounds
|
||||
path.scale(0.5, 0.5);
|
||||
path.scale(0.5);
|
||||
compareRectangles(path.bounds, { x: 153.7437, y: 312.09976, width: 77.8329, height: 74.06381 });
|
||||
|
||||
// Move the path to another position and check bounds
|
||||
|
|
Loading…
Reference in a new issue