forked from paulmach/orb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polygon.go
55 lines (45 loc) · 1.09 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
package orb
// Polygon is a closed area. The first LineString is the outer ring.
// The others are the holes. Each LineString is expected to be closed
// ie. the first point matches the last.
type Polygon []Ring
// GeoJSONType returns the GeoJSON type for the object.
func (p Polygon) GeoJSONType() string {
return "Polygon"
}
// Dimensions returns 2 because a Polygon is a 2d object.
func (p Polygon) Dimensions() int {
return 2
}
// Bound returns a bound around the polygon.
func (p Polygon) Bound() Bound {
if len(p) == 0 {
return emptyBound
}
return p[0].Bound()
}
// Equal compares two polygons. Returns true if lengths are the same
// and all points are Equal.
func (p Polygon) Equal(polygon Polygon) bool {
if len(p) != len(polygon) {
return false
}
for i := range p {
if !p[i].Equal(polygon[i]) {
return false
}
}
return true
}
// Clone returns a new deep copy of the polygon.
// All of the rings are also cloned.
func (p Polygon) Clone() Polygon {
if p == nil {
return p
}
np := make(Polygon, 0, len(p))
for _, r := range p {
np = append(np, r.Clone())
}
return np
}