Skip to main content

bevy_rapier2d/geometry/shape_views/
halfspace.rs

1use crate::math::Vect;
2use rapier::parry::shape::HalfSpace;
3
4/// Read-only access to the properties of a half-space.
5#[derive(Copy, Clone)]
6pub struct HalfSpaceView<'a> {
7    /// The raw shape from Rapier.
8    pub raw: &'a HalfSpace,
9}
10
11macro_rules! impl_ref_methods(
12    ($View: ident) => {
13        impl<'a> $View<'a> {
14            /// The halfspace planar boundary's outward normal.
15            pub fn normal(&self) -> Vect {
16                self.raw.normal
17            }
18        }
19    }
20);
21
22impl_ref_methods!(HalfSpaceView);
23
24/// Read-write access to the properties of a half-space.
25pub struct HalfSpaceViewMut<'a> {
26    /// The raw shape from Rapier.
27    pub raw: &'a mut HalfSpace,
28}
29
30impl_ref_methods!(HalfSpaceViewMut);
31
32impl HalfSpaceViewMut<'_> {
33    /// Set the normal of the half-space.
34    pub fn set_normal(&mut self, normal: Vect) {
35        let normal: rapier::math::Vector = normal;
36        if normal.length_squared() >= 1.0e-12 {
37            self.raw.normal = normal.normalize();
38        }
39    }
40}