-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
68 lines (55 loc) · 1.41 KB
/
utils.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 main
import (
"math"
"time"
"github.com/mshafiee/swephgo"
)
/* general helpers */
func jdToUTC(jd *float64) time.Time {
year := make([]int, 1)
month := make([]int, 1)
day := make([]int, 1)
hour := make([]float64, 1)
swephgo.Revjul(*jd, swephgo.SeGregCal, year, month, day, hour)
h := int(hour[0])
m := int(60 * (hour[0] - float64(h)))
utc := time.Date(year[0], time.Month(month[0]), day[0], h, m, 0, 0, time.UTC)
return utc
}
func jdToLocal(jd *float64) time.Time {
utc := jdToUTC(jd)
return utc.In(location)
}
func julian(d time.Time) *float64 {
h := float64(d.Hour()) + float64(d.Minute())/60 + float64(d.Second())/3600
jd := swephgo.Julday(d.Year(), int(d.Month()), d.Day(), h, swephgo.SeGregCal)
return &jd
}
/* Begining of the Day */
func bod(t time.Time) time.Time {
year, month, day := t.Date()
return time.Date(year, month, day, 0, 0, 0, 0, time.Local)
}
/* Noon of the Day */
func nod(t time.Time) time.Time {
year, month, day := t.Date()
return time.Date(year, month, day, 12, 0, 0, 0, time.Local)
}
func smallestSignedAngleBetween(x float64, y float64) float64 {
return math.Min(2.0*math.Pi-math.Abs(x-y), math.Abs(x-y))
}
func fixangle(a float64) float64 {
return (a - 360*math.Floor(a/360))
}
func rad2deg(r float64) float64 {
return (r * 180) / math.Pi
}
func deg2rad(d float64) float64 {
return (d * math.Pi) / 180
}
func bool2int(b bool) int {
if b {
return 1
}
return 0
}