moon_calc/
consts.rs

1/// The period of the lunar orbit in days.
2pub const ORBIT_PERIOD: f64 = 29.53058770576;
3
4/// The offset for the lunar orbit calculations.
5pub const ORBIT_OFFSET: f64 = 2451550.26;
6
7/// The period of the lunar distance in days.
8pub const DISTANCE_PERIOD: f64 = 27.55454988;
9
10/// The offset for the lunar distance calculations.
11pub const DISTANCE_OFFSET: f64 = 2451562.2;
12
13/// The base value for calculating lunation.
14pub const LUNATION_BASE: f64 = 2423436.6115277777;
15
16/// The mean radius of the Earth in kilometers.
17pub const EARTH_RADIUS_KM: f64 = 6371.0084;
18
19
20/// Represents a lunar phase with name, emoji and start and end fractions.
21#[derive(Debug, Clone, Copy)]
22pub struct Phase {
23    /// Name of the lunar phase.
24    pub name: &'static str,
25    /// Emoji representing the lunar phase.
26    pub emoji: &'static str,
27    /// Start fraction of the lunar phase.
28    pub start: f64,
29    /// End fraction of the lunar phase.
30    pub end: f64,
31}
32pub const PHASES: [Phase; 8] = [
33    Phase { emoji: "🌑", name: "New Moon", start: 0.0, end: 0.02 },
34    Phase { emoji: "🌒", name: "Waxing Crescent", start: 0.02, end: 0.22 }, 
35    Phase { emoji: "🌓", name: "First Quarter", start: 0.22, end: 0.27 },
36    Phase { emoji: "🌔", name: "Waxing Gibbous", start: 0.27, end: 0.47 },
37    Phase { emoji: "🌕", name: "Full Moon", start: 0.47, end: 0.52 },
38    Phase { emoji: "🌖", name: "Waning Gibbous", start: 0.52, end: 0.72 },
39    Phase { emoji: "🌗", name: "Last Quarter", start: 0.72, end: 0.77 },
40    Phase { emoji: "🌘", name: "Waning Crescent", start: 0.77, end: 1.0 },
41];
42
43/// Represents information about the moon, including its julian date, phase,
44/// age, illumination, distance, and lunation.
45#[derive(Debug, Clone, Copy)]
46pub struct Moon {
47    /// A continuous count of days and fractions since noon Universal Time on January 1, 4713 BC 
48    pub julian_date: f64,
49    /// Phase of the moon.
50    pub phase: f64,
51    /// Age of the moon.
52    pub age: f64,
53    /// Illumination of the moon (0 to 1 where 1 is a full moon).
54    pub illumination: f64,
55    /// Distance of the moon in earth radii.
56    pub distance: f64,
57    /// Lunation number.
58    pub lunation: u16,
59}
60