Skip to main content

lib_jsl_geometry/dim_1/
plane1d.rs

1//! Concrete one-dimensional mirror plane abstraction.
2
3use crate::common::{GeometricPrimitive, IsPlane};
4use crate::one_d::{CoordinateVector1D, UnitVector1D};
5use std::fmt::{self, Display, Formatter};
6
7/// Concrete 1D mirror reference represented by a point and unit normal.
8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10pub struct Plane1D {
11    point: CoordinateVector1D,
12    normal: UnitVector1D,
13}
14
15impl Plane1D {
16    /// Creates a new 1D mirror reference.
17    pub fn new(point: CoordinateVector1D, normal: UnitVector1D) -> Self {
18        Self { point, normal }
19    }
20}
21
22impl Display for Plane1D {
23    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
24        write!(f, "Plane1D(point={}, normal={})", self.point, self.normal)
25    }
26}
27
28impl GeometricPrimitive for Plane1D {}
29
30impl IsPlane for Plane1D {
31    type Point = CoordinateVector1D;
32    type Normal = UnitVector1D;
33
34    fn point(&self) -> Self::Point {
35        self.point
36    }
37
38    fn point_mut(&mut self) -> &mut Self::Point {
39        &mut self.point
40    }
41
42    fn normal(&self) -> Self::Normal {
43        self.normal
44    }
45
46    fn normal_mut(&mut self) -> &mut Self::Normal {
47        &mut self.normal
48    }
49}