From 34ebc962738ce104585ae17db683f45729421720 Mon Sep 17 00:00:00 2001 From: sonicbluesky Date: Tue, 21 Jan 2025 02:25:06 -0800 Subject: [PATCH] add pi. fix upstream issue #6 using pr #35 use the fix xqjibz recommended. upstream (mourner) never merged xqjibz's pull request because it would've broken dependent apps. it was suggested to merge the pr with a major version increment in order to avoid dependent apps automatically updating, but that suggestion was never heeded. my repo doesn't have dependent apps right now so i can go ahead and just solve this issue. --- suncalc.js | 2 +- test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/suncalc.js b/suncalc.js index c9ca56d2..7e29e508 100644 --- a/suncalc.js +++ b/suncalc.js @@ -38,7 +38,7 @@ var e = rad * 23.4397; // obliquity of the Earth function rightAscension(l, b) { return atan(sin(l) * cos(e) - tan(b) * sin(e), cos(l)); } function declination(l, b) { return asin(sin(b) * cos(e) + cos(b) * sin(e) * sin(l)); } -function azimuth(H, phi, dec) { return atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi)); } +function azimuth(H, phi, dec) { return PI + atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi)); } function altitude(H, phi, dec) { return asin(sin(phi) * sin(dec) + cos(phi) * cos(dec) * cos(H)); } function siderealTime(d, lw) { return rad * (280.16 + 360.9856235 * d) - lw; } diff --git a/test.js b/test.js index d2aaff6c..271b7d98 100644 --- a/test.js +++ b/test.js @@ -38,7 +38,7 @@ var heightTestTimes = { t.test('getPosition returns azimuth and altitude for the given time and location', function (t) { var sunPos = SunCalc.getPosition(date, lat, lng); - t.ok(near(sunPos.azimuth, -2.5003175907168385), 'azimuth'); + t.ok(near(sunPos.azimuth, 0.6412750628729547), 'azimuth'); t.ok(near(sunPos.altitude, -0.7000406838781611), 'altitude'); t.end(); }); @@ -64,7 +64,7 @@ t.test('getTimes adjusts sun phases when additionally given the observer height' t.test('getMoonPosition returns moon position data given time and location', function (t) { var moonPos = SunCalc.getMoonPosition(date, lat, lng); - t.ok(near(moonPos.azimuth, -0.9783999522438226), 'azimuth'); + t.ok(near(moonPos.azimuth, 2.1631927013459706), 'azimuth'); t.ok(near(moonPos.altitude, 0.014551482243892251), 'altitude'); t.ok(near(moonPos.distance, 364121.37256256194), 'distance'); t.end();