@@ -7,11 +7,11 @@ inline T map(T2 val, T2 in_min, T2 in_max, T out_min, T out_max) {
7
7
return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
8
8
}
9
9
10
- static inline double _fhour ( const struct tm &timeinfo ) {
11
- return timeinfo.tm_hour + map ( ( timeinfo.tm_min * 60 ) + timeinfo.tm_sec , 0 , 3600 , 0.0 , 1.0 );
10
+ double moonPhase:: _fhour (const struct tm &timeinfo) {
11
+ return timeinfo.tm_hour + map (( timeinfo.tm_min * 60 ) + timeinfo.tm_sec , 0 , 3600 , 0.0 , 1.0 );
12
12
}
13
13
14
- static double _Julian ( int32_t year, int32_t month, const double &day )
14
+ static double _Julian (int32_t year, int32_t month, const double &day)
15
15
{
16
16
int32_t b, c, e;
17
17
b = 0 ;
@@ -30,15 +30,15 @@ static double _Julian( int32_t year, int32_t month, const double &day )
30
30
return b + c + e + day + 1720994.5 ;
31
31
}
32
32
33
- static double _sun_position ( const double &j )
33
+ static double _sun_position (const double &j)
34
34
{
35
35
double n, x, e, l, dl, v;
36
36
int32_t i;
37
37
n = 360 / 365.2422 * j;
38
38
i = n / 360 ;
39
39
n = n - i * 360.0 ;
40
40
x = n - 3.762863 ;
41
- if (x < 0 ) x += 360 ;
41
+ x += (x < 0 ) ? 360 : 0 ;
42
42
x *= DEG_TO_RAD;
43
43
e = x;
44
44
do {
@@ -52,16 +52,16 @@ static double _sun_position( const double &j )
52
52
return l;
53
53
}
54
54
55
- static double _moon_position ( const double &j, const double &ls )
55
+ static double _moon_position (const double &j, const double &ls)
56
56
{
57
57
double ms, l, mm, ev, sms, ae, ec;
58
58
int32_t i;
59
59
ms = 0.985647332099 * j - 3.762863 ;
60
- if (ms < 0 ) ms += 360.0 ;
60
+ ms += (ms < 0 ) ? 360.0 : 0 ;
61
61
l = 13.176396 * j + 64.975464 ;
62
62
i = l / 360 ;
63
63
l = l - i * 360.0 ;
64
- if (l < 0 ) l += 360. 0 ;
64
+ l += (l < 0 ) ? 360 : 0 ;
65
65
mm = l - 0.1114041 * j - 349.383063 ;
66
66
i = mm / 360 ;
67
67
mm -= i * 360.0 ;
@@ -75,7 +75,7 @@ static double _moon_position( const double &j, const double &ls )
75
75
return l;
76
76
}
77
77
78
- static moonData_t _getPhase ( const int32_t & year, const int32_t & month, const int32_t & day, const double &hour )
78
+ moonData_t moonPhase:: _getPhase (const int32_t year, const int32_t month, const int32_t day, const double &hour)
79
79
{
80
80
/*
81
81
Calculates the phase of the moon at the given epoch.
@@ -85,19 +85,14 @@ static moonData_t _getPhase( const int32_t &year, const int32_t &month, const in
85
85
double ls = _sun_position (j);
86
86
double lm = _moon_position (j, ls);
87
87
double t = lm - ls;
88
- if (t < 0 ) t += 360 ;
88
+ t += (t < 0 ) ? 360 : 0 ;
89
89
moonData_t returnValue;
90
90
returnValue.angle = t;
91
91
returnValue.percentLit = (1.0 - cos ((lm - ls) * DEG_TO_RAD)) / 2 ;
92
92
return returnValue;
93
93
}
94
94
95
- moonData_t moonPhase::getPhase ( const time_t t )
96
- {
97
- struct tm timeinfo;
98
- gmtime_r ( &t, &timeinfo );
99
- return _getPhase ( 1900 + timeinfo.tm_year , 1 + timeinfo.tm_mon , timeinfo.tm_mday , _fhour ( timeinfo ) );
100
- }
95
+
101
96
102
97
103
98
0 commit comments