forked from twpayne/go-geom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinearring.go
67 lines (56 loc) · 1.66 KB
/
linearring.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 geom
// A LinearRing is a linear ring.
type LinearRing struct {
geom1
}
// NewLinearRing returns a new LinearRing with no coordinates.
func NewLinearRing(layout Layout) *LinearRing {
return NewLinearRingFlat(layout, nil)
}
// NewLinearRingFlat returns a new LinearRing with the given flat coordinates.
func NewLinearRingFlat(layout Layout, flatCoords []float64) *LinearRing {
lr := new(LinearRing)
lr.layout = layout
lr.stride = layout.Stride()
lr.flatCoords = flatCoords
return lr
}
// Area returns the the area.
func (lr *LinearRing) Area() float64 {
return doubleArea1(lr.flatCoords, 0, len(lr.flatCoords), lr.stride) / 2
}
// Clone returns a deep copy.
func (lr *LinearRing) Clone() *LinearRing {
flatCoords := make([]float64, len(lr.flatCoords))
copy(flatCoords, lr.flatCoords)
return NewLinearRingFlat(lr.layout, flatCoords)
}
// Empty returns false.
func (lr *LinearRing) Empty() bool {
return false
}
// Length returns the length of the perimeter.
func (lr *LinearRing) Length() float64 {
return length1(lr.flatCoords, 0, len(lr.flatCoords), lr.stride)
}
// MustSetCoords sets the coordinates and panics if there is any error.
func (lr *LinearRing) MustSetCoords(coords []Coord) *LinearRing {
Must(lr.SetCoords(coords))
return lr
}
// SetCoords sets the coordinates.
func (lr *LinearRing) SetCoords(coords []Coord) (*LinearRing, error) {
if err := lr.setCoords(coords); err != nil {
return nil, err
}
return lr, nil
}
// SetSRID sets the SRID of lr.
func (lr *LinearRing) SetSRID(srid int) *LinearRing {
lr.srid = srid
return lr
}
// Swap swaps the values of lr and lr2.
func (lr *LinearRing) Swap(lr2 *LinearRing) {
lr.geom1.swap(&lr2.geom1)
}