parry3d/shape/
half_space.rs

1//! Support mapping based HalfSpace shape.
2use crate::math::{Real, Vector};
3use na::Unit;
4
5#[cfg(feature = "rkyv")]
6use rkyv::{bytecheck, CheckBytes};
7
8/// A half-space delimited by an infinite plane.
9#[derive(PartialEq, Debug, Clone, Copy)]
10#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11#[cfg_attr(
12    feature = "rkyv",
13    derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize, CheckBytes),
14    archive(as = "Self")
15)]
16#[repr(C)]
17pub struct HalfSpace {
18    /// The halfspace planar boundary's outward normal.
19    pub normal: Unit<Vector<Real>>,
20}
21
22impl HalfSpace {
23    /// Builds a new halfspace from its center and its normal.
24    #[inline]
25    pub fn new(normal: Unit<Vector<Real>>) -> HalfSpace {
26        HalfSpace { normal }
27    }
28
29    /// Computes a scaled version of this half-space.
30    ///
31    /// Returns `None` if `self.normal` scaled by `scale` is zero (the scaled half-space
32    /// degenerates to a single point).
33    pub fn scaled(self, scale: &Vector<Real>) -> Option<Self> {
34        Unit::try_new(self.normal.component_mul(scale), 0.0).map(|normal| Self { normal })
35    }
36}