-
Notifications
You must be signed in to change notification settings - Fork 0
/
angle.go
201 lines (170 loc) · 3.04 KB
/
angle.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package ops
import (
"github.com/blackchip-org/dms"
"github.com/blackchip-org/zc/v5/pkg/zc"
)
/*
oper dec
func DecDMS p0:DMS -- Float
title DMS angle to decimal degrees
desc
Convert the DMS angle *p0* to decimal degrees.
end
example
10d7m24.24s dec -- 10.1234
end
*/
func DecDMS(c zc.Calc) {
p0 := zc.PopDMS(c)
r0 := p0.Degrees()
zc.PushFloat(c, r0)
}
/*
oper deg-min
func DM p0:DMS -- DMS
alias dm
title Angle in degrees and minutes
desc
Reformat the angle *p0* to degrees and minutes
end
example
10.1234 dm -- 10° 7.404000000000011′
end
*/
func DM(c zc.Calc) {
f := dms.NewFormatter(dms.MinType, -1)
p0 := zc.PopDMS(c)
r0 := f.Format(p0)
zc.PushString(c, r0)
}
/*
oper deg-min-round
func DMRound p0:DMS n:Int -- DMS
alias dmr
title Rounded angle in degrees and minutes
desc
Reformat the angle *p0* to degrees and minutes and round the minutes to
*n* places.
end
example
12.57611 3 dmr -- 12° 34.567′
end
*/
func DMRound(c zc.Calc) {
places := zc.PopInt(c)
f := dms.NewFormatter(dms.MinType, places)
p0 := zc.PopDMS(c)
r0 := f.Format(p0)
zc.PushString(c, r0)
}
/*
oper deg-min-sec
func DMS p0:DMS -- DMS
alias dms
title Angle in degrees and minutes
desc
Reformat the angle *p0* to degrees, minutes, and seconds.
end
example
-76.856944 dms -- -76° 51′ 24.998399999994945″
end
*/
func DMS(c zc.Calc) {
p0 := zc.PopDMS(c)
zc.PushDMS(c, p0)
}
/*
oper deg-min-sec-round
func DMSRound p0:DMS n:Int -- DMS
alias dmsr
title Rounded angle in degrees, minutes, seconds
desc
Reformat the angle *p0* to degrees, minutes, and seconds, and round the
seconds to *n* places.
end
example
-76.856944 0 dmsr -- -76° 51′ 25″
end
*/
func DMSRound(c zc.Calc) {
places := zc.PopInt(c)
f := dms.NewFormatter(dms.SecType, places)
p0 := zc.PopDMS(c)
r0 := f.Format(p0)
zc.PushString(c, r0)
}
/*
oper deg-rad
func - p0:DMS -- Decimal
macro pi 180 div mul
title Degrees to radians
desc
Converts the angle *p0* in degrees to radians
end
example
90 deg-rad -- 1.5707963267948966
end
*/
/*
oper is-dms
func IsDMS p0:Str -- Bool
alias is-dec-min-sec
title Checks value can be parsed as degree, minutes, seconds
desc
Returns `true` if the value *p0* can be parsed as an angle with degrees,
minutes, and seconds.
end
example
c [10° 30′ 45″] is-dms -- true
c [10 30 45 ] is-dms -- false
end
*/
func IsDMS(c zc.Calc) {
p0 := zc.PopString(c)
r0 := zc.DMS.Is(p0)
zc.PushBool(c, r0)
}
/*
oper minutes
func MinutesDMS p0:DMS -- Float
title Angle in minutes
desc
Converts the angle *p0* to minutes.
end
example
10d30m minutes -- 630
end
*/
func MinutesDMS(c zc.Calc) {
p0 := zc.PopDMS(c)
r0 := p0.Minutes()
zc.PushFloat(c, r0)
}
/*
oper rad-deg
func - p0:Decimal -- DMS
macro 180 pi div mul
title Degrees to radians
desc
Converts the angle *p0* in radians to degrees
end
example
1.570796326794897 rad-deg 2 round -- 90
end
*/
/*
oper seconds
func SecondsDMS p0:DMS -- Float
title Angle in seconds
desc
Converts the angle *p0* to seconds.
end
example
10d30m seconds -- 37800
end
*/
func SecondsDMS(c zc.Calc) {
p0 := zc.PopDMS(c)
r0 := p0.Seconds()
zc.PushFloat(c, r0)
}