-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsplit.js
134 lines (128 loc) · 3.76 KB
/
split.js
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
132
133
134
var test = require('tape')
var Path = require('../lib/Path')
test('single path', function (t) {
var path = new Path([
{ type: 'M', relative:false, x:0, y:0 },
{ type: 'L', relative:false, x:100, y:100 },
{ type: 'Z' }
])
var subpaths = path.split()
t.same(subpaths.length, 1)
t.same(subpaths[0].content,
[
{ type: 'M', relative:false, x:0, y:0 },
{ type: 'L', relative:false, x:100, y:100 },
{ type: 'Z' }
])
t.end()
})
test('explicit subpath', function (t) {
var path = new Path([
{ type: 'M', relative:false, x:0, y:0 },
{ type: 'L', relative:false, x:100, y:100 },
{ type: 'Z' },
{ type: 'M', relative:false, x:50, y:50 },
{ type: 'L', relative:false, x:200, y:200 }
])
var subpaths = path.split()
t.same(subpaths.length, 2)
t.same(subpaths[0].content,
[
{ type: 'M', relative:false, x:0, y:0 },
{ type: 'L', relative:false, x:100, y:100 },
{ type: 'Z' }
])
t.same(subpaths[1].content,
[
{ type: 'M', relative:false, x:50, y:50 },
{ type: 'L', relative:false, x:200, y:200 }
])
t.end()
})
test('relative subpath', function (t) {
var path = new Path([
{ type: 'M', relative:false, x:50, y:50 },
{ type: 'L', relative:false, x:100, y:100 },
{ type: 'Z' },
{ type: 'M', relative:true, x:50, y:50 },
{ type: 'L', relative:false, x:200, y:200 }
])
var subpaths = path.split()
t.same(subpaths.length, 2)
t.same(subpaths[0].content,
[
{ type: 'M', relative:false, x:50, y:50 },
{ type: 'L', relative:false, x:100, y:100 },
{ type: 'Z' }
])
t.same(subpaths[1].content,
[
{ type: 'M', relative:false, x:100, y:100 },
{ type: 'L', relative:false, x:200, y:200 }
])
t.end()
})
test('subpath without closepath', function (t) {
var path = new Path([
{ type: 'M', relative:false, x:0, y:0 },
{ type: 'L', relative:false, x:100, y:100 },
{ type: 'M', relative:false, x:50, y:50 },
{ type: 'L', relative:false, x:200, y:200 }
])
var subpaths = path.split()
t.same(subpaths.length, 2)
t.same(subpaths[0].content,
[
{ type: 'M', relative:false, x:0, y:0 },
{ type: 'L', relative:false, x:100, y:100 }
])
t.same(subpaths[1].content,
[
{ type: 'M', relative:false, x:50, y:50 },
{ type: 'L', relative:false, x:200, y:200 }
])
t.end()
})
test('implicit subpath after closepath', function (t) {
var path = new Path([
{ type: 'M', relative:false, x:0, y:0 },
{ type: 'L', relative:false, x:100, y:100 },
{ type: 'Z' },
{ type: 'L', relative:false, x:200, y:200 }
])
var subpaths = path.split()
t.same(subpaths.length, 2)
t.same(subpaths[0].content,
[
{ type: 'M', relative:false, x:0, y:0 },
{ type: 'L', relative:false, x:100, y:100 },
{ type: 'Z' }
])
t.same(subpaths[1].content,
[
{ type: 'M', relative:false, x:0, y:0 },
{ type: 'L', relative:false, x:200, y:200 }
])
t.end()
})
test('commands are clones', function (t) {
var path = new Path([
{ type: 'M', relative:false, x:0, y:0 },
{ type: 'L', relative:false, x:100, y:100 },
{ type: 'M', relative:false, x:50, y:50 },
{ type: 'L', relative:false, x:200, y:200 }
])
var subpaths = path.split()
t.same(subpaths.length, 2)
// commands should be clones...
t.same(path.content[0], subpaths[0].content[0])
t.same(path.content[1], subpaths[0].content[1])
t.same(path.content[2], subpaths[1].content[0])
t.same(path.content[3], subpaths[1].content[1])
// ...not references to the same objects:
t.notEqual(path.content[0], subpaths[0].content[0])
t.notEqual(path.content[1], subpaths[0].content[1])
t.notEqual(path.content[2], subpaths[1].content[0])
t.notEqual(path.content[3], subpaths[1].content[1])
t.end()
})