2011-02-11 09:02:35 -05:00
|
|
|
module('Path');
|
2011-04-11 17:30:08 -04:00
|
|
|
|
|
|
|
test('path.join(path)', function() {
|
|
|
|
var path = new Path();
|
2011-05-05 07:35:38 -04:00
|
|
|
path.add(0, 0);
|
|
|
|
path.add(10, 0);
|
2011-04-11 17:30:08 -04:00
|
|
|
|
|
|
|
var path2 = new Path();
|
2011-05-05 07:35:38 -04:00
|
|
|
path2.add(10, 0);
|
|
|
|
path2.add(20, 10);
|
2011-04-11 17:30:08 -04:00
|
|
|
|
|
|
|
path.join(path2);
|
2011-05-04 14:40:52 -04:00
|
|
|
equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } }');
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children.length;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, 1);
|
2011-04-11 17:30:08 -04:00
|
|
|
|
|
|
|
var path = new Path();
|
2011-05-05 07:35:38 -04:00
|
|
|
path.add(0, 0);
|
|
|
|
path.add(10, 0);
|
2011-04-11 17:30:08 -04:00
|
|
|
|
|
|
|
var path2 = new Path();
|
2011-05-05 07:35:38 -04:00
|
|
|
path2.add(20, 10);
|
|
|
|
path2.add(10, 0);
|
2011-04-11 17:30:08 -04:00
|
|
|
path.join(path2);
|
2011-05-04 14:40:52 -04:00
|
|
|
equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } }');
|
2011-04-11 17:30:08 -04:00
|
|
|
|
|
|
|
var path = new Path();
|
2011-05-05 07:35:38 -04:00
|
|
|
path.add(0, 0);
|
|
|
|
path.add(10, 0);
|
2011-04-11 17:30:08 -04:00
|
|
|
|
|
|
|
var path2 = new Path();
|
2011-05-05 07:35:38 -04:00
|
|
|
path2.add(30, 10);
|
|
|
|
path2.add(40, 0);
|
2011-04-11 17:30:08 -04:00
|
|
|
path.join(path2);
|
2011-05-04 14:40:52 -04:00
|
|
|
equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 30, y: 10 } },{ point: { x: 40, y: 0 } }');
|
|
|
|
|
2011-04-11 17:30:08 -04:00
|
|
|
var path = new Path();
|
2011-05-05 07:35:38 -04:00
|
|
|
path.add(0, 0);
|
|
|
|
path.add(10, 0);
|
|
|
|
path.add(20, 10);
|
2011-04-11 17:30:08 -04:00
|
|
|
|
|
|
|
var path2 = new Path();
|
2011-05-05 07:35:38 -04:00
|
|
|
path2.add(0, 0);
|
|
|
|
path2.add(10, 5);
|
|
|
|
path2.add(20, 10);
|
2011-04-11 17:30:08 -04:00
|
|
|
|
|
|
|
path.join(path2);
|
2011-05-04 14:40:52 -04:00
|
|
|
|
|
|
|
equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } },{ point: { x: 10, y: 5 } }');
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.closed;
|
|
|
|
}, true);
|
2011-04-13 10:16:32 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('path.remove()', function() {
|
|
|
|
var path = new Path();
|
2011-05-05 07:35:38 -04:00
|
|
|
path.add(0, 0);
|
|
|
|
path.add(10, 0);
|
|
|
|
path.add(20, 0);
|
|
|
|
path.add(30, 0);
|
2011-04-13 10:16:32 -04:00
|
|
|
|
2011-04-28 10:42:16 -04:00
|
|
|
path.removeSegment(0);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.segments.length;
|
|
|
|
}, 3);
|
2011-04-13 10:16:32 -04:00
|
|
|
|
2011-04-28 10:42:16 -04:00
|
|
|
path.removeSegment(0);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.segments.length;
|
|
|
|
}, 2);
|
2011-04-13 10:16:32 -04:00
|
|
|
|
2011-05-01 08:27:53 -04:00
|
|
|
path.removeSegments(0, 2);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.segments.length;
|
|
|
|
}, 0);
|
2011-04-13 10:16:32 -04:00
|
|
|
|
|
|
|
path.remove();
|
|
|
|
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children.length;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, 0);
|
2011-04-22 05:39:12 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2011-04-22 05:40:54 -04:00
|
|
|
test('Is the path deselected after setting a new list of segments?', function() {
|
2011-04-22 05:39:12 -04:00
|
|
|
var path = new Path([0, 0]);
|
|
|
|
path.selected = true;
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.selectedItems.length;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, 1);
|
2011-04-22 05:52:24 -04:00
|
|
|
|
2011-04-22 05:39:12 -04:00
|
|
|
path.segments = [[0, 10]];
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.selectedItems.length;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, 0);
|
2011-04-27 06:13:28 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Path#reverse', function() {
|
|
|
|
var path = new Path.Circle([100, 100], 30);
|
|
|
|
path.reverse();
|
2011-05-04 14:40:52 -04:00
|
|
|
equals(path.segments.toString(), '{ point: { x: 100, y: 130 }, handleIn: { x: -16.56854, y: 0 }, handleOut: { x: 16.56854, y: 0 } },{ point: { x: 130, y: 100 }, handleIn: { x: 0, y: 16.56854 }, handleOut: { x: 0, y: -16.56854 } },{ point: { x: 100, y: 70 }, handleIn: { x: 16.56854, y: 0 }, handleOut: { x: -16.56854, y: 0 } },{ point: { x: 70, y: 100 }, handleIn: { x: 0, y: -16.56854 }, handleOut: { x: 0, y: 16.56854 } }');
|
2011-04-27 06:13:28 -04:00
|
|
|
});
|
|
|
|
|