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

Function makePolygon

s2/textformat_test.go:194–217  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

192// "empty" // the empty polygon (consisting of no loops)
193// "full" // the full polygon (consisting of one full loop)
194func 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.
220func makePolyline(s string) *Polyline {

Callers 6

TestEncodeDecodeFunction · 0.85
polygon_test.goFile · 0.85
TestPolygonContainsPointFunction · 0.85
TestPolygonAreaFunction · 0.85
TestPolygonCentroidFunction · 0.85

Calls 4

PolygonFromLoopsFunction · 0.85
makeLoopFunction · 0.85
IsFullMethod · 0.65
NormalizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…