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/
|
|
|
|
*
|
2020-05-23 16:24:42 -04:00
|
|
|
* Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
|
|
|
|
* http://juerglehni.com/ & https://puckey.studio/
|
2011-07-01 06:17:45 -04:00
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2016-01-27 13:57:07 -05:00
|
|
|
QUnit.module('Item');
|
2011-02-11 12:50:26 -05:00
|
|
|
|
2011-05-16 08:33:15 -04:00
|
|
|
test('copyTo(project)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var project = paper.project;
|
|
|
|
var path = new Path();
|
|
|
|
var secondDoc = new Project();
|
|
|
|
var copy = path.copyTo(secondDoc);
|
|
|
|
equals(function() {
|
|
|
|
return secondDoc.activeLayer.children.indexOf(copy) != -1;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.children.indexOf(copy) == -1;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return copy != path;
|
|
|
|
}, true);
|
2011-02-12 11:43:51 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('copyTo(layer)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var project = paper.project;
|
|
|
|
var path = new Path();
|
|
|
|
var layer = new Layer();
|
|
|
|
var copy = path.copyTo(layer);
|
|
|
|
equals(function() {
|
|
|
|
return layer.children.indexOf(copy) != -1;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return project.layers[0].children.indexOf(copy) == -1;
|
|
|
|
}, true);
|
2011-02-12 11:43:51 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('clone()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var project = paper.project;
|
|
|
|
var path = new Path();
|
|
|
|
var copy = path.clone();
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.children.length;
|
|
|
|
}, 2);
|
|
|
|
equals(function() {
|
|
|
|
return path != copy;
|
|
|
|
}, true);
|
2011-02-12 11:43:51 -05:00
|
|
|
});
|
|
|
|
|
2011-06-17 10:58:22 -04:00
|
|
|
test('addChild(item)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var project = paper.project;
|
|
|
|
var path = new Path();
|
|
|
|
project.activeLayer.addChild(path);
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.children.length;
|
|
|
|
}, 1);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2013-03-10 10:35:33 -04:00
|
|
|
test('setting item.parent', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var layer1 = paper.project.activeLayer;
|
|
|
|
var layer2 = new Layer();
|
|
|
|
layer1.activate();
|
|
|
|
var group = new Group();
|
|
|
|
|
|
|
|
var path = new Path();
|
|
|
|
equals(function() {
|
|
|
|
return path.parent === layer1;
|
|
|
|
}, true, 'Path is a child of layer1 because it is active');
|
|
|
|
|
|
|
|
path.parent = layer2;
|
|
|
|
equals(function() {
|
|
|
|
return path.parent === layer2;
|
|
|
|
}, true, 'The parent of path was set to layer2');
|
|
|
|
|
|
|
|
path.parent = group;
|
|
|
|
equals(function() {
|
|
|
|
return path.parent === group;
|
|
|
|
}, true, 'The parent of path was set to group');
|
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return layer2.children.indexOf(path) === -1;
|
|
|
|
}, true, 'The path is no longer a child of layer2');
|
|
|
|
|
|
|
|
var path2 = new Path({
|
|
|
|
parent: group
|
|
|
|
});
|
|
|
|
equals(function() {
|
|
|
|
return path2.parent === group;
|
|
|
|
}, true, 'setting the parent in the constructor');
|
|
|
|
equals(function() {
|
|
|
|
return group.children.indexOf(path2) == 1;
|
|
|
|
}, true, 'the index of path2 is 1, because group already contains path from before');
|
2013-03-10 10:35:33 -04:00
|
|
|
});
|
|
|
|
|
2011-09-18 04:38:16 -04:00
|
|
|
test('item.parent / item.isChild / item.isParent / item.layer', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var project = paper.project;
|
|
|
|
var secondDoc = new Project();
|
|
|
|
var path = new Path();
|
|
|
|
project.activeLayer.addChild(path);
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.children.indexOf(path) != -1;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path.layer == project.activeLayer;
|
|
|
|
}, true);
|
|
|
|
secondDoc.activeLayer.addChild(path);
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.isChild(path);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return path.layer == secondDoc.activeLayer;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path.isParent(project.activeLayer);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return secondDoc.activeLayer.isChild(path);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path.isParent(secondDoc.activeLayer);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.children.indexOf(path) == -1;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return secondDoc.activeLayer.children.indexOf(path) === 0;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2014-09-27 16:49:32 -04:00
|
|
|
test('item.remove()', function() {
|
|
|
|
var project = paper.project;
|
|
|
|
var path = new Path();
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.children.length;
|
|
|
|
}, 1);
|
|
|
|
path.remove();
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.children.length;
|
|
|
|
}, 0);
|
|
|
|
var group = new Group(path);
|
|
|
|
equals(function() {
|
|
|
|
return group.children.length;
|
|
|
|
}, 1);
|
|
|
|
path.remove();
|
|
|
|
equals(function() {
|
|
|
|
return group.children.length;
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2016-02-23 05:55:03 -05:00
|
|
|
|
|
|
|
test('item.addChildren() / item.removeChildren()', function() {
|
|
|
|
var project = paper.project,
|
|
|
|
layer = project.activeLayer,
|
|
|
|
path1 = new Path({ insert: false }),
|
|
|
|
path2 = new Path({ insert: false, name: 'path2' });
|
|
|
|
|
|
|
|
layer.addChildren([path1, path2]);
|
|
|
|
equals(function() { return path1.index; }, 0);
|
|
|
|
equals(function() { return path2.index; }, 1);
|
|
|
|
equals(function() { return path1.parent === layer; }, true);
|
|
|
|
equals(function() { return path2.parent === layer; }, true);
|
|
|
|
equals(function() { return layer.children['path2'] === path2; }, true);
|
|
|
|
layer.removeChildren();
|
|
|
|
equals(function() { return path1.index; }, undefined);
|
|
|
|
equals(function() { return path2.index; }, undefined);
|
|
|
|
equals(function() { return path1.parent; }, null);
|
|
|
|
equals(function() { return path2.parent; }, null);
|
|
|
|
equals(function() { return layer.children['path2'] === undefined; }, true);
|
|
|
|
|
|
|
|
layer.children = [path1, path2];
|
|
|
|
equals(function() { return path1.index; }, 0);
|
|
|
|
equals(function() { return path2.index; }, 1);
|
|
|
|
equals(function() { return path1.parent === layer; }, true);
|
|
|
|
equals(function() { return path2.parent === layer; }, true);
|
|
|
|
equals(function() { return layer.children['path2'] === path2; }, true);
|
|
|
|
layer.children = [];
|
|
|
|
equals(function() { return path1.index; }, undefined);
|
|
|
|
equals(function() { return path2.index; }, undefined);
|
|
|
|
equals(function() { return path1.parent; }, null);
|
|
|
|
equals(function() { return path2.parent; }, null);
|
|
|
|
equals(function() { return layer.children['path2'] === undefined; }, true);
|
|
|
|
});
|
|
|
|
|
2011-02-11 12:50:26 -05:00
|
|
|
test('item.lastChild / item.firstChild', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var project = paper.project;
|
2016-07-22 17:29:33 -04:00
|
|
|
var path1 = new Path();
|
|
|
|
var path2 = new Path();
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return project.activeLayer.firstChild == path1;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return project.activeLayer.lastChild == path2;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2014-09-27 16:50:22 -04:00
|
|
|
test('item.nextSibling / item.previousSibling', function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
var path1 = new Path();
|
|
|
|
var path2 = new Path();
|
2014-09-27 16:50:22 -04:00
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path1.previousSibling == null;
|
2014-09-27 16:50:22 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path1.nextSibling == path2;
|
2014-09-27 16:50:22 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path2.previousSibling == path1;
|
2014-09-27 16:50:22 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path2.nextSibling == null;
|
2014-09-27 16:50:22 -04:00
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
2014-09-27 16:52:37 -04:00
|
|
|
test('item.replaceWith(other)', function() {
|
|
|
|
var project = paper.project;
|
2016-07-22 17:29:33 -04:00
|
|
|
var path1 = new Path();
|
|
|
|
var path2 = new Path();
|
|
|
|
var path3 = new Path();
|
2014-09-27 16:52:37 -04:00
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.children.length;
|
|
|
|
}, 3);
|
2016-07-22 17:29:33 -04:00
|
|
|
equals(function() {
|
|
|
|
return path1.replaceWith(path2) == path2;
|
|
|
|
}, true);
|
2014-09-27 16:52:37 -04:00
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.children.length;
|
|
|
|
}, 2);
|
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path1.parent == null;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path2.previousSibling == null;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path2.nextSibling == path3;
|
2014-09-27 16:52:37 -04:00
|
|
|
}, true);
|
2016-07-22 17:29:33 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('item.replaceWith(item)', function() {
|
|
|
|
var item = new Path();
|
2014-09-27 16:52:37 -04:00
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return item.replaceWith(item) == null;
|
2014-09-27 16:52:37 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return item.getParent() != null;
|
2014-09-27 16:52:37 -04:00
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
2014-09-27 16:50:22 -04:00
|
|
|
test('item.insertChild(0, child)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var project = paper.project;
|
2016-07-22 17:29:33 -04:00
|
|
|
var path1 = new Path();
|
|
|
|
var path2 = new Path();
|
|
|
|
project.activeLayer.insertChild(0, path2);
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path2.index < path1.index;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2014-09-27 16:50:22 -04:00
|
|
|
test('item.insertAbove(other)', function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
var path1 = new Path();
|
|
|
|
var path2 = new Path();
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path2.index > path1.index;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path1.insertAbove(path2) == path1;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path2.index < path1.index;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return paper.project.activeLayer.lastChild == path1;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2014-09-27 16:50:22 -04:00
|
|
|
test('item.insertBelow(other)', function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
var path1 = new Path();
|
|
|
|
var path2 = new Path();
|
|
|
|
equals(function() {
|
|
|
|
return path2.index > path1.index;
|
|
|
|
}, true);
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path2.insertBelow(path1) == path2;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path2.index < path1.index;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return paper.project.activeLayer.lastChild == path1;
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('item.insertAbove(item)', function() {
|
|
|
|
var path = new Path();
|
|
|
|
equals(function() {
|
|
|
|
return path.insertAbove(path) == null;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path.insertBelow(path) == null;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2014-09-27 16:50:22 -04:00
|
|
|
test('item.sendToBack()', function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
var path1 = new Path();
|
|
|
|
var path2 = new Path();
|
|
|
|
path2.sendToBack();
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path2.index === 0;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2013-03-03 14:08:49 -05:00
|
|
|
});
|
|
|
|
|
2014-09-27 16:50:22 -04:00
|
|
|
test('item.bringToFront()', function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
var path1 = new Path();
|
|
|
|
var path2 = new Path();
|
|
|
|
path1.bringToFront();
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path1.index == 1;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2013-03-03 14:08:49 -05:00
|
|
|
});
|
|
|
|
|
2014-09-27 16:50:22 -04:00
|
|
|
test('item.isDescendant(other) / item.isAncestor(other)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var project = paper.project;
|
|
|
|
var path = new Path();
|
|
|
|
equals(function() {
|
|
|
|
return path.isDescendant(project.activeLayer);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.isDescendant(path);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return path.isAncestor(project.activeLayer);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.isAncestor(path);
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
// an item can't be its own descendant:
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.isDescendant(project.activeLayer);
|
|
|
|
}, false);
|
|
|
|
// an item can't be its own ancestor:
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.isAncestor(project.activeLayer);
|
|
|
|
}, false);
|
2011-02-24 12:09:48 -05:00
|
|
|
});
|
|
|
|
|
2014-09-27 16:50:22 -04:00
|
|
|
test('item.addChildren(items)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path1 = new Path(),
|
|
|
|
path2 = new Path(),
|
|
|
|
path3 = new Path(),
|
|
|
|
group = new Group([path1, path2, path3]);
|
|
|
|
|
|
|
|
function check(i1, i2, i3) {
|
|
|
|
equals(function() {
|
|
|
|
return group.children.length;
|
|
|
|
}, 3);
|
|
|
|
equals(function() {
|
|
|
|
return path1.index;
|
|
|
|
}, i1);
|
|
|
|
equals(function() {
|
|
|
|
return path2.index;
|
|
|
|
}, i2);
|
|
|
|
equals(function() {
|
|
|
|
return path3.index;
|
|
|
|
}, i3);
|
|
|
|
}
|
|
|
|
check(0, 1, 2);
|
|
|
|
group.addChild(path1);
|
|
|
|
check(2, 0, 1);
|
|
|
|
group.addChild(path2);
|
|
|
|
check(1, 2, 0);
|
|
|
|
group.addChildren([path1, path2, path3]);
|
|
|
|
check(0, 1, 2);
|
2013-03-02 01:41:58 -05:00
|
|
|
});
|
|
|
|
|
2014-09-27 16:50:22 -04:00
|
|
|
test('item.isGroupedWith(other)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path();
|
2016-07-22 17:29:33 -04:00
|
|
|
var path2 = new Path();
|
2014-08-16 13:24:54 -04:00
|
|
|
var group = new Group([path]);
|
2016-07-22 17:29:33 -04:00
|
|
|
var secondGroup = new Group([path2]);
|
2014-08-16 13:24:54 -04:00
|
|
|
|
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path.isGroupedWith(path2);
|
2014-08-16 13:24:54 -04:00
|
|
|
}, false);
|
|
|
|
secondGroup.addChild(path);
|
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path.isGroupedWith(path2);
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path.isGroupedWith(group);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return path.isDescendant(secondGroup);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return secondGroup.isDescendant(path);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return secondGroup.isDescendant(secondGroup);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return path.isGroupedWith(secondGroup);
|
|
|
|
}, false);
|
|
|
|
paper.project.activeLayer.addChild(path);
|
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path.isGroupedWith(path2);
|
2014-08-16 13:24:54 -04:00
|
|
|
}, false);
|
2016-07-22 17:29:33 -04:00
|
|
|
paper.project.activeLayer.addChild(path2);
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return path.isGroupedWith(path2);
|
2014-08-16 13:24:54 -04:00
|
|
|
}, false);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2011-02-24 13:31:07 -05:00
|
|
|
test('reverseChildren()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var project = paper.project;
|
|
|
|
var path = new Path();
|
2016-07-22 17:29:33 -04:00
|
|
|
var path2 = new Path();
|
|
|
|
var path3 = new Path();
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.firstChild == path;
|
|
|
|
}, true);
|
|
|
|
project.activeLayer.reverseChildren();
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.firstChild == path;
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
2016-07-22 17:29:33 -04:00
|
|
|
return project.activeLayer.firstChild == path3;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.lastChild == path;
|
|
|
|
}, true);
|
2011-04-21 09:57:19 -04:00
|
|
|
});
|
|
|
|
|
2011-05-16 08:33:15 -04:00
|
|
|
test('Check item#project when moving items across projects', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var doc1 = new Project();
|
|
|
|
var path = new Path();
|
|
|
|
var group = new Group();
|
|
|
|
group.addChild(new Path());
|
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return path.project == doc1;
|
|
|
|
}, true);
|
|
|
|
var doc2 = new Project();
|
|
|
|
doc2.activeLayer.addChild(path);
|
|
|
|
equals(function() {
|
|
|
|
return path.project == doc2;
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
doc2.activeLayer.addChild(group);
|
|
|
|
equals(function() {
|
|
|
|
return group.children[0].project == doc2;
|
|
|
|
}, true);
|
2011-04-21 09:57:19 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('group.selected', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path([0, 0]);
|
|
|
|
var path2 = new Path([0, 0]);
|
|
|
|
var group = new Group([path, path2]);
|
|
|
|
path.selected = true;
|
|
|
|
equals(function() {
|
|
|
|
return group.selected;
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
path.selected = false;
|
|
|
|
equals(function() {
|
|
|
|
return group.selected;
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
group.selected = true;
|
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path2.selected;
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
group.selected = false;
|
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return path2.selected;
|
|
|
|
}, false);
|
2011-05-15 13:13:55 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Check parent children object for named item', function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
var path1 = new Path({ name: 'test' });
|
|
|
|
var layer = paper.project.activeLayer;
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === path1;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2016-01-08 10:41:33 -05:00
|
|
|
var path2 = new Path({ name: 'test' });
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === path1;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
path2.remove();
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === path1;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2016-01-08 10:41:33 -05:00
|
|
|
path1.remove();
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return !layer.children['test'];
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-05-15 13:13:55 -04:00
|
|
|
});
|
|
|
|
|
2011-06-17 11:33:25 -04:00
|
|
|
test('Named child access 1', function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
var path1 = new Path({ name: 'test' });
|
|
|
|
var path2 = new Path({ name: 'test' });
|
|
|
|
var layer = paper.project.activeLayer;
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === path1;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-05-15 13:13:55 -04:00
|
|
|
|
2016-01-08 10:41:33 -05:00
|
|
|
path1.remove();
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === path2;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
path2.remove();
|
2011-05-15 13:13:55 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === undefined;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-05-15 13:13:55 -04:00
|
|
|
});
|
|
|
|
|
2016-01-08 10:41:33 -05:00
|
|
|
test('Named child access 2', function() {
|
|
|
|
var path1 = new Path({ name: 'test' });
|
|
|
|
var path2 = new Path({ name: 'test' });
|
|
|
|
var layer = paper.project.activeLayer;
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
var group = new Group();
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
group.addChild(path2);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === path1;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-06-17 11:33:25 -04:00
|
|
|
|
2016-01-08 10:41:33 -05:00
|
|
|
path1.remove();
|
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === undefined;
|
|
|
|
}, true);
|
2011-05-15 13:13:55 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return group.children['test'] === path2;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-06-17 11:33:25 -04:00
|
|
|
|
2016-01-08 10:41:33 -05:00
|
|
|
path2.remove();
|
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return group.children['test'] === undefined;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-06-17 11:33:25 -04:00
|
|
|
|
2016-01-08 10:41:33 -05:00
|
|
|
group.addChild(path2);
|
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return group.children['test'] === path2;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-06-17 11:33:25 -04:00
|
|
|
|
2016-01-08 10:41:33 -05:00
|
|
|
layer.appendTop(path2);
|
2011-05-15 13:13:55 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return group.children['test'] === undefined;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-06-17 11:33:25 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === path2;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-06-17 11:33:25 -04:00
|
|
|
|
2016-01-08 10:41:33 -05:00
|
|
|
layer.addChild(path1);
|
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === path2;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-06-17 11:33:25 -04:00
|
|
|
|
2016-01-08 10:41:33 -05:00
|
|
|
path2.remove();
|
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === path1;
|
|
|
|
}, true);
|
2011-05-15 13:13:55 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Setting name of child back to null', function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
var path1 = new Path({ name: 'test' });
|
|
|
|
var path2 = new Path({ name: 'test' });
|
|
|
|
var layer = paper.project.activeLayer;
|
2011-05-15 13:53:22 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] == path1;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-05-15 13:53:22 -04:00
|
|
|
|
2016-01-08 10:41:33 -05:00
|
|
|
path1.name = null;
|
2011-05-15 13:13:55 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] == path2;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2016-01-08 10:41:33 -05:00
|
|
|
path2.name = null;
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === undefined;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-05-15 13:13:55 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Renaming item', function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
var path = new Path({ name: 'test' });
|
2014-08-16 13:24:54 -04:00
|
|
|
path.name = 'test2';
|
2016-01-08 10:41:33 -05:00
|
|
|
var layer = paper.project.activeLayer;
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test'] === undefined;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
2016-01-08 10:41:33 -05:00
|
|
|
return layer.children['test2'] == path;
|
2014-08-16 13:24:54 -04:00
|
|
|
}, true);
|
2011-05-15 13:13:55 -04:00
|
|
|
});
|
2011-05-30 19:46:49 -04:00
|
|
|
|
|
|
|
test('Changing item#position.x', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path.Circle(new Point(50, 50), 50);
|
|
|
|
path.position.x += 5;
|
|
|
|
equals(path.position.toString(), '{ x: 55, y: 50 }',
|
|
|
|
'path.position.x += 5');
|
2011-06-21 12:42:53 -04:00
|
|
|
});
|
|
|
|
|
2012-03-01 10:39:00 -05:00
|
|
|
test('Naming a removed item', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path();
|
|
|
|
path.remove();
|
|
|
|
path.name = 'test';
|
|
|
|
equals(function() {
|
|
|
|
return path.name;
|
|
|
|
}, 'test');
|
2012-03-01 10:39:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Naming a layer', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var layer = new Layer();
|
|
|
|
layer.name = 'test';
|
|
|
|
equals(function() {
|
|
|
|
return layer.name;
|
|
|
|
}, 'test');
|
2012-03-01 10:39:00 -05:00
|
|
|
});
|
|
|
|
|
2011-06-21 12:42:53 -04:00
|
|
|
test('Cloning a linked size', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path([40, 75], [140, 75]);
|
|
|
|
var error = null;
|
|
|
|
try {
|
|
|
|
var cloneSize = path.bounds.size.clone();
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
var description = 'Cloning a linked size should not throw an error';
|
|
|
|
if (error)
|
|
|
|
description += ': ' + error;
|
|
|
|
equals(error == null, true, description);
|
2013-03-03 08:40:37 -05:00
|
|
|
});
|
|
|
|
|
2014-03-18 06:42:38 -04:00
|
|
|
test('Item#className', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(new Group().className, 'Group');
|
|
|
|
equals(new Path().className, 'Path');
|
|
|
|
equals(new CompoundPath().className, 'CompoundPath');
|
|
|
|
equals(new Raster().className, 'Raster');
|
2016-01-31 10:52:51 -05:00
|
|
|
equals(new SymbolItem().className, 'SymbolItem');
|
|
|
|
equals(new PlacedSymbol().className, 'SymbolItem'); // deprecated
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(new PointText().className, 'PointText');
|
2013-03-03 08:40:37 -05:00
|
|
|
});
|
2013-03-03 10:59:27 -05:00
|
|
|
|
|
|
|
test('Item#isInserted', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var item = new Path();
|
|
|
|
equals(item.isInserted(), true);
|
|
|
|
item.remove();
|
|
|
|
equals(item.isInserted(), false);
|
2013-03-03 10:59:27 -05:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
var group = new Group(item);
|
|
|
|
equals(item.isInserted(), true);
|
|
|
|
group.remove();
|
|
|
|
equals(item.isInserted(), false);
|
2013-03-10 09:59:53 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Item#data', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var item = new Path();
|
|
|
|
var description = 'When accessed before any data was set, a plain object is created for us';
|
|
|
|
equals(Base.isPlainObject(item.data), true, description);
|
2013-03-10 09:59:53 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
var item = new Path();
|
|
|
|
item.data.test = true;
|
|
|
|
equals(item.data.test, true, description);
|
2013-03-10 09:59:53 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
var item = new Path();
|
|
|
|
var point = new Point();
|
|
|
|
item.data.point = point;
|
|
|
|
equals(item.data.point, point, 'We can set basic types on data');
|
2013-03-10 09:59:53 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
var item = new Path();
|
|
|
|
item.data = {
|
|
|
|
testing: true
|
2016-01-08 10:41:33 -05:00
|
|
|
};
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(item.data.testing, true, 'we can set data using an object literal');
|
2013-03-10 09:59:53 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
var item = new Path({
|
|
|
|
data: {
|
|
|
|
testing: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
equals(item.data.testing, true,
|
|
|
|
'we can set data using an object literal constructor');
|
2013-03-10 09:59:53 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
// TODO: add tests to see if importing and exporting of Item#data works
|
2013-03-16 10:44:04 -04:00
|
|
|
});
|
|
|
|
|
2013-03-23 20:08:17 -04:00
|
|
|
test('Item#blendMode in a transformed Group', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var layer = new Layer();
|
|
|
|
var path1 = new Path.Rectangle({
|
|
|
|
size: [100, 100],
|
|
|
|
fillColor: new Color(1, 0, 0)
|
|
|
|
});
|
2013-03-16 10:44:04 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
var path2 = new Path.Circle({
|
|
|
|
radius: 25,
|
|
|
|
center: [50, 50],
|
|
|
|
fillColor: new Color(0, 1, 0),
|
|
|
|
blendMode: 'screen'
|
|
|
|
});
|
2013-03-16 10:44:04 -04:00
|
|
|
|
2020-05-23 09:41:18 -04:00
|
|
|
var raster = layer.rasterize(72, false);
|
2014-12-28 09:21:38 -05:00
|
|
|
equals(raster.getPixel(0, 0), new Color(1, 0, 0, 1),
|
2020-05-23 09:41:18 -04:00
|
|
|
'Top left pixel should be red');
|
2014-12-28 09:21:38 -05:00
|
|
|
equals(raster.getPixel(50, 50), new Color(1, 1, 0, 1),
|
2020-05-23 09:41:18 -04:00
|
|
|
'Middle center pixel should be yellow');
|
2013-03-16 10:44:04 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
path2.position = [0, 0];
|
2013-03-16 10:44:04 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
var group = new Group(path2);
|
|
|
|
group.position = [50, 50];
|
2013-03-16 10:44:04 -04:00
|
|
|
|
2020-05-23 09:41:18 -04:00
|
|
|
var raster = layer.rasterize(72, false);
|
2014-12-28 09:21:38 -05:00
|
|
|
equals(raster.getPixel(0, 0), new Color(1, 0, 0, 1),
|
2020-05-23 09:41:18 -04:00
|
|
|
'Top left pixel should be red');
|
2014-12-28 09:21:38 -05:00
|
|
|
equals(raster.getPixel(50, 50), new Color(1, 1, 0, 1),
|
2020-05-23 09:41:18 -04:00
|
|
|
'Middle center pixel should be yellow');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Item#opacity', function() {
|
|
|
|
var layer = new Layer();
|
|
|
|
var background = new Path.Rectangle({
|
|
|
|
size: [100, 100],
|
|
|
|
fillColor: 'white'
|
|
|
|
});
|
|
|
|
|
|
|
|
var circle = new Path.Circle({
|
|
|
|
radius: 25,
|
|
|
|
center: [50, 50],
|
|
|
|
fillColor: 'red'
|
|
|
|
});
|
|
|
|
|
|
|
|
const red = new Color(1, 0, 0, 1)
|
|
|
|
const white = new Color(1, 1, 1, 1)
|
|
|
|
|
|
|
|
equals(layer.rasterize(72, false).getPixel(50, 50), red,
|
|
|
|
'Center pixel should be red');
|
|
|
|
circle.opacity = 0;
|
|
|
|
equals(layer.rasterize(72, false).getPixel(50, 50), white,
|
|
|
|
'Center pixel should be white');
|
|
|
|
circle.opacity = -1;
|
|
|
|
equals(layer.rasterize(72, false).getPixel(50, 50), white,
|
|
|
|
'Center pixel should be white');
|
|
|
|
circle.opacity = 1;
|
|
|
|
equals(layer.rasterize(72, false).getPixel(50, 50), red,
|
|
|
|
'Center pixel should be red');
|
|
|
|
circle.opacity = 2;
|
|
|
|
equals(layer.rasterize(72, false).getPixel(50, 50), red,
|
|
|
|
'Center pixel should be red');
|
2013-03-16 10:44:04 -04:00
|
|
|
});
|
2014-04-11 07:18:27 -04:00
|
|
|
|
2016-02-14 15:34:35 -05:00
|
|
|
test('Item#applyMatrix', function() {
|
|
|
|
equals(function() {
|
|
|
|
return new Path({ applyMatrix: true }).applyMatrix;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return new Path({ applyMatrix: false }).applyMatrix;
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return new Raster({ applyMatrix: false }).applyMatrix;
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return new Raster({ applyMatrix: true }).applyMatrix;
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
var applyMatrix = paper.settings.applyMatrix;
|
|
|
|
paper.settings.applyMatrix = true;
|
|
|
|
equals(function() {
|
|
|
|
return new Path().applyMatrix;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return new Raster().applyMatrix;
|
|
|
|
}, false);
|
|
|
|
paper.settings.applyMatrix = false;
|
|
|
|
equals(function() {
|
|
|
|
return new Path().applyMatrix;
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return new Raster().applyMatrix;
|
|
|
|
}, false);
|
|
|
|
paper.settings.applyMatrix = applyMatrix;
|
|
|
|
|
|
|
|
var path = new Path.Rectangle({
|
|
|
|
size: [100, 100],
|
2016-07-25 17:17:45 -04:00
|
|
|
position: [0, 0]
|
2016-02-14 15:34:35 -05:00
|
|
|
});
|
|
|
|
|
2016-07-25 17:17:45 -04:00
|
|
|
path.applyMatrix = false;
|
|
|
|
|
2016-02-14 15:34:35 -05:00
|
|
|
equals(path.matrix, new Matrix(),
|
|
|
|
'path.matrix before scaling');
|
|
|
|
equals(path.bounds, new Rectangle(-50, -50, 100, 100),
|
|
|
|
'path.bounds before scaling');
|
|
|
|
equals(path.segments[0].point, new Point(-50, 50),
|
|
|
|
'path.segments[0].point before scaling');
|
|
|
|
|
|
|
|
path.scale(1, 2);
|
|
|
|
|
|
|
|
equals(path.matrix, new Matrix().scale(1, 2),
|
|
|
|
'path.matrix after scaling');
|
|
|
|
equals(path.bounds, new Rectangle(-50, -100, 100, 200),
|
|
|
|
'path.bounds after scaling');
|
|
|
|
equals(path.segments[0].point, new Point(-50, 50),
|
|
|
|
'path.segments[0].point after scaling');
|
|
|
|
|
|
|
|
path.applyMatrix = true;
|
|
|
|
|
|
|
|
equals(path.matrix, new Matrix(),
|
|
|
|
'path.matrix after setting path.applyMatrix = true;');
|
|
|
|
equals(path.bounds, new Rectangle(-50, -100, 100, 200),
|
|
|
|
'path.bounds after setting path.applyMatrix = true;');
|
|
|
|
equals(path.segments[0].point, new Point(-50, 100),
|
|
|
|
'path.segments[0].point after setting path.applyMatrix = true;');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('PaperScope#settings.insertItems', function() {
|
|
|
|
var insertItems = paper.settings.insertItems;
|
|
|
|
paper.settings.insertItems = true;
|
2016-02-14 16:04:40 -05:00
|
|
|
|
|
|
|
var path1, path2;
|
|
|
|
|
2016-02-14 15:34:35 -05:00
|
|
|
equals(function() {
|
2016-02-14 16:04:40 -05:00
|
|
|
path1 = new Path();
|
|
|
|
return path1.parent === project.activeLayer;
|
2016-02-14 15:34:35 -05:00
|
|
|
}, true);
|
|
|
|
paper.settings.insertItems = false;
|
2016-02-14 16:04:40 -05:00
|
|
|
|
2016-02-14 15:34:35 -05:00
|
|
|
equals(function() {
|
2016-02-14 16:04:40 -05:00
|
|
|
path2 = new Path();
|
|
|
|
return path2.parent === null;
|
2016-02-14 15:34:35 -05:00
|
|
|
}, true);
|
2016-02-14 16:04:40 -05:00
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.children.length;
|
|
|
|
}, 1);
|
|
|
|
|
|
|
|
project.activeLayer.addChild(path2);
|
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return project.activeLayer.children.length;
|
|
|
|
}, 2);
|
|
|
|
|
2016-02-14 15:34:35 -05:00
|
|
|
paper.settings.insertItems = insertItems;
|
|
|
|
});
|
2014-04-11 07:18:27 -04:00
|
|
|
|
|
|
|
test('Item#pivot', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path1 = new Path.Rectangle({
|
|
|
|
point: [50, 50],
|
|
|
|
size: [100, 100],
|
|
|
|
strokeColor: 'red',
|
|
|
|
applyMatrix: false
|
|
|
|
});
|
|
|
|
|
|
|
|
var path2 = new Path.Rectangle({
|
|
|
|
point: [50, 50],
|
|
|
|
size: [100, 100],
|
|
|
|
strokeColor: 'green',
|
|
|
|
applyMatrix: true
|
|
|
|
});
|
|
|
|
|
2015-08-18 11:23:33 -04:00
|
|
|
var pivot = new Point(100, 100);
|
|
|
|
|
|
|
|
path1.pivot = pivot;
|
2014-08-16 13:24:54 -04:00
|
|
|
path1.position = [200, 200];
|
2016-02-14 15:34:35 -05:00
|
|
|
equals(path1.pivot, pivot,
|
|
|
|
'Changing position of an item with applyMatrix = false should not change pivot');
|
2014-08-16 13:24:54 -04:00
|
|
|
|
2015-08-18 11:23:33 -04:00
|
|
|
var difference = new Point(100, 100);
|
|
|
|
path2.pivot = pivot;
|
|
|
|
path2.position = path2.position.add(difference);
|
2016-02-14 15:34:35 -05:00
|
|
|
equals(path2.pivot, pivot.add(difference),
|
|
|
|
'Changing position of an item with applyMatrix = true should change pivot');
|
2014-04-11 07:18:27 -04:00
|
|
|
});
|
2017-04-22 06:55:42 -04:00
|
|
|
|
|
|
|
test('Item#position with irregular shape, #pivot and rotation', function() {
|
|
|
|
var path1 = new Path([ [0, 0], [200, 100], [0, 100] ]);
|
|
|
|
var path2 = path1.clone();
|
|
|
|
path2.pivot = path2.position;
|
|
|
|
equals(path1.position, new Point(100, 50),
|
|
|
|
'path1.position, before rotation');
|
|
|
|
path1.rotate(45);
|
|
|
|
equals(path1.position, new Point(64.64466, 50),
|
|
|
|
'path1.position, after rotation');
|
|
|
|
equals(path2.position, new Point(100, 50),
|
|
|
|
'path2.position with pivot, before rotation');
|
|
|
|
path2.rotate(45);
|
|
|
|
equals(path2.position, new Point(100, 50),
|
|
|
|
'path2.position with pivot, after rotation');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Item#scaling, #rotation', function() {
|
|
|
|
var expected = new Rectangle(100, 50, 100, 200);
|
|
|
|
|
|
|
|
var rect1 = new Path.Rectangle({
|
|
|
|
from: [100, 100],
|
|
|
|
to: [200, 200],
|
|
|
|
applyMatrix: false
|
|
|
|
});
|
|
|
|
var rect2 = rect1.clone();
|
|
|
|
|
|
|
|
rect1.scaling = [2, 1];
|
|
|
|
rect1.rotation = 90;
|
|
|
|
equals(rect1.bounds, expected,
|
|
|
|
'rect1.bounds, setting rect1.scaling before rect1.rotation');
|
|
|
|
|
|
|
|
rect2.rotation = 90;
|
|
|
|
rect2.scaling = [2, 1];
|
|
|
|
equals(rect2.bounds, expected,
|
|
|
|
'rect2.bounds, setting rect2.scaling before rect2.rotation');
|
|
|
|
|
|
|
|
var shape1 = new Shape.Rectangle({
|
|
|
|
from: [100, 100],
|
|
|
|
to: [200, 200]
|
|
|
|
});
|
|
|
|
var shape2 = shape1.clone();
|
|
|
|
|
|
|
|
shape1.scaling = [2, 1];
|
|
|
|
shape1.rotation = 90;
|
|
|
|
equals(shape1.bounds, expected,
|
|
|
|
'shape1.bounds, setting shape1.scaling before shape1.rotation');
|
|
|
|
|
|
|
|
shape2.rotation = 90;
|
|
|
|
shape2.scaling = [2, 1];
|
|
|
|
equals(shape2.bounds, expected,
|
|
|
|
'shape2.bounds, setting shape2.scaling before shape2.rotation');
|
|
|
|
});
|
2018-10-01 13:25:04 -04:00
|
|
|
|
2018-10-03 12:21:26 -04:00
|
|
|
test('Item#position pivot point and caching (#1503)', function() {
|
2018-10-01 13:25:04 -04:00
|
|
|
var item = Path.Rectangle(new Point(0, 0), new Size(20));
|
|
|
|
item.pivot = new Point(0, 0);
|
2018-10-03 12:21:26 -04:00
|
|
|
var bounds = item.bounds;
|
2018-10-01 13:25:04 -04:00
|
|
|
item.translate(5, 5);
|
|
|
|
equals(item.position, new Point(5, 5));
|
|
|
|
});
|
2018-10-13 10:28:20 -04:00
|
|
|
|
|
|
|
test('Children global matrices are cleared after parent transformation', function() {
|
|
|
|
var item = Path.Rectangle(new Point(0, 0), new Size(100));
|
|
|
|
var group = new Group({ children: [item], applyMatrix: false });
|
|
|
|
equals(item.localToGlobal(item.getPointAt(0)), new Point(0, 100));
|
|
|
|
group.translate(100, 0);
|
|
|
|
equals(item.localToGlobal(item.getPointAt(0)), new Point(100, 100));
|
|
|
|
});
|
2018-11-14 05:21:40 -05:00
|
|
|
|
|
|
|
test('Item#rasterize() with empty bounds', function() {
|
|
|
|
new Path.Line([0, 0], [100, 0]).rasterize();
|
|
|
|
view.update();
|
|
|
|
expect(0);
|
|
|
|
});
|
2018-11-09 04:26:54 -05:00
|
|
|
|
|
|
|
test('Item#draw() with CompoundPath as clip item', function() {
|
|
|
|
function createdClippedGroup(invertedOrder) {
|
|
|
|
var compound = new CompoundPath({
|
|
|
|
children: [
|
|
|
|
new Path.Circle(new Point(50, 50), 50),
|
|
|
|
new Path.Circle(new Point(100, 50), 50)
|
|
|
|
],
|
|
|
|
fillRule: 'evenodd'
|
|
|
|
});
|
|
|
|
|
|
|
|
var rectangle = new Shape.Rectangle(new Point(0, 0), new Point(150, 50));
|
|
|
|
|
|
|
|
var group = new Group();
|
|
|
|
group.children = invertedOrder
|
|
|
|
? [compound, rectangle]
|
|
|
|
: [rectangle, compound];
|
|
|
|
group.fillColor = 'black';
|
|
|
|
group.clipped = true;
|
|
|
|
return group;
|
|
|
|
};
|
|
|
|
|
|
|
|
comparePixels(createdClippedGroup(true), createdClippedGroup(false));
|
|
|
|
});
|