[astro] Restore lost 180° on azimuth (#20187)

Signed-off-by: gael@lhopital.org <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital
2026-02-05 20:03:13 +01:00
committed by GitHub
parent fcdadacb14
commit 753ab06289
2 changed files with 13 additions and 1 deletions
@@ -98,7 +98,7 @@ public class SunCalc {
double a = getRightAscension(lsun);
double th = getSiderealTime(j, lw);
double azimuth = Math.toDegrees(getAzimuth(th, a, phi, d));
double azimuth = Math.toDegrees(getAzimuth(th, a, phi, d)) + 180;
double elevation = Math.toDegrees(getElevation(th, a, phi, d));
return new Position(azimuth, elevation);
}
@@ -27,6 +27,7 @@ import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openhab.binding.astro.internal.model.Position;
import org.openhab.binding.astro.internal.model.Range;
import org.openhab.binding.astro.internal.model.Sun;
import org.openhab.binding.astro.internal.model.SunPhase;
@@ -429,6 +430,17 @@ public class SunCalcTest {
assertEquals(SunPhase.DAYLIGHT, sun.getSunPhase());
}
@Test
public void testAzimuthRange() {
for (int hour = 0; hour < 23; hour++) {
Calendar noonCalendar = SunCalcTest.newCalendar(2019, Calendar.FEBRUARY, 27, hour, 0, AMSTERDAM_TIME_ZONE);
Position position = Objects.requireNonNull(sunCalc).getPosition(noonCalendar, AMSTERDAM_LATITUDE,
AMSTERDAM_LONGITUDE);
double azimuth = position.getAzimuthAsDouble();
assertTrue(azimuth >= 0 && azimuth < 360, "Azimuth should be >=0 and <360");
}
}
/***
* Constructs a <code>GregorianCalendar</code> with the given date and time set
* for the provided time zone.