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-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-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);
|
|
|
|
};
|
|
|
|
path.fullySelected = true;
|
2011-06-20 14:08:34 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, true);
|
|
|
|
|
2011-06-20 13:17:07 -04:00
|
|
|
path.simplify();
|
2011-06-20 14:08:34 -04:00
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, true);
|
2011-06-20 10:51:13 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.fullySelected;
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
2011-06-20 19:31:07 -04:00
|
|
|
test('After simplifying a path using #simplify(), the path should stay fullySelected', function() {
|
|
|
|
var path = new Path();
|
|
|
|
for (var i = 0; i < 30; i++) {
|
|
|
|
path.add(i * 10, 10);
|
|
|
|
};
|
|
|
|
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();
|
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return paper.project.selectedItems.length
|
|
|
|
}, 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));
|
|
|
|
};
|
|
|
|
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));
|
|
|
|
};
|
|
|
|
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));
|
|
|
|
};
|
|
|
|
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
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
});
|