makePolygon constructs a polygon from the sequence of loops in the input string. Loops are automatically normalized by inverting them if necessary so that they enclose at most half of the unit sphere. (Historically this was once a requirement of polygon loops. It also hides the problem that if the u
(s string, normalize bool)
| 192 | // "empty" // the empty polygon (consisting of no loops) |
| 193 | // "full" // the full polygon (consisting of one full loop) |
| 194 | func makePolygon(s string, normalize bool) *Polygon { |
| 195 | var loops []*Loop |
| 196 | // Avoid the case where strings.Split on empty string will still return |
| 197 | // one empty value, where we want no values. |
| 198 | if s == "empty" || s == "" { |
| 199 | return PolygonFromLoops(loops) |
| 200 | } |
| 201 | |
| 202 | for _, str := range strings.Split(s, ";") { |
| 203 | // The polygon test strings mostly have a trailing semicolon |
| 204 | // (to make concatenating them for tests easy). The C++ |
| 205 | // SplitString doesn't return empty elements where as Go does, |
| 206 | // so we need to check before using it. |
| 207 | if str == "" { |
| 208 | continue |
| 209 | } |
| 210 | loop := makeLoop(strings.TrimSpace(str)) |
| 211 | if normalize && !loop.IsFull() { |
| 212 | loop.Normalize() |
| 213 | } |
| 214 | loops = append(loops, loop) |
| 215 | } |
| 216 | return PolygonFromLoops(loops) |
| 217 | } |
| 218 | |
| 219 | // makePolyline constructs a Polyline from the given string. |
| 220 | func makePolyline(s string) *Polyline { |
no test coverage detected
searching dependent graphs…