bevy_rapier2d/geometry/shape_views/
round_shape.rs1use crate::geometry::shape_views::{CuboidView, CuboidViewMut, TriangleView, TriangleViewMut};
2use rapier::geometry::{RoundCuboid, RoundTriangle};
3
4#[cfg(feature = "dim2")]
5use {
6 crate::geometry::shape_views::{ConvexPolygonView, ConvexPolygonViewMut},
7 rapier::geometry::RoundConvexPolygon,
8};
9
10#[cfg(feature = "dim3")]
11use {
12 crate::geometry::shape_views::{
13 ConeView, ConeViewMut, ConvexPolyhedronView, ConvexPolyhedronViewMut, CylinderView,
14 CylinderViewMut,
15 },
16 rapier::geometry::{RoundCone, RoundConvexPolyhedron, RoundCylinder},
17};
18
19macro_rules! round_shape_view(
20 ($RoundShape: ident, $RoundShapeView: ident, $ShapeView: ident, $RoundShapeViewMut: ident, $ShapeViewMut: ident) => {
21 #[derive(Copy, Clone)]
23 pub struct $RoundShapeView<'a> {
24 pub raw: &'a $RoundShape,
26 }
27
28 impl<'a> $RoundShapeView<'a> {
29 pub fn border_radius(&self) -> f32 {
31 self.raw.border_radius
32 }
33
34 pub fn inner_shape(&self) -> $ShapeView<'_> {
36 $ShapeView {
37 raw: &self.raw.inner_shape,
38 }
39 }
40 }
41
42 pub struct $RoundShapeViewMut<'a> {
44 pub raw: &'a mut $RoundShape,
46 }
47
48 impl<'a> $RoundShapeViewMut<'a> {
49 pub fn border_radius(&self) -> f32 {
51 self.raw.border_radius
52 }
53
54 pub fn set_border_radius(&mut self, new_border_radius: f32) {
56 self.raw.border_radius = new_border_radius;
57 }
58
59 pub fn inner_shape(&mut self) -> $ShapeViewMut<'_> {
61 $ShapeViewMut {
62 raw: &mut self.raw.inner_shape,
63 }
64 }
65 }
66 }
67);
68
69round_shape_view!(
70 RoundCuboid,
71 RoundCuboidView,
72 CuboidView,
73 RoundCuboidViewMut,
74 CuboidViewMut
75);
76
77round_shape_view!(
78 RoundTriangle,
79 RoundTriangleView,
80 TriangleView,
81 RoundTriangleViewMut,
82 TriangleViewMut
83);
84
85#[cfg(feature = "dim2")]
86round_shape_view!(
87 RoundConvexPolygon,
88 RoundConvexPolygonView,
89 ConvexPolygonView,
90 RoundConvexPolygonViewMut,
91 ConvexPolygonViewMut
92);
93
94#[cfg(feature = "dim3")]
95round_shape_view!(
96 RoundCone,
97 RoundConeView,
98 ConeView,
99 RoundConeViewMut,
100 ConeViewMut
101);
102
103#[cfg(feature = "dim3")]
104round_shape_view!(
105 RoundCylinder,
106 RoundCylinderView,
107 CylinderView,
108 RoundCylinderViewMut,
109 CylinderViewMut
110);
111
112#[cfg(feature = "dim3")]
113round_shape_view!(
114 RoundConvexPolyhedron,
115 RoundConvexPolyhedronView,
116 ConvexPolyhedronView,
117 RoundConvexPolyhedronViewMut,
118 ConvexPolyhedronViewMut
119);