forked from twpayne/go-geom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint.go
93 lines (78 loc) · 1.95 KB
/
point.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
85
86
87
88
89
90
91
92
93
package geom
// A Point represents a single point.
type Point struct {
geom0
}
// NewPoint allocates a new Point with layout l and all values zero.
func NewPoint(l Layout) *Point {
return NewPointFlat(l, make([]float64, l.Stride()))
}
// NewPointEmpty allocates a new Point with no coordinates.
func NewPointEmpty(l Layout) *Point {
return NewPointFlat(l, []float64{})
}
// NewPointFlat allocates a new Point with layout l and flat coordinates flatCoords.
func NewPointFlat(l Layout, flatCoords []float64) *Point {
g := new(Point)
g.layout = l
g.stride = l.Stride()
g.flatCoords = flatCoords
return g
}
// Area returns g's area, i.e. zero.
func (g *Point) Area() float64 {
return 0
}
// Clone returns a copy of g that does not alias g.
func (g *Point) Clone() *Point {
return deriveClonePoint(g)
}
// Length returns the length of g, i.e. zero.
func (g *Point) Length() float64 {
return 0
}
// MustSetCoords is like SetCoords but panics on any error.
func (g *Point) MustSetCoords(coords Coord) *Point {
Must(g.SetCoords(coords))
return g
}
// SetCoords sets the coordinates of g.
func (g *Point) SetCoords(coords Coord) (*Point, error) {
if err := g.setCoords(coords); err != nil {
return nil, err
}
return g, nil
}
// SetSRID sets the SRID of g.
func (g *Point) SetSRID(srid int) *Point {
g.srid = srid
return g
}
// Swap swaps the values of g and g2.
func (g *Point) Swap(g2 *Point) {
*g, *g2 = *g2, *g
}
// X returns g's X-coordinate.
func (g *Point) X() float64 {
return g.flatCoords[0]
}
// Y returns g's Y-coordinate.
func (g *Point) Y() float64 {
return g.flatCoords[1]
}
// Z returns g's Z-coordinate, or zero if g has no Z-coordinate.
func (g *Point) Z() float64 {
zIndex := g.layout.ZIndex()
if zIndex == -1 {
return 0
}
return g.flatCoords[zIndex]
}
// M returns g's M-coordinate, or zero if g has no M-coordinate.
func (g *Point) M() float64 {
mIndex := g.layout.MIndex()
if mIndex == -1 {
return 0
}
return g.flatCoords[mIndex]
}