use crate::kundli::astro::{AstroBody, Ayanamsha, ZodiacType};
const BODY_COUNT: usize = AstroBody::ALL.len();
const HOUSE_CUSP_COUNT: usize = 12;
#[derive(Debug, Clone, PartialEq)]
pub struct AstroBodyPosition {
pub body: AstroBody,
pub longitude: f64,
pub latitude: f64,
pub distance: f64,
pub speed_longitude: f64,
}
#[derive(Debug, Clone, PartialEq)]
pub struct AstroMeta {
pub jd_ut: f64,
pub latitude: f64,
pub longitude: f64,
pub zodiac: ZodiacType,
pub ayanamsha: Ayanamsha,
pub ayanamsha_value: Option<f64>,
pub sidereal_time: f64,
}
#[derive(Debug, Clone, PartialEq)]
pub struct AstroResult {
pub bodies: [AstroBodyPosition; BODY_COUNT],
pub ascendant_longitude: f64,
pub mc_longitude: f64,
pub house_cusps: [f64; HOUSE_CUSP_COUNT],
pub meta: AstroMeta,
}
impl AstroResult {
pub fn body(&self, body: AstroBody) -> &AstroBodyPosition {
let position = &self.bodies[body.index()];
debug_assert_eq!(position.body, body);
position
}
}
#[cfg(test)]
mod tests {
use super::*;
fn sample_body(body: AstroBody, longitude: f64) -> AstroBodyPosition {
AstroBodyPosition {
body,
longitude,
latitude: 0.0,
distance: 1.0,
speed_longitude: 0.0,
}
}
#[test]
fn body_uses_canonical_slot_lookup() {
let bodies = std::array::from_fn(|index| {
let body = AstroBody::ALL[index];
sample_body(body, index as f64 * 10.0)
});
let result = AstroResult {
bodies,
ascendant_longitude: 0.0,
mc_longitude: 0.0,
house_cusps: [0.0; HOUSE_CUSP_COUNT],
meta: AstroMeta {
jd_ut: 2451545.0,
latitude: 37.5665,
longitude: 126.9780,
zodiac: ZodiacType::Sidereal,
ayanamsha: Ayanamsha::Lahiri,
ayanamsha_value: Some(24.0),
sidereal_time: 12.0,
},
};
let moon = result.body(AstroBody::Moon);
let ketu = result.body(AstroBody::Ketu);
assert_eq!(moon.body, AstroBody::Moon);
assert_eq!(moon.longitude, 10.0);
assert_eq!(ketu.body, AstroBody::Ketu);
assert_eq!(ketu.longitude, 80.0);
}
}