bevy_rapier2d/geometry/shape_views/
convex_polygon.rs

1use crate::math::Vect;
2use rapier::parry::shape::ConvexPolygon;
3
4/// Read-only access to the properties of a convex polygon.
5#[derive(Copy, Clone)]
6pub struct ConvexPolygonView<'a> {
7    /// The raw shape from Rapier.
8    pub raw: &'a ConvexPolygon,
9}
10
11impl ConvexPolygonView<'_> {
12    /// The vertices of this convex polygon.
13    pub fn points(&self) -> impl ExactSizeIterator<Item = Vect> + '_ {
14        self.raw.points().iter().map(|pt| (*pt).into())
15    }
16
17    /// The normals of the edges of this convex polygon.
18    pub fn normals(&self) -> impl ExactSizeIterator<Item = Vect> + '_ {
19        self.raw.normals().iter().map(|n| (**n).into())
20    }
21}
22
23/// Read-write access to the properties of a convex polygon.
24pub struct ConvexPolygonViewMut<'a> {
25    /// The raw shape from Rapier.
26    pub raw: &'a mut ConvexPolygon,
27}
28
29impl ConvexPolygonViewMut<'_> {
30    /// The vertices of this convex polygon.
31    pub fn points(&self) -> impl ExactSizeIterator<Item = Vect> + '_ {
32        self.raw.points().iter().map(|pt| (*pt).into())
33    }
34
35    /// The normals of the edges of this convex polygon.
36    pub fn normals(&self) -> impl ExactSizeIterator<Item = Vect> + '_ {
37        self.raw.normals().iter().map(|n| (**n).into())
38    }
39
40    // TODO: add modifications.
41}