2013-02-08 22:38:32 -05:00
|
|
|
/*
|
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2014-01-03 19:47:16 -05:00
|
|
|
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
2013-02-08 22:38:32 -05:00
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
module('Matrix');
|
2013-02-09 02:02:20 -05:00
|
|
|
test('Decomposition: rotate()', function() {
|
2013-02-09 02:25:10 -05:00
|
|
|
function testAngle(a, ea) {
|
|
|
|
var m = new Matrix().rotate(a),
|
|
|
|
s = 'new Matrix().rotate(' + a + ')';
|
|
|
|
equals(m.getRotation(), Base.pick(ea, a),
|
|
|
|
s + '.getRotation()',
|
|
|
|
Numerical.TOLERANCE);
|
2014-02-22 07:09:26 -05:00
|
|
|
comparePoints(m.getScaling(), new Point(1, 1),
|
2013-02-09 02:25:10 -05:00
|
|
|
s + '.getScaling()');
|
2013-02-09 02:02:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
testAngle(0);
|
|
|
|
testAngle(1);
|
|
|
|
testAngle(45);
|
|
|
|
testAngle(90);
|
|
|
|
testAngle(135);
|
|
|
|
testAngle(180);
|
|
|
|
testAngle(270, -90);
|
|
|
|
testAngle(-1);
|
|
|
|
testAngle(-45);
|
|
|
|
testAngle(-90);
|
|
|
|
testAngle(-135);
|
|
|
|
testAngle(-180);
|
|
|
|
testAngle(-270, 90);
|
2013-02-08 22:38:32 -05:00
|
|
|
});
|
|
|
|
|
2013-02-09 02:02:20 -05:00
|
|
|
test('Decomposition: scale()', function() {
|
2013-02-09 02:25:10 -05:00
|
|
|
function testScale(sx, sy, ex, ey, ea) {
|
|
|
|
var m = new Matrix().scale(sx, sy),
|
|
|
|
s = 'new Matrix().scale(' + sx + ', ' + sy + ')';
|
|
|
|
equals(m.getRotation(), ea || 0,
|
2014-02-24 06:19:03 -05:00
|
|
|
s + '.getRotation()',
|
|
|
|
Numerical.TOLERANCE);
|
|
|
|
comparePoints(m.getScaling(), new Point(Base.pick(ex, sx),
|
|
|
|
Base.pick(ey, sy)),
|
|
|
|
s + '.getScaling()');
|
2013-02-09 02:02:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
testScale(1, 1);
|
2013-02-09 02:25:10 -05:00
|
|
|
testScale(1, -1, -1, 1, -180); // Decomposing results in correct flipping
|
2013-02-09 02:02:20 -05:00
|
|
|
testScale(-1, 1);
|
2013-02-09 02:25:10 -05:00
|
|
|
testScale(-1, -1, 1, 1, 180); // Decomposing results in correct flipping
|
2013-02-09 02:02:20 -05:00
|
|
|
testScale(2, 4);
|
2013-02-09 02:25:10 -05:00
|
|
|
testScale(2, -4, -2, 4, -180); // Decomposing results in correct flipping
|
2013-02-09 02:02:20 -05:00
|
|
|
testScale(4, 2);
|
|
|
|
testScale(-4, 2);
|
2013-02-09 02:25:10 -05:00
|
|
|
testScale(-4, -4, 4, 4, 180); // Decomposing results in correct flipping
|
2013-02-09 02:02:20 -05:00
|
|
|
});
|
2013-02-08 22:38:32 -05:00
|
|
|
|
2013-02-09 02:02:20 -05:00
|
|
|
test('Decomposition: rotate() & scale()', function() {
|
2013-02-09 02:25:10 -05:00
|
|
|
function testAngleAndScale(sx, sy, a, ex, ey, ea) {
|
|
|
|
var m = new Matrix().scale(sx, sy).rotate(a),
|
|
|
|
s = 'new Matrix().scale(' + sx + ', ' + sy + ').rotate(' + a + ')';
|
|
|
|
equals(m.getRotation(), ea || a,
|
2014-02-24 06:19:03 -05:00
|
|
|
s + '.getRotation()',
|
|
|
|
Numerical.TOLERANCE);
|
|
|
|
comparePoints(m.getScaling(), new Point(Base.pick(ex, sx),
|
|
|
|
Base.pick(ey, sy)),
|
|
|
|
s + '.getScaling()');
|
2013-02-09 02:25:10 -05:00
|
|
|
}
|
2013-02-08 22:38:32 -05:00
|
|
|
|
2013-02-09 02:25:10 -05:00
|
|
|
testAngleAndScale(2, 4, 45);
|
|
|
|
testAngleAndScale(2, -4, 45, -2, 4, -135);
|
|
|
|
testAngleAndScale(-2, 4, 45);
|
|
|
|
testAngleAndScale(-2, -4, 45, 2, 4, -135);
|
2013-02-08 22:38:32 -05:00
|
|
|
});
|