forked from go-spatial/tegola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.go
93 lines (73 loc) · 1.87 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 basic
import (
"fmt"
"github.com/terranodo/tegola"
"github.com/terranodo/tegola/maths"
)
// Point describes a simple 2d point
type Point [2]float64
// Just to make basic collection only usable with basic types.
func (Point) basicType() {}
// AsPt returns the equivalent maths.Pt
func (p *Point) AsPt() maths.Pt {
if p == nil {
return maths.Pt{0, 0}
}
return maths.Pt{p[0], p[1]}
}
// X is the x coordinate
func (bp Point) X() float64 {
return bp[0]
}
// Y is the y coordinate
func (bp Point) Y() float64 {
return bp[1]
}
func (p Point) String() string {
return fmt.Sprintf("Point(%v,%v)", p[0], p[1])
}
// Point3 describes a simple 3d point
type Point3 [3]float64
// Just to make basic collection only usable with basic types.
func (Point3) basicType() {}
// X is the x coordinate
func (bp Point3) X() float64 {
return bp[0]
}
func (p Point3) String() string {
return fmt.Sprintf("Point3(%v,%v,%v)", p[0], p[1], p[2])
}
// Y is the y coordinate
func (bp Point3) Y() float64 {
return bp[1]
}
// Z is the z coordinate
func (bp Point3) Z() float64 {
return bp[2]
}
// MultiPoint describes a simple set of 2d points
type MultiPoint []Point
// Just to make basic collection only usable with basic types.
func (MultiPoint) basicType() {}
func (MultiPoint) String() string { return "MultiPoint" }
// Points are the points that make up the set
func (v MultiPoint) Points() (points []tegola.Point) {
for i := range v {
points = append(points, v[i])
}
return points
}
// MultiPoint3 describes a simple set of 3d points
type MultiPoint3 []Point3
// Just to make basic collection only usable with basic types.
func (MultiPoint3) basicType() {}
// Points are the points that make up the set
func (v MultiPoint3) Points() (points []tegola.Point) {
for i := range v {
points = append(points, v[i])
}
return points
}
func (MultiPoint3) String() string {
return "MultiPoint3"
}