forked from go-spatial/tegola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polygon.go
67 lines (58 loc) · 1.65 KB
/
polygon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package basic
import (
"github.com/terranodo/tegola"
"github.com/terranodo/tegola/maths"
)
// Polygon describes a basic polygon; made up of multiple lines.
type Polygon []Line
// Just to make basic collection only usable with basic types.
func (Polygon) basicType() {}
// Sublines returns the lines that make up the polygon.
func (p Polygon) Sublines() (slines []tegola.LineString) {
slines = make([]tegola.LineString, 0, len(p))
for i := range p {
slines = append(slines, p[i])
}
return slines
}
func (Polygon) String() string {
return "Polygon"
}
// MultiPolygon describes a set of polygons.
type MultiPolygon []Polygon
// Just to make basic collection only usable with basic types.
func (MultiPolygon) basicType() {}
// Polygons retuns the polygons that make up the set.
func (mp MultiPolygon) Polygons() (polygons []tegola.Polygon) {
polygons = make([]tegola.Polygon, 0, len(mp))
for i := range mp {
polygons = append(polygons, mp[i])
}
return polygons
}
func (MultiPolygon) String() string {
return "MultiPolygon"
}
func NewPolygon(main []maths.Pt, clines ...[]maths.Pt) Polygon {
p := Polygon{NewLineFromPt(main...)}
for _, l := range clines {
p = append(p, NewLineFromPt(l...))
}
return p
}
func NewPolygonFromSubLines(lines ...tegola.LineString) (p Polygon) {
p = make(Polygon, 0, len(lines))
for i := range lines {
l := NewLineFromSubPoints(lines[i].Subpoints()...)
p = append(p, l)
}
return p
}
func NewMultiPolygonFromPolygons(polygons ...tegola.Polygon) (mp MultiPolygon) {
mp = make(MultiPolygon, 0, len(polygons))
for i := range polygons {
p := NewPolygonFromSubLines(polygons[i].Sublines()...)
mp = append(mp, p)
}
return mp
}