Spec: the Moon's phase and libration #1
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
jeff/zig-astro#1
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem Statement
A Zig program that wants to know about the Moon — when the next full Moon is, how much of the disk is lit tonight, which way the Moon is tipped so that features near the limb can be seen — has nothing to call. It would have to transcribe a lunar theory from a book itself, along with the time-scale conversions, nutation, the Sun's position and the coordinate transforms that the theory leans on, and it would have to get every unit, sign convention and time scale right on its own. Those are exactly the places such code goes quietly wrong: degrees mistaken for radians, UT passed where TT was meant, libration reported with the opposite sign.
Solution
zig-astro provides geocentric calculations of the Moon's phase and libration, built on Jean Meeus's Astronomical Algorithms (2nd edition, 1998; see ADR 0001), together with the foundations they need, each of which is public and reusable by the bodies that come later:
Every calculation is a pure function of an instant. The vocabulary is the project's
GLOSSARY.md.User Stories
Instants and time scales
Angles and coordinates
The Earth
The Sun
The Moon's position
Phase at an instant
Principal phases and lunar age
Libration
The Sun on the Moon
Robustness
Documentation and trust
Implementation Decisions
astro.time(the instant, the time scale, calendars, ΔT),astro.Angle,astro.coord(ecliptic and equatorial coordinates and the conversion between them),astro.earth(nutation, obliquity),astro.sun(the apparent position), andastro.moonholdingposition,phaseandlibration. The time and angle types sit at the top because every later body will use them, and each body gets a namespace of its own.f64and a time scale, TT or UT. UTC is counted as UT; the difference is under 0.9 s, which moves the Moon about 0.5″. Calendar construction takes an explicit Julian or Gregorian choice. Every calculation accepts either scale and converts internally.f64radians.f64throughout, with no generic float parameter.Io, no global state anywhere.@intFromFloatpanics on NaN and on values out of range.Testing Decisions
astromodule. Tests call only what a consumer can call. Internal helpers — series evaluation, the lunation number, angle reduction — are not tested directly; an error in any of them shows up as an error in a public result.f64Julian Day, including NaN, ±∞ and extreme finite values, no calculation panics; every finite result lies in its documented range; and non-finite input gives NaN. Further properties: the next principal phase of a kind is after the instant and the previous one is before it; consecutive principal phases go new → first quarter → full → last quarter; lunar age is never negative and is less than about 29.9 days; the illuminated fraction agrees with the phase angle. The same targets run underzig build teston fixed seeds and underzig build fuzz --fuzz. The test binary is compiled with LLVM so that the fuzzer and kcov get coverage.Out of Scope
Position.Further Notes
GLOSSARY.md, and the two decisions behind the theory and the instant type are ADRs 0001 and 0002.Every ticket the spec was broken into is done: #2 through #9.