-
Notifications
You must be signed in to change notification settings - Fork 105
/
multi_polygon.go
56 lines (45 loc) · 1.04 KB
/
multi_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
package orb
// MultiPolygon is a set of polygons.
type MultiPolygon []Polygon
// GeoJSONType returns the GeoJSON type for the object.
func (mp MultiPolygon) GeoJSONType() string {
return "MultiPolygon"
}
// Dimensions returns 2 because a MultiPolygon is a 2d object.
func (mp MultiPolygon) Dimensions() int {
return 2
}
// Bound returns a bound around the multi-polygon.
func (mp MultiPolygon) Bound() Bound {
if len(mp) == 0 {
return emptyBound
}
bound := mp[0].Bound()
for i := 1; i < len(mp); i++ {
bound = bound.Union(mp[i].Bound())
}
return bound
}
// Equal compares two multi-polygons.
func (mp MultiPolygon) Equal(multiPolygon MultiPolygon) bool {
if len(mp) != len(multiPolygon) {
return false
}
for i, p := range mp {
if !p.Equal(multiPolygon[i]) {
return false
}
}
return true
}
// Clone returns a new deep copy of the multi-polygon.
func (mp MultiPolygon) Clone() MultiPolygon {
if mp == nil {
return nil
}
nmp := make(MultiPolygon, 0, len(mp))
for _, p := range mp {
nmp = append(nmp, p.Clone())
}
return nmp
}