bevy_rapier2d/geometry/shape_views/
polyline.rs1use crate::math::Vect;
2use rapier::parry::shape::Polyline;
3
4#[derive(Copy, Clone)]
6pub struct PolylineView<'a> {
7 pub raw: &'a Polyline,
9}
10
11macro_rules! impl_ref_methods(
12 ($View: ident) => {
13 impl<'a> $View<'a> {
14 pub fn num_segments(&self) -> usize {
16 self.raw.num_segments()
17 }
18
19 pub fn segments(&self) -> impl ExactSizeIterator<Item = (Vect, Vect)> + '_ {
21 self.raw.segments().map(|seg| (seg.a.into(), seg.b.into()))
22 }
23
24 pub fn segment(&self, i: u32) -> (Vect, Vect) {
26 let seg = self.raw.segment(i);
27 (seg.a.into(), seg.b.into())
28 }
29
30 pub fn vertices(&self) -> impl ExactSizeIterator<Item = Vect> + '_ {
32 self.raw.vertices().iter().map(|v| (*v).into())
33 }
34
35 pub fn indices(&self) -> &[[u32; 2]] {
37 self.raw.indices()
38 }
39 }
40 }
41);
42
43impl_ref_methods!(PolylineView);
44
45pub struct PolylineViewMut<'a> {
47 pub raw: &'a mut Polyline,
49}
50
51impl_ref_methods!(PolylineViewMut);
52
53impl PolylineViewMut<'_> {
54 pub fn reverse(&mut self) {
57 self.raw.reverse()
58 }
59}