Skip to main content

roche/
star_eclipse.rs

1use crate::errors::RocheError;
2use crate::{Etype, Star, Vec3};
3use crate::{ingress_egress, sphere_eclipse};
4
5///
6/// Covenience routine which wraps up the code to compute a star eclipse allowing for roche-dirstortion or not.
7///
8/// Arguments:
9///
10/// * `q`: mass ratio
11/// * `r`: radius of star
12/// * `spin`: spin/orbital frequency factor
13/// * `ffac`: roche filling factor
14/// * `iangle`: inclination angle
15/// * `posn`: position of point
16/// * `delta`: accuracy in phase
17/// * `roche`: account for roche distortion or not
18/// * `eclipses`: set of ingress/egress pairs
19///
20pub fn star_eclipse(
21    q: f64,
22    spin: f64,
23    r: f64,
24    ffac: f64,
25    iangle: f64,
26    posn: &Vec3,
27    delta: f64,
28    roche: bool,
29    star: Star,
30    eclipses: &mut Etype,
31) -> Result<(), RocheError> {
32    let ri = iangle.to_radians();
33    let (sini, cosi) = ri.sin_cos();
34    let cofm = match star {
35        Star::Primary => Vec3::cofm1(),
36        Star::Secondary => Vec3::cofm2(),
37    };
38    let mut lam1: f64 = 0.0;
39    let mut lam2: f64 = 0.0;
40    let mut ingress: f64 = 0.0;
41    let mut egress: f64 = 0.0;
42    // let mut eclipses = Etype::new();
43    if (roche
44        && ingress_egress(
45            q,
46            star,
47            spin,
48            ffac,
49            iangle,
50            delta,
51            posn,
52            &mut ingress,
53            &mut egress,
54        )?)
55        || (!roche
56            && sphere_eclipse(
57                cosi,
58                sini,
59                posn,
60                &cofm,
61                r,
62                &mut ingress,
63                &mut egress,
64                &mut lam1,
65                &mut lam2,
66            ))
67    {
68        eclipses.push((ingress, egress));
69    }
70    Ok(())
71}