Skip to content

Commit fc7c20c

Browse files
committed
Fix landscape composite moon rendering alignment
1 parent 4c9f5dc commit fc7c20c

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

apps/mobile/src/utils/photographyGuide.ts

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ export function buildLandscapeCompositeLayout(
473473
frameWidth,
474474
frameHeight,
475475
);
476+
const travelVector = normalizeTravelVector(input.travelVector);
476477
const rawHorizonY = anchorY + (maxSunAltitudeDeg / LANDSCAPE_VERTICAL_FOV_DEG_24MM) * frameHeight;
477478
const horizonY = clampRange(rawHorizonY, 0, frameHeight);
478479

@@ -497,8 +498,6 @@ export function buildLandscapeCompositeLayout(
497498
const rawY = anchorY - (altitudeDeltaDeg / LANDSCAPE_VERTICAL_FOV_DEG_24MM) * frameHeight;
498499
const clampedX = clampRange(rawX, minX, maxX);
499500
const clampedY = clampRange(rawY, minY, maxY);
500-
const clampedDeltaX = clampedX - rawX;
501-
const clampedDeltaY = clampedY - rawY;
502501
const clamped = Math.abs(clampedX - rawX) > 0.01 || Math.abs(clampedY - rawY) > 0.01;
503502

504503
let moon:
@@ -509,30 +508,23 @@ export function buildLandscapeCompositeLayout(
509508
}
510509
| undefined;
511510
if (row.showMoon) {
512-
const moonRadius = bodyAngularRadiusDegToPixels(
513-
sample.moon.angularRadiusDeg,
514-
frameWidth,
515-
frameHeight,
516-
);
517-
const moonAzimuthDeltaDeg = normalizeSignedDeltaDeg(maxSunAzimuthDeg, sample.moon.azimuthDeg);
518-
const moonAltitudeDeltaDeg = sample.moon.altitudeDeg - maxSunAltitudeDeg;
519-
const moonX =
520-
anchorX +
521-
(moonAzimuthDeltaDeg / LANDSCAPE_HORIZONTAL_FOV_DEG_24MM) * frameWidth +
522-
clampedDeltaX;
523-
const moonY =
524-
anchorY -
525-
(moonAltitudeDeltaDeg / LANDSCAPE_VERTICAL_FOV_DEG_24MM) * frameHeight +
526-
clampedDeltaY;
527-
const centerDistance = Math.hypot(moonX - clampedX, moonY - clampedY);
528-
const isOccluding = centerDistance <= sunRadius + moonRadius + 0.25;
529-
if (isOccluding) {
530-
moon = {
531-
x: moonX,
532-
y: moonY,
533-
radius: moonRadius,
534-
};
535-
}
511+
const moonGeometryStageSize = Math.max(64, sunRadius * LANDSCAPE_MOON_GEOMETRY_STAGE_FACTOR);
512+
const moonGeometry = calculatePreviewMoonGeometry({
513+
progress: row.progress,
514+
kindAtLocation: input.kindAtLocation,
515+
magnitude: input.magnitude,
516+
contacts: input.schedule.contacts,
517+
stageSize: moonGeometryStageSize,
518+
sunRadius,
519+
travelVector,
520+
});
521+
const moonOffsetX = moonGeometry.moonCenterX - moonGeometryStageSize / 2;
522+
const moonOffsetY = moonGeometry.moonCenterY - moonGeometryStageSize / 2;
523+
moon = {
524+
x: clampedX + moonOffsetX,
525+
y: clampedY + moonOffsetY,
526+
radius: moonGeometry.moonRadius,
527+
};
536528
}
537529

538530
return {

apps/mobile/tests/photography-guide.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,14 @@ describe("photography guide schedule", () => {
257257
expect(placement.sunRadius).toBeLessThan(4);
258258
expect(placement.sunRadius).toBeGreaterThan(1);
259259
expect(placement.y + placement.sunRadius).toBeLessThanOrEqual(layout.horizonY);
260+
expect(placement.showMoon).toBe(true);
261+
expect(placement.moon).toBeDefined();
262+
if (!placement.moon) continue;
263+
const centerDistance = Math.hypot(
264+
placement.moon.x - placement.x,
265+
placement.moon.y - placement.y,
266+
);
267+
expect(centerDistance).toBeLessThan(placement.sunRadius * 2.5);
260268
}
261269
});
262270
});

0 commit comments

Comments
 (0)