From 8705e38fac227a7766e55f4b970cdc219e8f2e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20K=C3=B6rber?= Date: Mon, 8 Jul 2019 23:08:48 +0200 Subject: [PATCH] Enhance code readability of alwaysUp/alwaysDown check --- .../shredzone/commons/suncalc/SunTimes.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/shredzone/commons/suncalc/SunTimes.java b/src/main/java/org/shredzone/commons/suncalc/SunTimes.java index 437a2da..a9bc319 100644 --- a/src/main/java/org/shredzone/commons/suncalc/SunTimes.java +++ b/src/main/java/org/shredzone/commons/suncalc/SunTimes.java @@ -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++) { @@ -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; @@ -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; }