1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
//! Rounded shapes are shapes with smoothed/rounded borders.
//!
//! This module provides the `RoundShape` wrapper that adds a border radius to any shape,
//! effectively creating a "padded" or "rounded" version of the original shape.
use crate;
use crateSupportMap;
/// A shape with rounded borders.
///
/// # What is a Rounded Shape?
///
/// A `RoundShape` wraps an existing shape and adds a "border radius" around it. This creates
/// a smooth, rounded version of the original shape by effectively expanding it outward by
/// the border radius distance. Think of it as adding padding or a cushion around the shape.
///
/// The rounding is achieved by using Minkowski sum operations: any point on the surface of
/// the rounded shape is computed by taking a point on the original shape's surface and moving
/// it outward along the surface normal by the border radius distance.
///
/// # Common Use Cases
///
/// - **Creating softer collisions**: Rounded shapes can make collision detection more forgiving
/// and realistic, as sharp corners and edges are smoothed out.
/// - **Capsule-like shapes**: You can create capsule variations of any shape by adding a
/// border radius (e.g., a rounded cuboid becomes similar to a capsule).
/// - **Visual aesthetics**: Rounded shapes often look more pleasing and natural than sharp-edged
/// shapes.
/// - **Improved numerical stability**: Rounded shapes can sometimes be more numerically stable
/// in collision detection algorithms since they avoid sharp corners.
///
/// # Examples
///
/// ## Creating a Rounded Cuboid
///
/// ```rust
/// # #[cfg(all(feature = "dim3", feature = "f32"))] {
/// # #[cfg(feature = "f32")]
/// use parry3d::shape::{RoundShape, Cuboid};
/// # #[cfg(feature = "f64")]
/// use parry3d_f64::shape::{RoundShape, Cuboid};
/// use parry3d::math::Vector;
///
/// // Create a cuboid with half-extents of 1.0 in each direction
/// let cuboid = Cuboid::new(Vector::new(1.0, 1.0, 1.0));
///
/// // Add a border radius of 0.2 to create a rounded cuboid
/// let rounded_cuboid = RoundShape {
/// inner_shape: cuboid,
/// border_radius: 0.2,
/// };
///
/// // The effective size is now 1.2 in each direction from the center
/// // (1.0 from the cuboid + 0.2 from the border)
/// assert_eq!(rounded_cuboid.inner_shape.half_extents.x, 1.0);
/// assert_eq!(rounded_cuboid.border_radius, 0.2);
/// # }
/// ```
///
/// ## Creating a Rounded Triangle (2D)
///
/// ```rust
/// # #[cfg(all(feature = "dim2", feature = "f32"))] {
/// # #[cfg(feature = "f32")]
/// use parry2d::shape::{RoundShape, Triangle};
/// # #[cfg(feature = "f64")]
/// use parry2d_f64::shape::{RoundShape, Triangle};
/// use parry2d::math::Vector;
///
/// // Create a triangle
/// let triangle = Triangle::new(
/// Vector::ZERO,
/// Vector::new(1.0, 0.0),
/// Vector::new(0.0, 1.0),
/// );
///
/// // Add rounding with a 0.1 border radius
/// let rounded_triangle = RoundShape {
/// inner_shape: triangle,
/// border_radius: 0.1,
/// };
///
/// // The rounded triangle will have smooth, curved edges instead of sharp corners
/// assert_eq!(rounded_triangle.border_radius, 0.1);
/// # }
/// ```
///
/// ## Comparing Support Vectors
///
/// This example shows how the border radius affects the support point calculation:
///
/// ```rust
/// # #[cfg(all(feature = "dim3", feature = "f32"))] {
/// # #[cfg(feature = "f32")]
/// use parry3d::shape::{RoundShape, Cuboid, SupportMap};
/// # #[cfg(feature = "f64")]
/// use parry3d_f64::shape::{RoundShape, Cuboid, SupportMap};
/// use parry3d::math::Vector;
///
/// let cuboid = Cuboid::new(Vector::splat(1.0));
/// let rounded_cuboid = RoundShape {
/// inner_shape: cuboid,
/// border_radius: 0.5,
/// };
///
/// // Query the support point in the direction (1, 1, 1)
/// let direction = Vector::new(1.0, 1.0, 1.0);
/// let support_point = rounded_cuboid.local_support_point(direction);
///
/// // The support point will be further out than the original cuboid's support point
/// // due to the border radius
/// let cuboid_support = cuboid.local_support_point(direction);
///
/// // The rounded shape extends further in all directions
/// assert!(support_point.x > cuboid_support.x);
/// assert!(support_point.y > cuboid_support.y);
/// assert!(support_point.z > cuboid_support.z);
/// # }
/// ```
///
/// ## Using with Different Shape Types
///
/// `RoundShape` can wrap any shape that implements the `SupportMap` trait:
///
/// ```rust
/// # #[cfg(all(feature = "dim3", feature = "f32"))] {
/// # #[cfg(feature = "f32")]
/// use parry3d::shape::{RoundShape, Ball, Segment, SupportMap};
/// # #[cfg(feature = "f64")]
/// use parry3d_f64::shape::{RoundShape, Ball, Segment, SupportMap};
/// use parry3d::math::Vector;
///
/// // Rounded ball (creates a slightly larger sphere)
/// let ball = Ball::new(1.0);
/// let rounded_ball = RoundShape {
/// inner_shape: ball,
/// border_radius: 0.1,
/// };
/// // Effective radius is now 1.1
///
/// // Rounded segment (creates a capsule)
/// let segment = Segment::new(
/// Vector::ZERO,
/// Vector::new(0.0, 2.0, 0.0),
/// );
/// let rounded_segment = RoundShape {
/// inner_shape: segment,
/// border_radius: 0.5,
/// };
/// // This creates a capsule with radius 0.5
/// # }
/// ```
///
/// # Performance Considerations
///
/// - The computational cost of queries on a `RoundShape` is essentially the same as for the
/// inner shape, plus a small constant overhead to apply the border radius.
/// - `RoundShape` is most efficient when used with shapes that already implement `SupportMap`
/// efficiently (like primitives: Ball, Cuboid, Capsule, etc.).
/// - The struct is `Copy` when the inner shape is `Copy`, making it efficient to pass around.
///
/// # Technical Details
///
/// The `RoundShape` implements the `SupportMap` trait by computing the support point of the
/// inner shape and then offsetting it by the border radius in the query direction. This is
/// mathematically equivalent to computing the Minkowski sum of the inner shape with a ball
/// of radius equal to the border radius.
/// A shape reference with rounded borders.
///
/// This is an internal helper struct that provides the same rounding functionality as
/// `RoundShape`, but works with a borrowed reference to a shape instead of owning the shape.
/// This is useful in contexts where you want to temporarily treat a shape reference as
/// a rounded shape without creating a new allocation.
///
/// # Differences from `RoundShape`
///
/// - `RoundShapeRef` stores a reference (`&'a S`) instead of owning the shape
/// - It's marked `pub(crate)`, meaning it's only used internally within the Parry library
/// - The lifetime `'a` ensures the reference remains valid for the duration of use
/// - Works with unsized types (`S: ?Sized`), allowing it to work with trait objects
///
/// # Internal Use
///
/// This struct is primarily used internally by Parry for implementing collision detection
/// algorithms efficiently, where creating temporary rounded views of shapes is needed without
/// the overhead of cloning or moving data.
pub