Add error handling for moon position calculation
This commit is contained in:
1 parent
944982f34a
commit
e5765dd7de
1 file changed
+11
-2
+11
-2
@@ -364,6 +364,7 @@
|
||||
}
|
||||
|
||||
function getMoonPosition(now, moonTimes) {
|
||||
try {
|
||||
var rise = moonTimes.rise;
|
||||
var set = moonTimes.set;
|
||||
|
||||
@@ -380,7 +381,6 @@
|
||||
}
|
||||
|
||||
if (!isVisible) {
|
||||
// Below horizon - position based on current time (grayed out)
|
||||
return { point: pointOnCircle(now, MOON_ORBIT_RADIUS), isVisible: false };
|
||||
}
|
||||
|
||||
@@ -390,7 +390,6 @@
|
||||
|
||||
// Calculate the angular difference (could be negative if crossing midnight)
|
||||
var diff = setAngle - riseAngle;
|
||||
// Normalize so we take the "shorter" path that matches the moon arc
|
||||
if (diff > Math.PI) diff -= 2 * Math.PI;
|
||||
if (diff < -Math.PI) diff += 2 * Math.PI;
|
||||
|
||||
@@ -416,6 +415,9 @@
|
||||
},
|
||||
isVisible: true
|
||||
};
|
||||
} catch (e) {
|
||||
return { point: pointOnCircle(now, MOON_ORBIT_RADIUS), isVisible: false };
|
||||
}
|
||||
}
|
||||
|
||||
function renderMoonPhaseIcon(phase) {
|
||||
@@ -538,8 +540,15 @@
|
||||
|
||||
// Moon position - interpolated between moonrise and moonset on the orbit
|
||||
var moonPos = getMoonPosition(now, moonTimes);
|
||||
if (!moonPos || !moonPos.point || isNaN(moonPos.point.x) || isNaN(moonPos.point.y)) {
|
||||
// Fallback to current time position
|
||||
var fallbackP = pointOnCircle(now, MOON_ORBIT_RADIUS);
|
||||
rpgMoon.setAttribute('transform', 'translate(' + fallbackP.x + ', ' + fallbackP.y + ')');
|
||||
rpgMoon.setAttribute('opacity', '0.35');
|
||||
} else {
|
||||
rpgMoon.setAttribute('transform', 'translate(' + moonPos.point.x + ', ' + moonPos.point.y + ')');
|
||||
rpgMoon.setAttribute('opacity', moonPos.isVisible ? '1' : '0.35');
|
||||
}
|
||||
|
||||
// Sun rise/set arrows
|
||||
var srP = pointOnCircle(sunTimes.sunrise, SUN_ORBIT_RADIUS);
|
||||
|
||||
Reference in new issue
Block a user