Skip to content

Commit

Permalink
Enhance code readability of alwaysUp/alwaysDown check
Browse files Browse the repository at this point in the history
  • Loading branch information
shred committed Jul 8, 2019
1 parent e7552dc commit 8705e38
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/main/java/org/shredzone/commons/suncalc/SunTimes.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,16 @@ public SunTimes execute() {
Double set = null;
Double noon = null;
Double nadir = null;
boolean alwaysUp = true;
boolean alwaysDown = true;
boolean alwaysUp = false;
boolean alwaysDown = false;
double ye;

double y_minus = correctedSunHeight(jd);
if (y_minus > 0.0) {
alwaysUp = true;
} else {
alwaysDown = true;
}

int maxHours = fullCycle ? 365 * 24 : 24;
for (int hour = 1; hour < maxHours; hour++) {
Expand Down Expand Up @@ -308,11 +313,6 @@ public SunTimes execute() {
}

if (hour < 24) {
if (y_0 > 0.0) {
alwaysDown = false;
} else {
alwaysUp = false;
}
double xeAbs = Math.abs(qi.getXe());
if (xeAbs <= 1.0) {
double xeHour = qi.getXe() + hour;
Expand All @@ -324,6 +324,15 @@ public SunTimes execute() {
}
}

if (hour == 23) {
if (rise != null) {
alwaysDown = false;
}
if (set != null) {
alwaysUp = false;
}
}

if (hour >= 24 && rise != null && set != null) {
break;
}
Expand Down

0 comments on commit 8705e38

Please sign in to comment.