diff --git a/crates/bevy_math/src/sampling/shape_sampling.rs b/crates/bevy_math/src/sampling/shape_sampling.rs index 95dfe677fd20c..50c9b90c64328 100644 --- a/crates/bevy_math/src/sampling/shape_sampling.rs +++ b/crates/bevy_math/src/sampling/shape_sampling.rs @@ -542,6 +542,34 @@ impl ShapeSample for Capsule3d { } } +impl> ShapeSample for Extrusion

{ + type Output = Vec3; + + fn sample_interior(&self, rng: &mut R) -> Self::Output { + let base_point = self.base_shape.sample_interior(rng); + let depth = rng.gen_range(-self.half_depth..self.half_depth); + base_point.extend(depth) + } + + fn sample_boundary(&self, rng: &mut R) -> Self::Output { + let base_area = self.base_shape.area(); + let total_area = self.area(); + + let random = rng.gen_range(0.0..total_area); + match random { + x if x < base_area => self.base_shape.sample_interior(rng).extend(self.half_depth), + x if x < 2. * base_area => self + .base_shape + .sample_interior(rng) + .extend(-self.half_depth), + _ => self + .base_shape + .sample_boundary(rng) + .extend(rng.gen_range(-self.half_depth..self.half_depth)), + } + } +} + #[cfg(test)] mod tests { use super::*;