1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use {
    super::{vec3_is_finite, Vec3},
    serde::{Deserialize, Serialize},
};

#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub struct Plane {
    distance: f32,
    normal: Vec3,
}

impl Plane {
    pub fn new(normal: Vec3, distance: f32) -> Self {
        assert!(distance.is_finite());
        assert!(vec3_is_finite(normal));
        assert!(normal.is_normalized());

        Self { distance, normal }
    }

    /// Returns the distance in the direction of `normal` from the origin to this plane.
    pub const fn distance(&self) -> f32 {
        self.distance
    }

    /// Returns the orientation of this plane.
    pub const fn normal(&self) -> Vec3 {
        self.normal
    }
}