forked from andreaferretti/paths-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsector.js
72 lines (65 loc) · 1.52 KB
/
sector.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
import Sector from '../dist/node/sector.js'
import expect from 'expect.js'
let round = (x, digits = 5) => {
let a = Math.pow(10, digits)
return Math.round(a * x) / a
}
let roundVector = (v, digits = 5) => {
return v.map((x) => round(x, digits))
}
describe('sector function', () => {
it('should pass through the expected points', () => {
let sector = Sector({
r: 2,
R: 4,
center: [1, 1],
start: 0,
end: Math.PI / 2
})
let points = sector.path.points().map(roundVector)
let expected = [[1, -3], [5, 1], [3, 1], [1, -1]]
expect(points).to.eql(expected)
})
it('should have the expected centroid', () => {
let sector = Sector({
r: 2,
R: 6,
center: [0, 0],
start: 0,
end: Math.PI
})
expect(roundVector(sector.centroid)).to.eql([4, 0])
})
it('should be closed', () => {
let sector = Sector({
r: 2,
R: 4,
center: [1, 1],
start: 0,
end: 1
})
expect(sector.path.print()).to.match(/Z/)
})
it('should pass through the center when r = 0', () => {
let sector = Sector({
r: 0,
R: 3,
center: [3, 16],
start: 1,
end: 2
})
expect(sector.path.points().filter((x) =>
(x[0] === 3) && (x[1] === 16)
)).to.have.length(2)
})
it('should have the expected large arc flag', () => {
let sector = Sector({
r: 0,
R: 3,
center: [0, 0],
start: 0,
end: 3 / 2 * Math.PI
})
expect(sector.path.print()).to.match(/A 3 3 0 1 1 -3/)
})
})