2011-07-01 12:17:45 +02:00
|
|
|
/*
|
2013-01-28 18:03:27 -08:00
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
2011-07-01 12:17:45 +02:00
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2018-12-27 16:13:01 +09:00
|
|
|
* Copyright (c) 2011 - 2019, Juerg Lehni & Jonathan Puckey
|
2018-11-10 16:19:34 +09:00
|
|
|
* http://scratchdisk.com/ & https://puckey.studio/
|
2011-07-01 12:17:45 +02:00
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2016-01-27 19:57:07 +01:00
|
|
|
QUnit.module('Compound Path');
|
2011-02-17 16:00:20 +01:00
|
|
|
|
2016-07-19 10:09:55 +02:00
|
|
|
test('moveTo() / lineTo()', function() {
|
2014-08-16 19:24:54 +02:00
|
|
|
var path = new CompoundPath();
|
2011-02-17 16:00:20 +01:00
|
|
|
|
2014-08-16 19:24:54 +02:00
|
|
|
var lists = [
|
|
|
|
[new Point(279, 151), new Point(149, 151), new Point(149, 281), new Point(279, 281)],
|
|
|
|
[new Point(319, 321), new Point(109, 321), new Point(109, 111), new Point(319, 111)]
|
|
|
|
];
|
2011-02-17 16:00:20 +01:00
|
|
|
|
2014-08-16 19:24:54 +02:00
|
|
|
for (var i = 0; i < lists.length; i++) {
|
|
|
|
var list = lists[i];
|
|
|
|
for (var j = 0; j < list.length; j++) {
|
2016-07-22 13:46:24 +02:00
|
|
|
path[!j ? 'moveTo' : 'lineTo'](list[j]);
|
2014-08-16 19:24:54 +02:00
|
|
|
}
|
|
|
|
}
|
2011-02-17 16:00:20 +01:00
|
|
|
|
2014-08-16 19:24:54 +02:00
|
|
|
path.fillColor = 'black';
|
2011-07-07 16:09:02 +02:00
|
|
|
|
2014-08-16 19:24:54 +02:00
|
|
|
equals(function() {
|
|
|
|
return path.children.length;
|
|
|
|
}, 2);
|
2011-05-15 19:09:34 +01:00
|
|
|
});
|
2011-05-15 19:10:12 +01:00
|
|
|
|
2016-07-21 15:21:45 +02:00
|
|
|
test('CompoundPath#reorient()', function() {
|
|
|
|
var path1 = new Path.Rectangle([300, 300], [100, 100]);
|
2014-08-16 19:24:54 +02:00
|
|
|
var path2 = new Path.Rectangle([50, 50], [200, 200]);
|
2016-07-21 15:21:45 +02:00
|
|
|
var path3 = new Path.Rectangle([0, 0], [500, 500]);
|
2011-05-15 19:10:12 +01:00
|
|
|
|
2014-08-16 19:24:54 +02:00
|
|
|
equals(function() {
|
|
|
|
return path1.clockwise;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path2.clockwise;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path3.clockwise;
|
|
|
|
}, true);
|
2011-05-15 19:10:12 +01:00
|
|
|
|
2016-07-21 15:21:45 +02:00
|
|
|
var compound = new CompoundPath({
|
|
|
|
children: [path1, path2, path3],
|
|
|
|
}).reorient();
|
2011-05-15 19:10:12 +01:00
|
|
|
|
2014-08-16 19:24:54 +02:00
|
|
|
equals(function() {
|
|
|
|
return compound.lastChild == path3;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return compound.firstChild == path1;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path1.clockwise;
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return path2.clockwise;
|
2016-07-21 15:21:45 +02:00
|
|
|
}, false);
|
2014-08-16 19:24:54 +02:00
|
|
|
equals(function() {
|
|
|
|
return path3.clockwise;
|
|
|
|
}, true);
|
2014-04-06 13:48:03 +02:00
|
|
|
});
|