initBound sets up the approximate bounding Rects for this loop.
()
| 173 | |
| 174 | // initBound sets up the approximate bounding Rects for this loop. |
| 175 | func (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. |
| 219 | func (l *Loop) Validate() error { |
no test coverage detected