forked from paperjs/paper.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlacedSymbol.js
More file actions
131 lines (118 loc) · 3.85 KB
/
Copy pathPlacedSymbol.js
File metadata and controls
131 lines (118 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
module('Symbol & Placed Symbol');
test('placedSymbol bounds', function() {
var path = new Path.Circle([50, 50], 50);
path.strokeColor = 'black';
path.strokeWidth = 1;
path.strokeCap = 'round';
path.strokeJoin = 'round';
compareRectangles(path.strokeBounds,
{ x: -0.5, y: -0.5, width: 101, height: 101 },
'Path initial bounds');
var symbol = new Symbol(path);
var placedSymbol = new PlacedSymbol(symbol);
compareRectangles(placedSymbol.bounds,
new Rectangle(-50.5, -50.5, 101, 101),
'PlacedSymbol initial bounds');
placedSymbol.scale(1, 0.5);
compareRectangles(placedSymbol.bounds,
{ x: -50.5, y: -25.25, width: 101, height: 50.5 },
'Bounds after scale');
placedSymbol.rotate(40);
compareRectangles(placedSymbol.bounds,
{ x: -41.96283, y: -37.79252, width: 83.92567, height: 75.58503 },
'Bounds after rotation');
});
test('bounds of group of symbol instances', function() {
var path = new Path.Circle(new Point(), 10);
var symbol = new Symbol(path);
var instances = [];
for (var i = 0; i < 10; i++) {
var instance = symbol.place(new Point(i * 20, 20));
instances.push(instance);
}
var group = new Group(instances);
compareRectangles(group.bounds,
{ x: -10, y: 10, width: 200, height: 20 },
'Group bounds');
});
test('bounds of a symbol that contains a group of items', function() {
var path = new Path.Circle(new Point(), 10);
var path2 = path.clone();
path2.position.x += 20;
compareRectangles(path.bounds,
{ x: -10, y: -10, width: 20, height: 20 },
'path bounds');
compareRectangles(path2.bounds,
{ x: 10, y: -10, width: 20, height: 20 },
'path2 bounds');
var group = new Group(path, path2);
compareRectangles(group.bounds,
{ x: -10, y: -10, width: 40, height: 20 },
'Group bounds');
var symbol = new Symbol(group);
var instance = symbol.place(new Point(50, 50));
compareRectangles(instance.bounds,
{ x: 30, y: 40, width: 40, height: 20 },
'Instance bounds');
});
test('Changing the definition of a symbol should change the bounds of all instances of it.', function() {
var path = new Path.Circle(new Point(), 10);
var path2 = new Path.Circle(new Point(), 20);
var symbol = new Symbol(path);
var instance = symbol.place(new Point(0, 0));
compareRectangles(instance.bounds,
{ x: -10, y: -10, width: 20, height: 20 },
'Initial bounds');
symbol.definition = path2;
compareRectangles(instance.bounds,
{ x: -20, y: -20, width: 40, height: 40 },
'Bounds after changing symbol definition');
symbol.definition.scale(0.5, 0.5);
compareRectangles(instance.bounds,
{ x: -10, y: -10, width: 20, height: 20 },
'Bounds after modifying symbol definition');
});
test('Symbol definition selection', function() {
var path = new Path.Circle([50, 50], 50);
path.selected = true;
var symbol = new Symbol(path);
equals(function() {
return symbol.definition.selected == false;
}, true);
equals(function() {
return paper.project.selectedItems.length == 0;
}, true);
});
test('Symbol#place()', function() {
var path = new Path.Circle([50, 50], 50);
var symbol = new Symbol(path);
var placedSymbol = symbol.place();
equals(function() {
return placedSymbol.parent == paper.project.activeLayer;
}, true);
equals(function() {
return placedSymbol.symbol == symbol;
}, true);
equals(function() {
return placedSymbol.position.toString();
}, '{ x: 0, y: 0 }');
});
test('Symbol#place(position)', function() {
var path = new Path.Circle([50, 50], 50);
var symbol = new Symbol(path);
var placedSymbol = symbol.place(new Point(100, 100));
equals(function() {
return placedSymbol.position.toString();
}, '{ x: 100, y: 100 }');
});