use vedaksha_math::angle::normalize_degrees;
use super::{HouseCusps, HouseSystem};
pub(super) fn compute(ramc: f64, latitude: f64, obliquity: f64) -> HouseCusps {
let (asc, mc) = super::compute_asc_mc(ramc, latitude, obliquity);
let dsc = normalize_degrees(asc + 180.0);
let ic = normalize_degrees(mc + 180.0);
let arc_asc_ic = normalize_degrees(ic - asc);
let arc_ic_dsc = normalize_degrees(dsc - ic);
let arc_dsc_mc = normalize_degrees(mc - dsc);
let arc_mc_asc = normalize_degrees(asc - mc);
let mut cusps = [0.0_f64; 12];
cusps[0] = asc; cusps[3] = ic; cusps[6] = dsc; cusps[9] = mc;
cusps[1] = normalize_degrees(asc + arc_asc_ic / 3.0);
cusps[2] = normalize_degrees(asc + 2.0 * arc_asc_ic / 3.0);
cusps[4] = normalize_degrees(ic + arc_ic_dsc / 3.0);
cusps[5] = normalize_degrees(ic + 2.0 * arc_ic_dsc / 3.0);
cusps[7] = normalize_degrees(dsc + arc_dsc_mc / 3.0);
cusps[8] = normalize_degrees(dsc + 2.0 * arc_dsc_mc / 3.0);
cusps[10] = normalize_degrees(mc + arc_mc_asc / 3.0);
cusps[11] = normalize_degrees(mc + 2.0 * arc_mc_asc / 3.0);
HouseCusps {
cusps,
asc,
mc,
system: HouseSystem::Porphyry,
polar_fallback: false,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn angles_placed_correctly() {
let result = compute(30.0, 45.0, 23.44);
let dsc = normalize_degrees(result.asc + 180.0);
let ic = normalize_degrees(result.mc + 180.0);
assert!((result.cusps[0] - result.asc).abs() < 1e-10);
assert!((result.cusps[6] - dsc).abs() < 1e-10);
assert!((result.cusps[9] - result.mc).abs() < 1e-10);
assert!((result.cusps[3] - ic).abs() < 1e-10);
}
#[test]
fn all_cusps_in_range() {
let result = compute(120.0, 52.0, 23.44);
for (i, &c) in result.cusps.iter().enumerate() {
assert!((0.0..360.0).contains(&c), "cusp {i}: {c}");
}
}
#[test]
fn system_tag() {
let result = compute(0.0, 0.0, 23.44);
assert_eq!(result.system, HouseSystem::Porphyry);
}
}