Implement Default and Display for Plane
This commit is contained in:
parent
e4b6d375f8
commit
edb70037d6
|
@ -1,15 +1,21 @@
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
use glam::{Mat3, Vec3, Vec4};
|
use glam::{Mat3, Vec3, Vec4};
|
||||||
|
|
||||||
use crate::math;
|
use crate::math;
|
||||||
|
|
||||||
//? Should this be normalised or does that risk introducing fpp errors
|
//? Should this be normalised or does that risk introducing fpp errors
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
pub struct Plane {
|
pub struct Plane {
|
||||||
pub normal: Vec3,
|
pub normal: Vec3,
|
||||||
pub offset: f32,
|
pub offset: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Plane {
|
impl Plane {
|
||||||
|
pub fn new(normal: Vec3, offset: f32) -> Self {
|
||||||
|
Self { normal, offset }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_point_normal(point: Vec3, normal: Vec3) -> Self {
|
pub fn from_point_normal(point: Vec3, normal: Vec3) -> Self {
|
||||||
Self {
|
Self {
|
||||||
normal,
|
normal,
|
||||||
|
@ -33,6 +39,16 @@ impl PartialEq for Plane {
|
||||||
|
|
||||||
impl Eq 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)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct PlaneIntersection {
|
pub struct PlaneIntersection {
|
||||||
pub planes: [Plane; 3],
|
pub planes: [Plane; 3],
|
||||||
|
|
Loading…
Reference in New Issue