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