Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 729d8dc

Browse files
rsneddsymonds
authored andcommitted
s2: Fill out more Polygon internals.
Signed-off-by: David Symonds <[email protected]>
1 parent 88da43e commit 729d8dc

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

s2/polygon.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@ package s2
4646
// - No loop may be empty. The full loop may appear only in the full polygon.
4747
type Polygon struct {
4848
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
4968
}
5069

5170
// PolygonFromLoops constructs a polygon from the given hierarchically nested
@@ -63,7 +82,10 @@ func PolygonFromLoops(loops []*Loop) *Polygon {
6382
panic("s2.PolygonFromLoops for multiple loops is not yet implemented")
6483
}
6584
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(),
6789
}
6890
}
6991

@@ -73,6 +95,9 @@ func FullPolygon() *Polygon {
7395
loops: []*Loop{
7496
FullLoop(),
7597
},
98+
numVertices: len(FullLoop().Vertices()),
99+
bound: FullRect(),
100+
subregionBound: FullRect(),
76101
}
77102
}
78103

0 commit comments

Comments
 (0)