diff --git a/csg/src/plane.rs b/csg/src/plane.rs index 0afc3f5..aba3730 100644 --- a/csg/src/plane.rs +++ b/csg/src/plane.rs @@ -1,15 +1,21 @@ +use std::fmt::Display; + use glam::{Mat3, Vec3, Vec4}; use crate::math; //? Should this be normalised or does that risk introducing fpp errors -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Default)] pub struct Plane { pub normal: Vec3, pub offset: f32, } impl Plane { + pub fn new(normal: Vec3, offset: f32) -> Self { + Self { normal, offset } + } + pub fn from_point_normal(point: Vec3, normal: Vec3) -> Self { Self { normal, @@ -33,6 +39,16 @@ impl PartialEq for Plane { impl Eq for Plane {} +impl Display for Plane { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "({})x + ({})y +({})z + ({}) = 0", + self.normal.x, self.normal.y, self.normal.z, -self.offset + ) + } +} + #[derive(Clone, Copy, Debug)] pub struct PlaneIntersection { pub planes: [Plane; 3],