bevy_rapier2d/geometry/shape_views/
cuboid.rs

1use crate::math::Vect;
2use rapier::geometry::Cuboid;
3
4/// Read-only access to the properties of a cuboid.
5#[derive(Copy, Clone)]
6pub struct CuboidView<'a> {
7    /// The raw shape from Rapier.
8    pub raw: &'a Cuboid,
9}
10
11macro_rules! impl_ref_methods(
12    ($View: ident) => {
13        impl<'a> $View<'a> {
14            /// The half-extents of the cuboid.
15            pub fn half_extents(&self) -> Vect {
16                self.raw.half_extents.into()
17            }
18        }
19    }
20);
21
22impl_ref_methods!(CuboidView);
23
24/// Read-write access to the properties of a cuboid.
25pub struct CuboidViewMut<'a> {
26    /// The raw shape from Rapier.
27    pub raw: &'a mut Cuboid,
28}
29
30impl_ref_methods!(CuboidViewMut);
31
32impl CuboidViewMut<'_> {
33    /// Set the half-extents of the cuboid.
34    pub fn set_half_extents(&mut self, half_extents: Vect) {
35        self.raw.half_extents = half_extents.into();
36    }
37}