This repository has been archived by the owner on May 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
431 lines (372 loc) · 7.93 KB
/
types.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
package asterisk
import (
"fmt"
"math"
"time"
"github.com/dc0d/gosweph"
)
//-----------------------------------------------------------------------------
// TransitFlag .
type TransitFlag int32
// TransitFlag valid values
const (
Rise TransitFlag = TransitFlag(gosweph.SE_CALC_RISE)
Set TransitFlag = TransitFlag(gosweph.SE_CALC_SET)
MTransit TransitFlag = TransitFlag(gosweph.SE_CALC_MTRANSIT)
ITransit TransitFlag = TransitFlag(gosweph.SE_CALC_ITRANSIT)
DiscCenter TransitFlag = TransitFlag(gosweph.SE_BIT_DISC_CENTER)
DiscBottom TransitFlag = TransitFlag(gosweph.SE_BIT_DISC_BOTTOM)
NoRefraction TransitFlag = TransitFlag(gosweph.SE_BIT_NO_REFRACTION)
CivilTwilight TransitFlag = TransitFlag(gosweph.SE_BIT_CIVIL_TWILIGHT)
NauticTwilight TransitFlag = TransitFlag(gosweph.SE_BIT_NAUTIC_TWILIGHT)
AstroTwilight TransitFlag = TransitFlag(gosweph.SE_BIT_ASTRO_TWILIGHT)
FixedDiscSize TransitFlag = TransitFlag(gosweph.SE_BIT_FIXED_DISC_SIZE)
)
//-----------------------------------------------------------------------------
// Degree .
type Degree float64
func (d Degree) String() string {
return DegreeString(DurationFromHour(float64(d)))
}
//-----------------------------------------------------------------------------
// Sign
// Sign .
type Sign int32
// Sign valid values
const (
Aries Sign = 1
Taurus Sign = 2
Gemini Sign = 3
Cancer Sign = 4
Leo Sign = 5
Virgo Sign = 6
Libra Sign = 7
Scorpio Sign = 8
Sagittarius Sign = 9
Capricorn Sign = 10
Aquarius Sign = 11
Pisces Sign = 12
)
func (s Sign) String() string {
return SignStrings[s]
}
// ParseSign .
func ParseSign(str string) Sign {
return SignParsed[str]
}
// SignOf .
func SignOf(lon float64) Sign {
rem := Mod(lon, 30.)
return Sign(math.Floor((lon-rem)/30.0) + 1.0)
}
// SignDegree .
func SignDegree(longitude float64) float64 {
return Mod(longitude, 30.)
}
// SignStrings helps with Sign implementing Stringer
var SignStrings = map[Sign]string{
Aries: "Aries",
Taurus: "Taurus",
Gemini: "Gemini",
Cancer: "Cancer",
Leo: "Leo",
Virgo: "Virgo",
Libra: "Libra",
Scorpio: "Scorpio",
Sagittarius: "Sagittarius",
Capricorn: "Capricorn",
Aquarius: "Aquarius",
Pisces: "Pisces",
}
// SignList .
var SignList = []Sign{
Aries,
Taurus,
Gemini,
Cancer,
Leo,
Virgo,
Libra,
Scorpio,
Sagittarius,
Capricorn,
Aquarius,
Pisces,
}
// SignParsed .
var SignParsed = map[string]Sign{
"Aries": Aries,
"Taurus": Taurus,
"Gemini": Gemini,
"Cancer": Cancer,
"Leo": Leo,
"Virgo": Virgo,
"Libra": Libra,
"Scorpio": Scorpio,
"Sagittarius": Sagittarius,
"Capricorn": Capricorn,
"Aquarius": Aquarius,
"Pisces": Pisces,
}
//-----------------------------------------------------------------------------
// Position
// Position .
type Position struct {
Lon, Lat float64
}
func (x Position) String() string {
return fmt.Sprintf("{lon: %s, lat: %s}", DegreeString(DurationFromHour(x.Lon)), DegreeString(DurationFromHour(x.Lat)))
}
//-----------------------------------------------------------------------------
// Planet
// Planet .
type Planet int32
// Planet valid values
var (
Su = Planet(1)
Mo = Planet(2)
Me = Planet(3)
Ve = Planet(4)
Ma = Planet(5)
Ju = Planet(6)
Sa = Planet(7)
Ur = Planet(8)
Ne = Planet(9)
Pl = Planet(10)
Ra = Planet(11)
Ke = Planet(12)
)
func (s Planet) String() string {
return PlanetStrings[s]
}
// Swe .
func (s Planet) Swe() int32 {
switch s {
case Su:
return gosweph.SE_SUN
case Mo:
return gosweph.SE_MOON
case Me:
return gosweph.SE_MERCURY
case Ve:
return gosweph.SE_VENUS
case Ma:
return gosweph.SE_MARS
case Ju:
return gosweph.SE_JUPITER
case Sa:
return gosweph.SE_SATURN
case Ur:
return gosweph.SE_URANUS
case Ne:
return gosweph.SE_NEPTUNE
case Pl:
return gosweph.SE_PLUTO
case Ra:
return NodeType
case Ke:
return NodeType
}
panic("not a valid planet")
}
// ParsePlanet .
func ParsePlanet(str string) Planet {
return PlanetParsed[str]
}
// PlanetStrings .
var PlanetStrings = map[Planet]string{
Su: "Su",
Mo: "Mo",
Me: "Me",
Ve: "Ve",
Ma: "Ma",
Ju: "Ju",
Sa: "Sa",
Ur: "Ur",
Ne: "Ne",
Pl: "Pl",
Ra: "Ra",
Ke: "Ke",
}
// PlanetList .
var PlanetList = []Planet{
Su,
Mo,
Me,
Ve,
Ma,
Ju,
Sa,
Ur,
Ne,
Pl,
Ra,
Ke,
}
// PlanetParsed .
var PlanetParsed = map[string]Planet{
"Su": Su,
"Mo": Mo,
"Me": Me,
"Ve": Ve,
"Ma": Ma,
"Ju": Ju,
"Sa": Sa,
"Ur": Ur,
"Ne": Ne,
"Pl": Pl,
"Ra": Ra,
"Ke": Ke,
}
// Spheres .
var Spheres = []Planet{
Mo,
Me,
Ve,
Su,
Ma,
Ju,
Sa,
}
//-----------------------------------------------------------------------------
// Flow
// Flow .
type Flow struct {
Distance, SpeedInLongitude, SpeedInLatitude, SpeedInDistance float64
}
func (x Flow) String() string {
return fmt.Sprintf("{dist: %f, in-lon: %s, in-lat: %s, in-dist: %s}", x.Distance, DegreeString(DurationFromHour(x.SpeedInLongitude)), DegreeString(DurationFromHour(x.SpeedInLatitude)), DegreeString(DurationFromHour(x.SpeedInDistance)))
}
//-----------------------------------------------------------------------------
// Point
// Point .
type Point struct {
ID Planet
Position Position
Flow Flow
}
func (p *Point) String() string {
return fmt.Sprintf("%v %v %v", p.ID, &p.Position, &p.Flow)
}
//-----------------------------------------------------------------------------
// Direction
// Direction .
type Direction bool
func (d Direction) String() string {
switch d {
case true:
return "Direct"
case false:
return "Reverse"
}
return ""
}
//-----------------------------------------------------------------------------
// House
// House .
type House int32
func (h House) String() string {
return HouseStrings[h]
}
// ParseHouse .
func ParseHouse(str string) House {
return HouseParsed[str]
}
// HouseOf .
func HouseOf(ascSign Sign, pointSign Sign) House {
n := pointSign - ascSign + 1
if n <= 0 {
n = n + 12
}
return House(n)
}
// House valid values
const (
H1 House = 1
H2 House = 2
H3 House = 3
H4 House = 4
H5 House = 5
H6 House = 6
H7 House = 7
H8 House = 8
H9 House = 9
H10 House = 10
H11 House = 11
H12 House = 12
)
// HouseStrings .
var HouseStrings = map[House]string{
H1: "H1",
H2: "H2",
H3: "H3",
H4: "H4",
H5: "H5",
H6: "H6",
H7: "H7",
H8: "H8",
H9: "H9",
H10: "H10",
H11: "H11",
H12: "H12",
}
// HouseList .
var HouseList = []House{
H1,
H2,
H3,
H4,
H5,
H6,
H7,
H8,
H9,
H10,
H11,
H12,
}
// HouseParsed .
var HouseParsed = map[string]House{
"H1": H1,
"H2": H2,
"H3": H3,
"H4": H4,
"H5": H5,
"H6": H6,
"H7": H7,
"H8": H8,
"H9": H9,
"H10": H10,
"H11": H11,
"H12": H12,
}
//-----------------------------------------------------------------------------
// JulianDay
// JulianDay .
type JulianDay float64
// JulianDayOf input should be universal time
func JulianDayOf(t time.Time) JulianDay {
year, month, day := int32(t.Year()), int32(t.Month()), int32(t.Day())
hour := float64(t.Hour()) + float64(t.Minute())/60. + float64(t.Second())/3600. + float64(t.Nanosecond())/(1000.*1000.*1000.)/3600.
hour = math.Floor(hour*10000000.) / 10000000.
flag := gosweph.SE_GREG_CAL
if (year*10000 + month*100 + day) < 15821015 {
flag = gosweph.SE_JUL_CAL
}
return JulianDay(gosweph.Swe_julday(year, month, day, hour, flag))
}
// Shift .
func (x JulianDay) Shift(dt time.Duration) JulianDay {
days := dt.Hours() / 24.
return x + JulianDay(days)
}
// Time .
func (x JulianDay) Time() time.Time {
var iyear, imonth, iday, ihour, imin int32
var dsec float64
gosweph.Swe_jdut1_to_utc(float64(x), gosweph.SE_GREG_CAL, &iyear, &imonth, &iday, &ihour, &imin, &dsec)
sec := int(math.Floor(dsec))
nsec := int((dsec - float64(sec)) * NanosecondFactor)
return time.Date(int(iyear), time.Month(imonth), int(iday), int(ihour), int(imin), sec, nsec, time.UTC)
}
//-----------------------------------------------------------------------------