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