Skip to main content

rust_roche/
point.rs

1use crate::Vec3;
2use crate::Etype;
3
4
5
6///
7/// Struct defining a point on the surface of a model grid (e.g. of a star or disc etc.)
8/// A `Point` has a position, a direction which is the surface normal, an area,
9/// a relative gravity, a vector of phase pairs defining when the point is eclipsed by
10/// another model component, and a flux.
11/// 
12#[derive(Clone, Debug)]
13pub struct Point {
14    pub position: Vec3,
15    pub direction: Vec3,
16    pub area: f32,
17    pub gravity: f32,
18    pub eclipse: Etype,
19    pub flux: f32,
20}
21
22impl Point {
23
24    ///
25    /// Creates a new Point.
26    /// 
27    pub fn new(position: Vec3, direction: Vec3, area: f64, gravity: f64, eclipse: Etype) -> Self {
28        Self {
29            position,
30            direction,
31            area: area as f32,
32            gravity: gravity as f32,
33            eclipse,
34            flux: 0.0,
35        }
36    }
37    ///
38    /// sets the point's flux.
39    /// 
40    pub fn set_flux(&mut self, flux: f32) -> () {
41        self.flux = flux;
42    }
43    
44    ///
45    ///checks that the given phase is not during one of the
46    /// phase ranges when the point is eclipsed.
47    ///  
48    pub fn is_visible(&self, phase: f64) -> bool {
49        let phi: f64 = phase - phase.floor();
50        for &(p1, p2) in &self.eclipse {
51            if (phi >= p1 && phi <= p2) || phi <= p2 - 1.0 {
52                return false
53            }
54        }
55        true
56    }
57}
58
59impl Default for Point {
60    fn default() -> Self {
61        Self::new(
62            Vec3::new(0.0, 0.0, 0.0),
63            Vec3::new(0.0, 0.0, 0.0),
64            0.0,
65            0.0,
66            vec![(0.0, 0.0)],
67            )
68    }
69}