MCPcopy
hub / github.com/golang/geo / initBound

Method initBound

s2/loop.go:175–216  ·  view source on GitHub ↗

initBound sets up the approximate bounding Rects for this loop.

()

Source from the content-addressed store, hash-verified

173
174// initBound sets up the approximate bounding Rects for this loop.
175func (l *Loop) initBound() {
176 if len(l.vertices) == 0 {
177 *l = *EmptyLoop()
178 return
179 }
180 // Check for the special "empty" and "full" loops.
181 if l.isEmptyOrFull() {
182 if l.IsEmpty() {
183 l.bound = EmptyRect()
184 } else {
185 l.bound = FullRect()
186 }
187 l.subregionBound = l.bound
188 return
189 }
190
191 // The bounding rectangle of a loop is not necessarily the same as the
192 // bounding rectangle of its vertices. First, the maximal latitude may be
193 // attained along the interior of an edge. Second, the loop may wrap
194 // entirely around the sphere (e.g. a loop that defines two revolutions of a
195 // candy-cane stripe). Third, the loop may include one or both poles.
196 // Note that a small clockwise loop near the equator contains both poles.
197 bounder := NewRectBounder()
198 for i := 0; i <= len(l.vertices); i++ { // add vertex 0 twice
199 bounder.AddPoint(l.Vertex(i))
200 }
201 b := bounder.RectBound()
202
203 if l.ContainsPoint(Point{r3.Vector{X: 0, Y: 0, Z: 1}}) {
204 b = Rect{r1.Interval{Lo: b.Lat.Lo, Hi: math.Pi / 2}, s1.FullInterval()}
205 }
206 // If a loop contains the south pole, then either it wraps entirely
207 // around the sphere (full longitude range), or it also contains the
208 // north pole in which case b.Lng.IsFull() due to the test above.
209 // Either way, we only need to do the south pole containment test if
210 // b.Lng.IsFull().
211 if b.Lng.IsFull() && l.ContainsPoint(Point{r3.Vector{X: 0, Y: 0, Z: -1}}) {
212 b.Lat.Lo = -math.Pi / 2
213 }
214 l.bound = b
215 l.subregionBound = ExpandForSubregions(l.bound)
216}
217
218// Validate checks whether this is a valid loop.
219func (l *Loop) Validate() error {

Callers 3

initOriginAndBoundMethod · 0.95
InvertMethod · 0.95
decodeCompressedMethod · 0.95

Calls 13

isEmptyOrFullMethod · 0.95
IsEmptyMethod · 0.95
AddPointMethod · 0.95
VertexMethod · 0.95
RectBoundMethod · 0.95
ContainsPointMethod · 0.95
FullIntervalFunction · 0.92
EmptyLoopFunction · 0.85
FullRectFunction · 0.85
NewRectBounderFunction · 0.85
ExpandForSubregionsFunction · 0.85
EmptyRectFunction · 0.70

Tested by

no test coverage detected