Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt MoonTool formula for calculating moon phase #34

Merged
merged 9 commits into from
Jul 13, 2024
Merged

Conversation

mannylopez
Copy link
Owner

Closes #27 [AstronomicalConstant] Calculations off by ~4.5hrs

Big refactor to remove most of the functions from sunCalc in favor of code from Moontool for Windows. The original code is written in Visual C and I converted it to Swift and removed extra functions I don't need.

Not only is this more accurate, but it also provides more metadata, such as the age of the moon and distance to the moon.

Added a new MoonDetail object to house this data.

struct MoonDetail {
    let julianDay: Double
    /// Number of days elapsed into the synodic cycle, represented as a fraction
    let daysElapsedInCycle: Double
    /// Age of the moon in days, minutes, hours
    let ageOfMoon: (days: Int, hours: Int, minutes: Int)
    /// Illuminated portion of the Moon, where 0.0 = new and 0.99 = full
    let illuminatedFraction: Double
    /// Distance of moon from the center of the Earth, in kilometers
    let distanceFromCenterOfEarth: Double
    /// Phase of the Moon, represented as a fraction
    ///
    /// Varies between `0.0` to `0.99`.
    /// `0.0` new moon,
    /// `0.25` first quarter,
    /// `0.5` full moon,
    /// `0.75` last quarter
    let phase: Double
  }

This does not break the API.


Special thank you to the author of MoonTool, John Walker, for providing the source code.
Screenshot 2024-07-12 at 3 44 31 PM

@mannylopez mannylopez merged commit 50b5dfd into main Jul 13, 2024
@mannylopez mannylopez deleted the adopt-moontool branch July 25, 2024 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AstronomicalConstant] Calculations off by ~4.5hrs
1 participant