2013-02-08 22:38:32 -05:00
|
|
|
/*
|
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2020-05-23 16:24:42 -04:00
|
|
|
* Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
|
|
|
|
* http://juerglehni.com/ & https://puckey.studio/
|
2013-02-08 22:38:32 -05:00
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2016-01-27 13:57:07 -05:00
|
|
|
QUnit.module('Matrix');
|
|
|
|
|
2013-02-09 02:02:20 -05:00
|
|
|
test('Decomposition: rotate()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
function testAngle(a, ea) {
|
|
|
|
var m = new Matrix().rotate(a),
|
|
|
|
s = 'new Matrix().rotate(' + a + ')';
|
|
|
|
equals(m.getRotation(), Base.pick(ea, a),
|
2015-09-13 07:43:50 -04:00
|
|
|
s + '.getRotation()');
|
2014-12-28 08:59:48 -05:00
|
|
|
equals(m.getScaling(), new Point(1, 1),
|
2014-08-16 13:24:54 -04:00
|
|
|
s + '.getScaling()');
|
|
|
|
}
|
2013-02-09 02:02:20 -05:00
|
|
|
|
2014-08-16 13:24:54 -04: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() {
|
2014-08-16 13:24:54 -04: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,
|
2015-09-13 07:43:50 -04:00
|
|
|
s + '.getRotation()');
|
2014-12-28 08:59:48 -05:00
|
|
|
equals(m.getScaling(), new Point(Base.pick(ex, sx), Base.pick(ey, sy)),
|
2014-08-16 13:24:54 -04:00
|
|
|
s + '.getScaling()');
|
|
|
|
}
|
2013-02-09 02:02:20 -05:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
testScale(1, 1);
|
2016-02-14 04:59:57 -05:00
|
|
|
testScale(1, -1);
|
|
|
|
testScale(-1, 1, 1, -1, -180); // Decomposing results in correct flipping
|
|
|
|
testScale(-1, -1, 1, 1, -180); // Decomposing results in correct flipping
|
2014-08-16 13:24:54 -04:00
|
|
|
testScale(2, 4);
|
2016-02-14 04:59:57 -05:00
|
|
|
testScale(2, -4);
|
2014-08-16 13:24:54 -04:00
|
|
|
testScale(4, 2);
|
2016-02-14 04:59:57 -05:00
|
|
|
testScale(-4, 2, 4, -2, -180); // Decomposing results in correct flipping
|
|
|
|
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
|
|
|
|
2016-02-14 04:59:57 -05:00
|
|
|
test('Decomposition: scale() & rotate()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
function testAngleAndScale(sx, sy, a, ex, ey, ea) {
|
2016-02-14 04:59:57 -05:00
|
|
|
var m = new Matrix().rotate(a).scale(sx, sy),
|
2014-08-16 13:24:54 -04:00
|
|
|
s = 'new Matrix().scale(' + sx + ', ' + sy + ').rotate(' + a + ')';
|
|
|
|
equals(m.getRotation(), ea || a,
|
2015-09-13 07:43:50 -04:00
|
|
|
s + '.getRotation()');
|
2014-12-28 08:59:48 -05:00
|
|
|
equals(m.getScaling(), new Point(Base.pick(ex, sx), Base.pick(ey, sy)),
|
2014-08-16 13:24:54 -04:00
|
|
|
s + '.getScaling()');
|
|
|
|
}
|
2013-02-08 22:38:32 -05:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
testAngleAndScale(2, 4, 45);
|
2016-02-14 04:59:57 -05:00
|
|
|
testAngleAndScale(2, -4, 45);
|
|
|
|
testAngleAndScale(-2, 4, 45, 2, -4, -135);
|
2014-08-16 13:24:54 -04:00
|
|
|
testAngleAndScale(-2, -4, 45, 2, 4, -135);
|
2013-02-08 22:38:32 -05:00
|
|
|
});
|