...
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
34 func LaxLoopFromPoints(vertices []Point) *LaxLoop {
35 l := &LaxLoop{
36 numVertices: len(vertices),
37 vertices: make([]Point, len(vertices)),
38 }
39 copy(l.vertices, vertices)
40 return l
41 }
42
43
44 func LaxLoopFromLoop(loop *Loop) *LaxLoop {
45 if loop.IsFull() {
46 panic("FullLoops are not yet supported")
47 }
48 if loop.IsEmpty() {
49 return &LaxLoop{}
50 }
51
52 l := &LaxLoop{
53 numVertices: len(loop.vertices),
54 vertices: make([]Point, len(loop.vertices)),
55 }
56 copy(l.vertices, loop.vertices)
57 return l
58 }
59
60 func (l *LaxLoop) vertex(i int) Point { return l.vertices[i] }
61 func (l *LaxLoop) NumEdges() int { return l.numVertices }
62 func (l *LaxLoop) Edge(e int) Edge {
63 e1 := e + 1
64 if e1 == l.numVertices {
65 e1 = 0
66 }
67 return Edge{l.vertices[e], l.vertices[e1]}
68
69 }
70 func (l *LaxLoop) Dimension() int { return 2 }
71 func (l *LaxLoop) ReferencePoint() ReferencePoint { return referencePointForShape(l) }
72 func (l *LaxLoop) NumChains() int { return minInt(1, l.numVertices) }
73 func (l *LaxLoop) Chain(i int) Chain { return Chain{0, l.numVertices} }
74 func (l *LaxLoop) ChainEdge(i, j int) Edge {
75 var k int
76 if j+1 == l.numVertices {
77 k = j + 1
78 }
79 return Edge{l.vertices[j], l.vertices[k]}
80 }
81 func (l *LaxLoop) ChainPosition(e int) ChainPosition { return ChainPosition{0, e} }
82 func (l *LaxLoop) IsEmpty() bool { return defaultShapeIsEmpty(l) }
83 func (l *LaxLoop) IsFull() bool { return defaultShapeIsFull(l) }
84 func (l *LaxLoop) typeTag() typeTag { return typeTagNone }
85 func (l *LaxLoop) privateInterface() {}
86
87
88
89
90
View as plain text