lib_jsl_geometry/dim_2/
plane2d.rs1use crate::common::{GeometricPrimitive, GeometricPrimitive2D, IsPlane};
4use crate::two_d::{CoordinateVector2D, UnitVector2D};
5use std::fmt::{self, Display, Formatter};
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14pub struct Plane2D {
15 point: CoordinateVector2D,
16 normal: UnitVector2D,
17}
18
19impl Plane2D {
20 pub fn new(point: CoordinateVector2D, normal: UnitVector2D) -> Self {
22 Self { point, normal }
23 }
24}
25
26impl Display for Plane2D {
27 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
28 write!(f, "Plane2D(point={}, normal={})", self.point, self.normal)
29 }
30}
31
32impl GeometricPrimitive for Plane2D {}
33impl GeometricPrimitive2D for Plane2D {}
34
35impl IsPlane for Plane2D {
36 type Point = CoordinateVector2D;
37 type Normal = UnitVector2D;
38
39 fn point(&self) -> Self::Point {
40 self.point
41 }
42
43 fn point_mut(&mut self) -> &mut Self::Point {
44 &mut self.point
45 }
46
47 fn normal(&self) -> Self::Normal {
48 self.normal
49 }
50
51 fn normal_mut(&mut self) -> &mut Self::Normal {
52 &mut self.normal
53 }
54}