2011-07-01 06:17:45 -04:00
|
|
|
/*
|
2013-01-28 21:03:27 -05:00
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
2011-07-01 06:17:45 -04:00
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2015-12-27 12:09:25 -05:00
|
|
|
* Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
|
2014-01-03 19:47:16 -05:00
|
|
|
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
2011-07-01 06:17:45 -04:00
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2011-05-29 14:54:43 -04:00
|
|
|
test('Item Order', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var line = new Path();
|
|
|
|
line.add([0, 0], [100, 100]);
|
|
|
|
line.name = 'line';
|
2011-05-29 14:54:43 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
var circle = new Path.Circle([50, 50], 50);
|
|
|
|
circle.name = 'circle';
|
2011-05-29 14:54:43 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
var group = new Group([circle]);
|
|
|
|
group.name = 'group';
|
2011-05-29 14:54:43 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
|
|
|
return circle.isAbove(line);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return line.isBelow(circle);
|
|
|
|
}, true);
|
2011-05-29 14:54:43 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
|
|
|
return group.isAbove(line);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return line.isBelow(group);
|
|
|
|
}, true);
|
2011-05-29 14:54:43 -04:00
|
|
|
|
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
|
|
|
return group.isAncestor(circle);
|
|
|
|
}, true);
|
2011-05-29 14:54:43 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
|
|
|
return circle.isDescendant(group);
|
|
|
|
}, true);
|
2011-05-29 14:54:43 -04:00
|
|
|
|
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
|
|
|
return group.isAbove(circle);
|
|
|
|
}, false);
|
2011-05-29 14:54:43 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
|
|
|
return group.isBelow(circle);
|
|
|
|
}, false);
|
2011-05-29 14:54:43 -04:00
|
|
|
});
|
2012-03-13 09:54:23 -04:00
|
|
|
|
2013-07-21 19:13:27 -04:00
|
|
|
test('Item#insertAbove(item) / Item#insertBelow(item)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var item0, item1, item2;
|
|
|
|
|
|
|
|
function testMove(command, indexes) {
|
|
|
|
paper.project.clear();
|
|
|
|
new Layer();
|
|
|
|
item0 = new Group();
|
|
|
|
item1 = new Group();
|
|
|
|
item2 = new Group();
|
|
|
|
command();
|
2014-12-28 08:33:22 -05:00
|
|
|
var str = getFunctionMessage(command);
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(item0.index, indexes[0], str + ': item0.index');
|
|
|
|
equals(item1.index, indexes[1], str + ': item1.index');
|
|
|
|
equals(item2.index, indexes[2], str + ': item2.index');
|
|
|
|
}
|
|
|
|
|
2014-12-28 08:33:22 -05:00
|
|
|
testMove(function() { item0.insertBelow(item0); }, [0,1,2]);
|
|
|
|
testMove(function() { item0.insertBelow(item1); }, [0,1,2]);
|
|
|
|
testMove(function() { item0.insertBelow(item2); }, [1,0,2]);
|
|
|
|
testMove(function() { item1.insertBelow(item0); }, [1,0,2]);
|
|
|
|
testMove(function() { item1.insertBelow(item1); }, [0,1,2]);
|
|
|
|
testMove(function() { item1.insertBelow(item2); }, [0,1,2]);
|
|
|
|
|
|
|
|
testMove(function() { item2.insertBelow(item0); }, [1,2,0]);
|
|
|
|
testMove(function() { item2.insertBelow(item1); }, [0,2,1]);
|
|
|
|
testMove(function() { item2.insertBelow(item2); }, [0,1,2]);
|
|
|
|
|
|
|
|
testMove(function() { item0.insertAbove(item0); }, [0,1,2]);
|
|
|
|
testMove(function() { item0.insertAbove(item1); }, [1,0,2]);
|
|
|
|
testMove(function() { item0.insertAbove(item2); }, [2,0,1]);
|
|
|
|
testMove(function() { item1.insertAbove(item0); }, [0,1,2]);
|
|
|
|
testMove(function() { item1.insertAbove(item1); }, [0,1,2]);
|
|
|
|
testMove(function() { item1.insertAbove(item2); }, [0,2,1]);
|
|
|
|
testMove(function() { item2.insertAbove(item0); }, [0,2,1]);
|
|
|
|
testMove(function() { item2.insertAbove(item1); }, [0,1,2]);
|
|
|
|
testMove(function() { item2.insertAbove(item2); }, [0,1,2]);
|
2012-03-13 09:54:23 -04:00
|
|
|
});
|