@@ -46,6 +46,25 @@ package s2
46
46
// - No loop may be empty. The full loop may appear only in the full polygon.
47
47
type Polygon struct {
48
48
loops []* Loop
49
+
50
+ // index is a spatial index of all the polygon loops.
51
+ index ShapeIndex
52
+
53
+ // hasHoles tracks if this polygon has at least one hole.
54
+ hasHoles bool
55
+
56
+ // numVertices keeps the running total of all of the vertices of the contained loops.
57
+ numVertices int
58
+
59
+ // bound is a conservative bound on all points contained by this loop.
60
+ // If l.ContainsPoint(P), then l.bound.ContainsPoint(P).
61
+ bound Rect
62
+
63
+ // Since bound is not exact, it is possible that a loop A contains
64
+ // another loop B whose bounds are slightly larger. subregionBound
65
+ // has been expanded sufficiently to account for this error, i.e.
66
+ // if A.Contains(B), then A.subregionBound.Contains(B.bound).
67
+ subregionBound Rect
49
68
}
50
69
51
70
// PolygonFromLoops constructs a polygon from the given hierarchically nested
@@ -63,7 +82,10 @@ func PolygonFromLoops(loops []*Loop) *Polygon {
63
82
panic ("s2.PolygonFromLoops for multiple loops is not yet implemented" )
64
83
}
65
84
return & Polygon {
66
- loops : loops ,
85
+ loops : loops ,
86
+ numVertices : len (loops [0 ].Vertices ()), // TODO(roberts): Once multi-loop is supported, fix this.
87
+ bound : EmptyRect (),
88
+ subregionBound : EmptyRect (),
67
89
}
68
90
}
69
91
@@ -73,6 +95,9 @@ func FullPolygon() *Polygon {
73
95
loops : []* Loop {
74
96
FullLoop (),
75
97
},
98
+ numVertices : len (FullLoop ().Vertices ()),
99
+ bound : FullRect (),
100
+ subregionBound : FullRect (),
76
101
}
77
102
}
78
103
0 commit comments