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
()
| 885 | // Notice that the last edge is the same in both cases except that its |
| 886 | // direction has been reversed. |
| 887 | func (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. |