@@ -7,41 +7,11 @@ inline T map(T2 val, T2 in_min, T2 in_max, T out_min, T out_max) {
77 return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
88}
99
10- inline double moonPhase:: _fhour ( const struct tm &timeinfo ) {
10+ static inline double _fhour ( const struct tm &timeinfo ) {
1111 return timeinfo.tm_hour + map ( ( timeinfo.tm_min * 60 ) + timeinfo.tm_sec , 0 , 3600 , 0.0 , 1.0 );
1212}
1313
14- moonData_t moonPhase::_getPhase ( const int32_t &year, const int32_t &month, const int32_t &day, const double &hour )
15- {
16- /*
17- Calculates the phase of the moon at the given epoch.
18- returns the moon percentage that is lit as a real number (0-1)
19- */
20- moonData_t returnValue;
21- double j = _Julian (year, month, (double )day + hour / 24.0 ) - 2444238.5 ;
22- double ls = _sun_position (j);
23- double lm = _moon_position (j, ls);
24- double t = lm - ls;
25- if (t < 0 ) t += 360 ;
26- returnValue.angle = t;
27- returnValue.percentLit = (1.0 - cos ((lm - ls) * DEG_TO_RAD)) / 2 ;
28- return returnValue;
29- }
30-
31- moonData_t moonPhase::getPhase ( const time_t t ) {
32- struct tm timeinfo;
33- gmtime_r ( &t, &timeinfo );
34- double hour = _fhour ( timeinfo );
35- return _getPhase ( 1900 + timeinfo.tm_year , 1 + timeinfo.tm_mon , timeinfo.tm_mday , hour );
36- }
37-
38- moonData_t moonPhase::getPhase () {
39- time_t now;
40- time ( &now );
41- return getPhase ( now );
42- }
43-
44- double moonPhase::_Julian ( int32_t year, int32_t month, const double &day )
14+ static double _Julian ( int32_t year, int32_t month, const double &day )
4515{
4616 int32_t b, c, e;
4717 b = 0 ;
@@ -60,7 +30,7 @@ double moonPhase::_Julian( int32_t year, int32_t month, const double &day )
6030 return b + c + e + day + 1720994.5 ;
6131}
6232
63- double moonPhase:: _sun_position ( const double &j )
33+ static double _sun_position ( const double &j )
6434{
6535 double n, x, e, l, dl, v;
6636 int32_t i;
@@ -82,7 +52,7 @@ double moonPhase::_sun_position( const double &j )
8252 return l;
8353}
8454
85- double moonPhase:: _moon_position ( const double &j, const double &ls )
55+ static double _moon_position ( const double &j, const double &ls )
8656{
8757 double ms, l, mm, ev, sms, ae, ec;
8858 int32_t i;
@@ -105,3 +75,36 @@ double moonPhase::_moon_position( const double &j, const double &ls )
10575 return l;
10676}
10777
78+ static moonData_t _getPhase ( const int32_t &year, const int32_t &month, const int32_t &day, const double &hour )
79+ {
80+ /*
81+ Calculates the phase of the moon at the given epoch.
82+ returns the moon percentage that is lit as a real number (0-1)
83+ */
84+ moonData_t returnValue;
85+ double j = _Julian (year, month, (double )day + hour / 24.0 ) - 2444238.5 ;
86+ double ls = _sun_position (j);
87+ double lm = _moon_position (j, ls);
88+ double t = lm - ls;
89+ if (t < 0 ) t += 360 ;
90+ returnValue.angle = t;
91+ returnValue.percentLit = (1.0 - cos ((lm - ls) * DEG_TO_RAD)) / 2 ;
92+ return returnValue;
93+ }
94+
95+ moonData_t moonPhase::getPhase ()
96+ {
97+ time_t now = time (NULL );
98+ return getPhase ( now );
99+ }
100+
101+ moonData_t moonPhase::getPhase ( const time_t t )
102+ {
103+ struct tm timeinfo;
104+ gmtime_r ( &t, &timeinfo );
105+ double hour = _fhour ( timeinfo );
106+ return _getPhase ( 1900 + timeinfo.tm_year , 1 + timeinfo.tm_mon , timeinfo.tm_mday , hour );
107+ }
108+
109+
110+
0 commit comments