chore(deps): update dependency suncalc to v2.1.3 #16
No files matched your search
Generated
+4
-4
@@ -11,7 +11,7 @@
|
|||||||
"maplibre-gl": "6.16.0",
|
"maplibre-gl": "6.16.0",
|
||||||
"maplibre-gl-lanes": "1.4.0",
|
"maplibre-gl-lanes": "1.4.0",
|
||||||
"pmtiles": "4.5.0",
|
"pmtiles": "4.5.0",
|
||||||
"suncalc": "2.1.1"
|
"suncalc": "2.1.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@mapbox/jsonlint-lines-primitives": {
|
"node_modules/@mapbox/jsonlint-lines-primitives": {
|
||||||
@@ -304,9 +304,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/suncalc": {
|
"node_modules/suncalc": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/suncalc/-/suncalc-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/suncalc/-/suncalc-2.1.3.tgz",
|
||||||
"integrity": "sha512-ufMOPzYRk5aomEs3g+qeJGdCPZWC3TL94E0HQagoSusFnNXCvfuewWBroY3lxRHqA7IA8UGvgg7dcrSSDJsuEg==",
|
"integrity": "sha512-7DWCsxPKRPMtylyGqSrgNBr+pseyczJGqb4NCpW2EziwNHaSuHc9w1lL4i91IyDw5CnPUWqBNBWyd/vFjr4rTw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/tinyqueue": {
|
"node_modules/tinyqueue": {
|
||||||
|
|||||||
+1
-1
@@ -8,6 +8,6 @@
|
|||||||
"maplibre-gl": "6.16.0",
|
"maplibre-gl": "6.16.0",
|
||||||
"maplibre-gl-lanes": "1.4.0",
|
"maplibre-gl-lanes": "1.4.0",
|
||||||
"pmtiles": "4.5.0",
|
"pmtiles": "4.5.0",
|
||||||
"suncalc": "2.1.1"
|
"suncalc": "2.1.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+55
-20
@@ -139,22 +139,36 @@ function solarTransit(dt, lw) {
|
|||||||
return dt;
|
return dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// time the Sun reaches altitude h0 on the given side of transit (sign -1 = rise, +1 = set);
|
// time the Sun reaches altitude h0 within the half day [a, b] between transit and nadir, given the
|
||||||
// starts from the hour angle at transit and converges with Meeus' altitude correction (15.2).
|
// sine of its altitude at both ends; NaN if it doesn't cross h0 there (altitude is monotonic over the
|
||||||
function getSetJ(h0, dt, sign, lw, phi, decT) {
|
// half day, so a sign change means exactly one crossing). Seeds from the hour angle at transit
|
||||||
const cosH0 = (sin(h0) - sin(phi) * sin(decT)) / (cos(phi) * cos(decT));
|
// declination, then Newton on sin(h) kept inside a shrinking bracket, bisecting whenever a step
|
||||||
if (cosH0 < -1 || cosH0 > 1) return NaN; // sun stays above / below this altitude all day
|
// leaves it — on near-grazing days the slope is tiny and plain Newton steps land days away.
|
||||||
|
function getSetJ(h0, a, b, sa, sb, dt, lw, phi, decT) {
|
||||||
|
const s0 = sin(h0);
|
||||||
|
const rising = sa < sb;
|
||||||
|
if ((sa - s0) * (sb - s0) > 0) return NaN; // sun stays above / below this altitude all half day
|
||||||
|
|
||||||
let d = dt + sign * acos(cosH0) / (2 * PI);
|
const cosH0 = (s0 - sin(phi) * sin(decT)) / (cos(phi) * cos(decT));
|
||||||
for (let i = 0; i < 2; i++) {
|
const H0 = cosH0 <= -1 ? PI : cosH0 >= 1 ? 0 : acos(cosH0);
|
||||||
|
let d = dt + (rising ? -H0 : H0) / (2 * PI);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
const c = sunCoords(toDaysTT(d));
|
const c = sunCoords(toDaysTT(d));
|
||||||
const H = wrapPi(siderealTime(d, lw) - c.ra);
|
const H = siderealTime(d, lw) - c.ra;
|
||||||
const h = altitude(H, phi, c.dec);
|
const k = cos(phi) * cos(c.dec);
|
||||||
const sinH = cos(phi) * cos(c.dec) * sin(H);
|
const f = sin(phi) * sin(c.dec) + k * cos(H) - s0;
|
||||||
if (abs(sinH) < 1e-6) break; // grazing the horizon — correction is ill-conditioned
|
if ((f < 0) === rising) a = d; else b = d;
|
||||||
d += (h - h0) / (2 * PI * sinH);
|
|
||||||
|
const step = f / (2 * PI * k * sin(H));
|
||||||
|
if (d + step > a && d + step < b) {
|
||||||
|
d += step;
|
||||||
|
if (abs(step) < 1e-5) return d; // ~1 s step, so quadratic convergence leaves ~µs error
|
||||||
|
} else {
|
||||||
|
d = (a + b) / 2;
|
||||||
|
if (b - a < 1e-8) return d;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// start of the civil day containing date in a zone utcOffset minutes ahead of UTC, as a ms timestamp
|
// start of the civil day containing date in a zone utcOffset minutes ahead of UTC, as a ms timestamp
|
||||||
@@ -182,24 +196,45 @@ export function getTimes(date, lat, lng, height = 0, utcOffset) {
|
|||||||
const dt = solarDayTransit(date, lw, utcOffset);
|
const dt = solarDayTransit(date, lw, utcOffset);
|
||||||
const dec = sunCoords(toDaysTT(dt)).dec; // declination at transit, shared by every rise/set solve
|
const dec = sunCoords(toDaysTT(dt)).dec; // declination at transit, shared by every rise/set solve
|
||||||
|
|
||||||
|
// sine of the Sun's altitude at transit and at the nadirs either side (H = 0 and π), bracketing
|
||||||
|
// every rise and set; the nadirs use their own declination, which matters on regime-boundary days
|
||||||
|
const sNoon = cos(phi - dec);
|
||||||
|
const sNadir1 = -cos(phi + sunCoords(toDaysTT(dt - 0.5)).dec);
|
||||||
|
const sNadir2 = -cos(phi + sunCoords(toDaysTT(dt + 0.5)).dec);
|
||||||
|
|
||||||
|
// the window is the solar day [dt - 0.5, dt + 0.5), or with an offset the civil day, which is just as
|
||||||
|
// long but shifted by up to half a day: it then also takes in the evening of the previous solar day
|
||||||
|
// or the morning of the next one, where events cut off from this solar day are looked up instead
|
||||||
|
const start = utcOffset === undefined ? dt - 0.5 : toDays(civilMidnight(date, utcOffset));
|
||||||
|
const end = start + 1;
|
||||||
|
const prev = start < dt - 0.5;
|
||||||
|
const next = end > dt + 0.5;
|
||||||
|
const dt2 = prev ? solarTransit(dt - 1, lw) : next ? solarTransit(dt + 1, lw) : dt;
|
||||||
|
const dec2 = dt2 === dt ? dec : sunCoords(toDaysTT(dt2)).dec;
|
||||||
|
const sNoon2 = cos(phi - dec2);
|
||||||
|
|
||||||
|
// solar days run up to ~30 s longer than 24 h, so a civil day can miss a nadir by seconds; keep
|
||||||
|
// this solar day's one then
|
||||||
const result = {
|
const result = {
|
||||||
solarNoon: fromJulian(dt + J2000),
|
solarNoon: fromJulian(dt + J2000),
|
||||||
nadir: fromJulian(dt + J2000 - 0.5)
|
nadir: fromJulian((next && dt2 - 0.5 < end ? dt2 : dt) - 0.5 + J2000)
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const [angle, riseName, setName] of times) {
|
for (const [angle, riseName, setName] of times) {
|
||||||
const h0 = (angle + dh) * rad;
|
const h0 = (angle + dh) * rad;
|
||||||
const jrise = getSetJ(h0, dt, -1, lw, phi, dec);
|
let jrise = getSetJ(h0, dt - 0.5, dt, sNadir1, sNoon, dt, lw, phi, dec);
|
||||||
const jset = getSetJ(h0, dt, 1, lw, phi, dec);
|
let jset = getSetJ(h0, dt, dt + 0.5, sNoon, sNadir2, dt, lw, phi, dec);
|
||||||
|
if (next && !(jrise >= start)) jrise = getSetJ(h0, dt + 0.5, dt2, sNadir2, sNoon2, dt2, lw, phi, dec2);
|
||||||
|
if (prev && !(jset < end)) jset = getSetJ(h0, dt2, dt - 0.5, sNoon2, sNadir1, dt2, lw, phi, dec2);
|
||||||
|
|
||||||
// a NaN means the Sun never reaches this altitude on this day — report null, not Invalid Date
|
// NaN (the Sun never reaches this altitude) or outside the window: report null, not Invalid Date
|
||||||
result[riseName] = Number.isNaN(jrise) ? null : fromJulian(jrise + J2000);
|
result[riseName] = jrise >= start && jrise < end ? fromJulian(jrise + J2000) : null;
|
||||||
result[setName] = Number.isNaN(jset) ? null : fromJulian(jset + J2000);
|
result[setName] = jset >= start && jset < end ? fromJulian(jset + J2000) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// polar day/night: when the Sun never crosses the standard rise/set altitude, flag which side it
|
// polar day/night: when the Sun never crosses the standard rise/set altitude, flag which side it
|
||||||
// stays on by comparing its altitude at solar noon (its daily maximum) against that threshold.
|
// stays on by comparing its altitude at solar noon (its daily maximum) against that threshold.
|
||||||
if (result.sunrise === null) {
|
if (result.sunrise === null && result.sunset === null) {
|
||||||
const noonAlt = altitude(0, phi, dec);
|
const noonAlt = altitude(0, phi, dec);
|
||||||
const riseSetAlt = (times[0][0] + dh) * rad;
|
const riseSetAlt = (times[0][0] + dh) * rad;
|
||||||
result.alwaysUp = noonAlt > riseSetAlt;
|
result.alwaysUp = noonAlt > riseSetAlt;
|
||||||
|
|||||||
Reference in new issue
Block a user