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

Method insertLoop

s2/polygon.go:309–338  ·  view source on GitHub ↗

insertLoop adds the given loop to the loop map under the specified parent. All children of the new entry are checked to see if the need to move up to a different level.

(newLoop, parent *Loop)

Source from the content-addressed store, hash-verified

307// All children of the new entry are checked to see if the need to move up to
308// a different level.
309func (lm loopMap) insertLoop(newLoop, parent *Loop) {
310 var children []*Loop
311 for done := false; !done; {
312 children = lm[parent]
313 done = true
314 for _, child := range children {
315 if child.ContainsNested(newLoop) {
316 parent = child
317 done = false
318 break
319 }
320 }
321 }
322
323 // Now, we have found a parent for this loop, it may be that some of the
324 // children of the parent of this loop may now be children of the new loop.
325 newChildren := lm[newLoop]
326 for i := 0; i < len(children); {
327 child := children[i]
328 if newLoop.ContainsNested(child) {
329 newChildren = append(newChildren, child)
330 children = append(children[0:i], children[i+1:]...)
331 } else {
332 i++
333 }
334 }
335
336 lm[newLoop] = newChildren
337 lm[parent] = append(children, newLoop)
338}
339
340// loopStack simplifies access to the loops while being initialized.
341type loopStack []*Loop

Callers 1

initNestedMethod · 0.80

Calls 1

ContainsNestedMethod · 0.80

Tested by

no test coverage detected