-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathpointm.go
More file actions
41 lines (33 loc) · 701 Bytes
/
pointm.go
File metadata and controls
41 lines (33 loc) · 701 Bytes
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
package geom
import (
"errors"
)
// ErrNilPointM is thrown when a point is null but shouldn't be
var ErrNilPointM = errors.New("geom: nil PointM")
// Point describes a simple 2D+1D point
type PointM [3]float64
// XYM returns an array of 2D+1D coordinates
func (p PointM) XYM() [3]float64 {
return p
}
// XY returns an array of 2D coordinates
func (p PointM) XY() [2]float64 {
return Point{
p[0],
p[1],
}
}
// M returns the metric related to the 2D point
func (p PointM) M() float64 {
return p[2]
}
// SetXYM sets the three coordinates
func (p *PointM) SetXYM(xym [3]float64) (err error) {
if p == nil {
return ErrNilPointM
}
p[0] = xym[0]
p[1] = xym[1]
p[2] = xym[2]
return
}