parry3d/shape/
round_shape.rs

1use crate::math::{Point, Real, Vector};
2use crate::shape::SupportMap;
3use na::Unit;
4
5#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
6#[cfg_attr(
7    feature = "rkyv",
8    derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize),
9    archive(check_bytes)
10)]
11#[derive(Copy, Clone, Debug)]
12#[repr(C)]
13/// A shape with rounded borders.
14pub struct RoundShape<S> {
15    /// The shape being rounded.
16    pub inner_shape: S,
17    /// The radius of the rounded border.
18    pub border_radius: Real,
19}
20
21impl<S: SupportMap> SupportMap for RoundShape<S> {
22    fn local_support_point(&self, dir: &Vector<Real>) -> Point<Real> {
23        self.local_support_point_toward(&Unit::new_normalize(*dir))
24    }
25
26    fn local_support_point_toward(&self, dir: &Unit<Vector<Real>>) -> Point<Real> {
27        self.inner_shape.local_support_point_toward(dir) + **dir * self.border_radius
28    }
29}
30
31/// A shape reference with rounded borders.
32pub(crate) struct RoundShapeRef<'a, S: ?Sized> {
33    /// The shape being rounded.
34    pub inner_shape: &'a S,
35    /// The radius of the rounded border.
36    pub border_radius: Real,
37}
38
39impl<S: ?Sized + SupportMap> SupportMap for RoundShapeRef<'_, S> {
40    fn local_support_point(&self, dir: &Vector<Real>) -> Point<Real> {
41        self.local_support_point_toward(&Unit::new_normalize(*dir))
42    }
43
44    fn local_support_point_toward(&self, dir: &Unit<Vector<Real>>) -> Point<Real> {
45        self.inner_shape.local_support_point_toward(dir) + **dir * self.border_radius
46    }
47}