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

Method Invert

s2/loop.go:887–913  ·  view source on GitHub ↗

Invert reverses the order of the loop vertices, effectively complementing the region represented by the loop. For example, the loop ABCD (with edges AB, BC, CD, DA) becomes the loop DCBA (with edges DC, CB, BA, AD). Notice that the last edge is the same in both cases except that its direction has be

()

Source from the content-addressed store, hash-verified

885// Notice that the last edge is the same in both cases except that its
886// direction has been reversed.
887func (l *Loop) Invert() {
888 l.index.Reset()
889 if l.isEmptyOrFull() {
890 if l.IsFull() {
891 l.vertices[0] = emptyLoopPoint
892 } else {
893 l.vertices[0] = fullLoopPoint
894 }
895 } else {
896 // For non-special loops, reverse the slice of vertices.
897 for i := len(l.vertices)/2 - 1; i >= 0; i-- {
898 opp := len(l.vertices) - 1 - i
899 l.vertices[i], l.vertices[opp] = l.vertices[opp], l.vertices[i]
900 }
901 }
902
903 // originInside must be set correctly before building the ShapeIndex.
904 l.originInside = !l.originInside
905 if l.bound.Lat.Lo > -math.Pi/2 && l.bound.Lat.Hi < math.Pi/2 {
906 // The complement of this loop contains both poles.
907 l.bound = FullRect()
908 l.subregionBound = l.bound
909 } else {
910 l.initBound()
911 }
912 l.index.Add(l)
913}
914
915// findVertex returns the index of the vertex at the given Point in the range
916// 1..numVertices, and a boolean indicating if a vertex was found.

Callers 10

NormalizeMethod · 0.95
TestLoopRectBoundFunction · 0.45
TestLoopRelationsFunction · 0.45
testLoopNestedPairFunction · 0.45
testLoopOneCoveringPairFunction · 0.45
TestLoopTurningAngleFunction · 0.45
TestPolygonInvertFunction · 0.45

Calls 6

isEmptyOrFullMethod · 0.95
IsFullMethod · 0.95
initBoundMethod · 0.95
FullRectFunction · 0.85
ResetMethod · 0.45
AddMethod · 0.45

Tested by 9

TestLoopRectBoundFunction · 0.36
TestLoopRelationsFunction · 0.36
testLoopNestedPairFunction · 0.36
testLoopOneCoveringPairFunction · 0.36
TestLoopTurningAngleFunction · 0.36
TestPolygonInvertFunction · 0.36