Skip to content

Commit e0596bb

Browse files
More const.
1 parent 07bcedd commit e0596bb

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

moonPhase.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,19 @@ moonData_t moonPhase::_getPhase(const int32_t year, const int32_t month, const i
7979
{
8080
/*
8181
Calculates the phase of the moon at the given epoch.
82+
returns the moon phase angle as an int (0-360)
8283
returns the moon percentage that is lit as a real number (0-1)
8384
*/
84-
double j = _Julian(year, month, (double)day + hour / 24.0) - 2444238.5;
85-
double ls = _sun_position(j);
86-
double lm = _moon_position(j, ls);
87-
double t = lm - ls;
88-
t += (t < 0) ? 360 : 0;
89-
moonData_t returnValue;
90-
returnValue.angle = t;
91-
returnValue.percentLit = (1.0 - cos((lm - ls) * DEG_TO_RAD)) / 2;
85+
const double j {_Julian(year, month, (double)day + hour / 24.0) - 2444238.5};
86+
const double ls {_sun_position(j)};
87+
const double lm {_moon_position(j, ls)};
88+
double angle = lm - ls;
89+
angle += (angle < 0) ? 360 : 0;
90+
const moonData_t returnValue
91+
{
92+
(int32_t)angle,
93+
(1.0 - cos((lm - ls) * DEG_TO_RAD)) / 2
94+
};
9295
return returnValue;
9396
}
9497

95-
96-
97-
98-

0 commit comments

Comments
 (0)