...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package s2
16
17
18 var _ Shape = (*laxLoop)(nil)
19
20
21
22
23
24
25
26
27
28 type laxLoop struct {
29 numVertices int
30 vertices []Point
31 }
32
33 func laxLoopFromPoints(vertices []Point) *laxLoop {
34 l := &laxLoop{
35 numVertices: len(vertices),
36 vertices: make([]Point, len(vertices)),
37 }
38 copy(l.vertices, vertices)
39 return l
40 }
41
42 func laxLoopFromLoop(loop *Loop) *laxLoop {
43 if loop.IsFull() {
44 panic("FullLoops are not yet supported")
45 }
46 if loop.IsEmpty() {
47 return &laxLoop{}
48 }
49
50 l := &laxLoop{
51 numVertices: len(loop.vertices),
52 vertices: make([]Point, len(loop.vertices)),
53 }
54 copy(l.vertices, loop.vertices)
55 return l
56 }
57
58 func (l *laxLoop) vertex(i int) Point { return l.vertices[i] }
59 func (l *laxLoop) NumEdges() int { return l.numVertices }
60 func (l *laxLoop) Edge(e int) Edge {
61 e1 := e + 1
62 if e1 == l.numVertices {
63 e1 = 0
64 }
65 return Edge{l.vertices[e], l.vertices[e1]}
66
67 }
68 func (l *laxLoop) Dimension() int { return 2 }
69 func (l *laxLoop) ReferencePoint() ReferencePoint { return referencePointForShape(l) }
70 func (l *laxLoop) NumChains() int { return minInt(1, l.numVertices) }
71 func (l *laxLoop) Chain(i int) Chain { return Chain{0, l.numVertices} }
72 func (l *laxLoop) ChainEdge(i, j int) Edge {
73 var k int
74 if j+1 == l.numVertices {
75 k = j + 1
76 }
77 return Edge{l.vertices[j], l.vertices[k]}
78 }
79 func (l *laxLoop) ChainPosition(e int) ChainPosition { return ChainPosition{0, e} }
80 func (l *laxLoop) IsEmpty() bool { return defaultShapeIsEmpty(l) }
81 func (l *laxLoop) IsFull() bool { return defaultShapeIsFull(l) }
82 func (l *laxLoop) typeTag() typeTag { return typeTagNone }
83 func (l *laxLoop) privateInterface() {}
84
View as plain text