forked from twpayne/go-geom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multipoint.go
84 lines (70 loc) · 1.89 KB
/
multipoint.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package geom
// A MultiPoint is a collection of Points.
type MultiPoint struct {
geom1
}
// NewMultiPoint returns a new, empty, MultiPoint.
func NewMultiPoint(layout Layout) *MultiPoint {
return NewMultiPointFlat(layout, nil)
}
// NewMultiPointFlat returns a new MultiPoint with the given flat coordinates.
func NewMultiPointFlat(layout Layout, flatCoords []float64) *MultiPoint {
mp := new(MultiPoint)
mp.layout = layout
mp.stride = layout.Stride()
mp.flatCoords = flatCoords
return mp
}
// Area returns zero.
func (mp *MultiPoint) Area() float64 {
return 0
}
// Clone returns a deep copy.
func (mp *MultiPoint) Clone() *MultiPoint {
return deriveCloneMultiPoint(mp)
}
// Empty returns true if the collection is empty.
func (mp *MultiPoint) Empty() bool {
return mp.NumPoints() == 0
}
// Length returns zero.
func (mp *MultiPoint) Length() float64 {
return 0
}
// MustSetCoords sets the coordinates and panics on any error.
func (mp *MultiPoint) MustSetCoords(coords []Coord) *MultiPoint {
Must(mp.SetCoords(coords))
return mp
}
// SetCoords sets the coordinates.
func (mp *MultiPoint) SetCoords(coords []Coord) (*MultiPoint, error) {
if err := mp.setCoords(coords); err != nil {
return nil, err
}
return mp, nil
}
// SetSRID sets the SRID of mp.
func (mp *MultiPoint) SetSRID(srid int) *MultiPoint {
mp.srid = srid
return mp
}
// NumPoints returns the number of Points.
func (mp *MultiPoint) NumPoints() int {
return mp.NumCoords()
}
// Point returns the ith Point.
func (mp *MultiPoint) Point(i int) *Point {
return NewPointFlat(mp.layout, mp.Coord(i))
}
// Push appends a point.
func (mp *MultiPoint) Push(p *Point) error {
if p.layout != mp.layout {
return ErrLayoutMismatch{Got: p.layout, Want: mp.layout}
}
mp.flatCoords = append(mp.flatCoords, p.flatCoords...)
return nil
}
// Swap swaps the values of mp and mp2.
func (mp *MultiPoint) Swap(mp2 *MultiPoint) {
*mp, *mp2 = *mp2, *mp
}