diff --git a/crates/bevy_math/src/sampling/shape_sampling.rs b/crates/bevy_math/src/sampling/shape_sampling.rs index c17bc6fa76..4b245eb8ff 100644 --- a/crates/bevy_math/src/sampling/shape_sampling.rs +++ b/crates/bevy_math/src/sampling/shape_sampling.rs @@ -224,6 +224,26 @@ impl ShapeSample for Annulus { } } +impl ShapeSample for Rhombus { + type Output = Vec2; + + fn sample_interior(&self, rng: &mut R) -> Vec2 { + let x: f32 = rng.gen_range(0.0..=1.0); + let y: f32 = rng.gen_range(0.0..=1.0); + + let unit_p = Vec2::NEG_X + x * Vec2::ONE + Vec2::new(y, -y); + unit_p * self.half_diagonals + } + + fn sample_boundary(&self, rng: &mut R) -> Vec2 { + let x: f32 = rng.gen_range(-1.0..=1.0); + let y_sign = if rng.r#gen() { -1.0 } else { 1.0 }; + + let y = (1.0 - ops::abs(x)) * y_sign; + Vec2::new(x, y) * self.half_diagonals + } +} + impl ShapeSample for Rectangle { type Output = Vec2;