use crate::errors::RocheError;
use crate::{Star, Vec3};
use crate::{rpot1, rpot2, x_l1_1, x_l1_2};
use pyo3::prelude::*;
#[pyfunction]
pub fn ref_sphere(q: f64, star: Star, spin: f64, ffac: f64) -> Result<(f64, f64), RocheError> {
let tref: f64;
let rref: f64;
let pref: f64;
if star == Star::Primary {
tref = x_l1_1(q, spin)?;
rref = tref * 1.0_f64.min(1.001 * ffac);
pref = rpot1(
q,
spin,
&Vec3 {
x: ffac * tref,
y: 0.0,
z: 0.0,
},
)?;
Ok((rref, pref))
} else if star == Star::Secondary {
tref = 1.0 - x_l1_2(q, spin)?;
rref = tref * 1.0_f64.min(1.001 * ffac);
pref = rpot2(
q,
spin,
&Vec3 {
x: 1.0 - ffac * tref,
y: 0.0,
z: 0.0,
},
)?;
Ok((rref, pref))
} else {
let message = format!("{:?} is not and instance of Star.", star);
Err(RocheError::ParameterError(message))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ref_sphere_test() -> Result<(), RocheError> {
assert_eq!(
ref_sphere(0.2, Star::Secondary, 1.0, 0.8)?,
(0.27342861229381593, -2.3996722470168605)
);
assert!(ref_sphere(-0.2, Star::Secondary, 1.0, 0.8).is_err());
Ok(())
}
}