1use pyo3::prelude::*;
2use std::fmt;
3use crate::Etype;
4use crate::Vec3;
5
6#[pyclass(skip_from_py_object)]
13#[derive(Clone, Debug)]
14pub struct Point {
15 #[pyo3(get)]
16 pub position: Vec3,
17
18 #[pyo3(get)]
19 pub direction: Vec3,
20
21 #[pyo3(get)]
22 pub area: f32,
23
24 #[pyo3(get)]
25 pub gravity: f32,
26
27 #[pyo3(get)]
28 pub eclipse: Etype,
29
30 #[pyo3(get)]
31 pub flux: f32,
32}
33
34
35#[pymethods]
36impl Point {
37
38 #[new]
42 pub fn new(position: Vec3, direction: Vec3, area: f64, gravity: f64, eclipse: Etype) -> Self {
43 Self {
44 position,
45 direction,
46 area: area as f32,
47 gravity: gravity as f32,
48 eclipse,
49 flux: 0.0,
50 }
51 }
52 pub fn set_flux(&mut self, flux: f32) {
56 self.flux = flux;
57 }
58
59 pub fn is_visible(&self, phase: f64) -> bool {
64 let phi: f64 = phase - phase.floor();
65 for &(p1, p2) in &self.eclipse {
66 if (phi >= p1 && phi <= p2) || phi <= p2 - 1.0 {
67 return false;
68 }
69 }
70 true
71 }
72
73 pub fn is_visible_phase_normed(&self, phase: f64) -> bool {
80 for &(p1, p2) in &self.eclipse {
81 if (phase >= p1 && phase <= p2) || phase <= p2 - 1.0 {
82 return false;
83 }
84 }
85 true
86 }
87
88 fn __repr__(&self) -> String {
89 format!("Point({}, {}, {}, {}, {:?}, {})", self.position, self.direction, self.area, self.gravity, self.eclipse, self.flux)
93 }
94}
95
96impl Default for Point {
97 fn default() -> Self {
98 Self::new(
99 Vec3::new(0.0, 0.0, 0.0),
100 Vec3::new(0.0, 0.0, 0.0),
101 0.0,
102 0.0,
103 vec![(0.0, 0.0)],
104 )
105 }
106}
107
108impl fmt::Display for Point {
109 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
110 write!(
111 f,
112 "Point({}, {}, {}, {}, {:?}, {})",
113 self.position,
114 self.direction,
115 self.area,
116 self.gravity,
117 self.eclipse,
118 self.flux
119 )
120 }
121}
122
123