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/
|
|
|
|
*
|
2013-01-28 21:03:27 -05:00
|
|
|
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
2011-07-01 06:17:45 -04:00
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
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-07-07 10:09:02 -04:00
|
|
|
|
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-07-07 10:09:02 -04:00
|
|
|
|
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-07-07 10:09:02 -04:00
|
|
|
|
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-07-07 10:09:02 -04:00
|
|
|
|
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-07-07 10:09:02 -04:00
|
|
|
|
2011-04-11 17:30:08 -04:00
|
|
|
path.join(path2);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
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-07-07 10:09:02 -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-06-05 13:50:24 -04:00
|
|
|
path.removeSegments(0, 1);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.segments.length;
|
2011-06-13 14:08:09 -04:00
|
|
|
}, 1);
|
2011-04-13 10:16:32 -04:00
|
|
|
|
|
|
|
path.remove();
|
2011-07-07 10:09:02 -04:00
|
|
|
|
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-06-05 13:50:24 -04:00
|
|
|
test('path.removeSegments()', function() {
|
|
|
|
var path = new Path();
|
|
|
|
path.add(0, 0);
|
|
|
|
path.add(10, 0);
|
|
|
|
path.add(20, 0);
|
|
|
|
path.add(30, 0);
|
|
|
|
|
|
|
|
path.removeSegments();
|
|
|
|
equals(function() {
|
|
|
|
return path.segments.length;
|
|
|
|
}, 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;
|
2011-06-20 14:08:34 -04:00
|
|
|
}, true);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.selectedItems.length;
|
2011-06-20 14:08:34 -04:00
|
|
|
}, 1);
|
2011-04-27 06:13:28 -04:00
|
|
|
});
|
|
|
|
|
2011-06-14 10:37:46 -04:00
|
|
|
test('After setting Path#fullySelected=true on an empty path, subsequent segments should be selected', function() {
|
2011-06-14 06:19:54 -04:00
|
|
|
var path = new Path();
|
2011-06-14 10:37:46 -04:00
|
|
|
path.fullySelected = true;
|
2011-06-14 06:19:54 -04:00
|
|
|
equals(function() {
|
2011-06-14 10:37:46 -04:00
|
|
|
return path.fullySelected;
|
2011-06-14 06:19:54 -04:00
|
|
|
}, true);
|
|
|
|
path.add([10, 10]);
|
|
|
|
equals(function() {
|
2011-06-14 10:37:46 -04:00
|
|
|
return path.fullySelected;
|
2011-06-14 06:19:54 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path.firstSegment.selected;
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
2011-06-20 11:00:41 -04:00
|
|
|
test('After removing all segments of a fully selected path, it should still be fully selected.', function() {
|
|
|
|
var path = new Path([10, 20], [30, 40]);
|
|
|
|
path.fullySelected = true;
|
|
|
|
path.removeSegments();
|
|
|
|
equals(function() {
|
|
|
|
return path.fullySelected;
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After removing all segments of a selected path, it should still be selected.', function() {
|
|
|
|
var path = new Path([10, 20], [30, 40]);
|
|
|
|
path.selected = true;
|
|
|
|
path.removeSegments();
|
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2011-06-20 13:17:07 -04:00
|
|
|
test('After simplifying a path using #simplify(), the path should stay fullySelected', function() {
|
2011-06-20 10:51:13 -04:00
|
|
|
var path = new Path();
|
|
|
|
for (var i = 0; i < 30; i++) {
|
|
|
|
path.add(i * 10, 10);
|
2013-10-17 05:32:11 -04:00
|
|
|
}
|
2011-06-20 19:31:07 -04:00
|
|
|
path.fullySelected = true;
|
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
path.simplify();
|
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path.fullySelected;
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After cloning a selected item, it should be added to the Project#selectedItems array', function() {
|
|
|
|
var path = new Path.Circle(new Size(80, 50), 35);
|
|
|
|
path.selected = true;
|
|
|
|
var copy = path.clone();
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-06-20 19:31:07 -04:00
|
|
|
equals(function() {
|
2013-10-17 05:32:11 -04:00
|
|
|
return paper.project.selectedItems.length;
|
2011-06-20 19:31:07 -04:00
|
|
|
}, 2);
|
|
|
|
});
|
|
|
|
|
2011-06-20 13:17:07 -04:00
|
|
|
test('After simplifying a path using #simplify(), the path should stay selected', function() {
|
2011-06-20 10:51:13 -04:00
|
|
|
var path = new Path();
|
|
|
|
for (var i = 0; i < 30; i++) {
|
|
|
|
path.add(i * 10, (i % 2 ? 20 : 40));
|
2013-10-17 05:32:11 -04:00
|
|
|
}
|
2011-06-20 10:51:13 -04:00
|
|
|
path.selected = true;
|
2011-06-20 13:17:07 -04:00
|
|
|
path.simplify();
|
2011-06-20 10:51:13 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After smoothing a path using #smooth(), the path should stay fullySelected', function() {
|
|
|
|
var path = new Path();
|
|
|
|
for (var i = 0; i < 30; i++) {
|
|
|
|
path.add(i * 10, (i % 2 ? 20 : 40));
|
2013-10-17 05:32:11 -04:00
|
|
|
}
|
2011-06-20 10:51:13 -04:00
|
|
|
path.fullySelected = true;
|
|
|
|
path.smooth();
|
|
|
|
equals(function() {
|
|
|
|
return path.fullySelected;
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('After smoothing a path using #smooth(), the path should stay selected', function() {
|
|
|
|
var path = new Path();
|
|
|
|
for (var i = 0; i < 30; i++) {
|
|
|
|
path.add(i * 10, (i % 2 ? 20 : 40));
|
2013-10-17 05:32:11 -04:00
|
|
|
}
|
2011-06-20 10:51:13 -04:00
|
|
|
path.selected = true;
|
|
|
|
path.smooth();
|
|
|
|
equals(function() {
|
2011-06-20 10:59:51 -04:00
|
|
|
return path.selected;
|
2011-06-20 10:51:13 -04:00
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
2011-06-17 08:10:10 -04:00
|
|
|
test('After selecting a segment, Path#selected should return true', function() {
|
|
|
|
var path = new Path();
|
|
|
|
path.add([10, 10]);
|
|
|
|
path.firstSegment.selected = true;
|
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2012-03-01 11:06:39 -05:00
|
|
|
test('Path#reverse should adjust segment indices', function() {
|
2012-02-18 18:13:23 -05:00
|
|
|
var path = new Path([[0, 0], [10, 10], [20, 20]]);
|
|
|
|
path.reverse();
|
2012-03-01 11:06:39 -05:00
|
|
|
equals(path.segments[0].index, 0);
|
|
|
|
equals(path.segments[1].index, 1);
|
|
|
|
equals(path.segments[2].index, 2);
|
2012-02-18 18:13:23 -05:00
|
|
|
});
|
|
|
|
|
2011-06-05 14:08:46 -04:00
|
|
|
test('Path#fullySelected', function() {
|
|
|
|
var path = new Path.Circle([100, 100], 10);
|
2011-06-14 10:37:46 -04:00
|
|
|
path.fullySelected = true;
|
2011-06-05 14:08:46 -04:00
|
|
|
path.segments[1].selected = false;
|
|
|
|
equals(function() {
|
|
|
|
return path.fullySelected;
|
|
|
|
}, false);
|
2012-02-18 18:13:23 -05:00
|
|
|
});
|
2013-02-27 11:34:28 -05:00
|
|
|
|
|
|
|
test('Simplifying a path with three segments of the same position should not throw an error', function() {
|
|
|
|
var path = new Path([20, 20], [20, 20], [20, 20]);
|
|
|
|
path.simplify();
|
2013-06-11 16:40:50 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.segments.length;
|
|
|
|
}, 1);
|
2013-02-27 11:34:28 -05:00
|
|
|
});
|