diff --git a/crates/bevy_math/src/primitives/dim2.rs b/crates/bevy_math/src/primitives/dim2.rs index 2befff6808..09eb970200 100644 --- a/crates/bevy_math/src/primitives/dim2.rs +++ b/crates/bevy_math/src/primitives/dim2.rs @@ -538,6 +538,15 @@ impl Rectangle { } } + /// Create a `Rectangle` from a single length. + /// The resulting `Rectangle` will be the same size in every direction. + #[inline(always)] + pub fn from_length(length: f32) -> Self { + Self { + half_size: Vec2::splat(length / 2.0), + } + } + /// Get the size of the rectangle #[inline(always)] pub fn size(&self) -> Vec2 { diff --git a/crates/bevy_math/src/primitives/dim3.rs b/crates/bevy_math/src/primitives/dim3.rs index 4eca086972..05b682f096 100644 --- a/crates/bevy_math/src/primitives/dim3.rs +++ b/crates/bevy_math/src/primitives/dim3.rs @@ -422,6 +422,15 @@ impl Cuboid { } } + /// Create a `Cuboid` from a single length. + /// The resulting `Cuboid` will be the same size in every direction. + #[inline(always)] + pub fn from_length(length: f32) -> Self { + Self { + half_size: Vec3::splat(length / 2.0), + } + } + /// Get the size of the cuboid #[inline(always)] pub fn size(&self) -> Vec3 { diff --git a/crates/bevy_render/src/mesh/primitives/dim3/plane.rs b/crates/bevy_render/src/mesh/primitives/dim3/plane.rs index 5fa8546c2a..02043acf48 100644 --- a/crates/bevy_render/src/mesh/primitives/dim3/plane.rs +++ b/crates/bevy_render/src/mesh/primitives/dim3/plane.rs @@ -46,6 +46,16 @@ impl PlaneMeshBuilder { } } + /// Creates a new [`PlaneMeshBuilder`] from the given length, with the normal pointing upwards, + /// and the resulting [`PlaneMeshBuilder`] being a square. + #[inline] + pub fn from_length(length: f32) -> Self { + Self { + half_size: Vec2::splat(length) / 2.0, + ..Default::default() + } + } + /// Sets the normal of the plane, aka the direction the plane is facing. #[inline] #[doc(alias = "facing")]