-
Notifications
You must be signed in to change notification settings - Fork 4
/
point.go
68 lines (55 loc) · 1.17 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
package lambertgo
import "math"
// Point represents a generic point with three space coordinates and unit.
type Point struct {
X float64
Y float64
Z float64
Unit int32
}
const (
degreeToradian float64 = math.Pi / 180.0
radianTodegree float64 = 180.0 / math.Pi
gradTodegree float64 = 180.0 / 200.0
degreeTograd float64 = 200.0 / 180.0
gradToradian float64 = math.Pi / 200.0
radiantTograd float64 = 200.0 / math.Pi
)
func (pt *Point) scale(s float64) {
pt.X *= s
pt.Y *= s
pt.Z *= s
}
// ToDegree converts the coordinates from Radian or Grad to Degree.
func (pt *Point) ToDegree() {
switch pt.Unit {
case Radian:
pt.scale(radianTodegree)
case Grad:
pt.scale(gradTodegree)
default:
}
pt.Unit = Degree
}
// ToGrad converts the coordinates from Degree or Radian to Gradian.
func (pt *Point) ToGrad() {
switch pt.Unit {
case Radian:
pt.scale(radiantTograd)
case Degree:
pt.scale(degreeTograd)
default:
}
pt.Unit = Grad
}
// ToRadian converts the coordinates from Degree or Grad to Radian.
func (pt *Point) ToRadian() {
switch pt.Unit {
case Grad:
pt.scale(gradToradian)
case Degree:
pt.scale(degreeToradian)
default:
}
pt.Unit = Radian
}