From 0c125515e4cad5f36d27ff9d1683f5f5d172be02 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Thu, 25 Jan 2024 13:27:49 +0200 Subject: [PATCH] Add `new` constructors for `Circle` and `Sphere` --- crates/bevy_math/src/primitives/dim2.rs | 6 ++++++ crates/bevy_math/src/primitives/dim3.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/crates/bevy_math/src/primitives/dim2.rs b/crates/bevy_math/src/primitives/dim2.rs index 63d7c3896aa8b..8d094e3e957d0 100644 --- a/crates/bevy_math/src/primitives/dim2.rs +++ b/crates/bevy_math/src/primitives/dim2.rs @@ -88,6 +88,12 @@ pub struct Circle { impl Primitive2d for Circle {} impl Circle { + /// Create a new [`Circle`] from a `radius` + #[inline(always)] + pub const fn new(radius: f32) -> Self { + Self { radius } + } + /// Finds the point on the circle that is closest to the given `point`. /// /// If the point is outside the circle, the returned point will be on the perimeter of the circle. diff --git a/crates/bevy_math/src/primitives/dim3.rs b/crates/bevy_math/src/primitives/dim3.rs index 4d270fd8acd1b..8c12f2b789f5b 100644 --- a/crates/bevy_math/src/primitives/dim3.rs +++ b/crates/bevy_math/src/primitives/dim3.rs @@ -92,6 +92,12 @@ pub struct Sphere { impl Primitive3d for Sphere {} impl Sphere { + /// Create a new [`Sphere`] from a `radius` + #[inline(always)] + pub const fn new(radius: f32) -> Self { + Self { radius } + } + /// Finds the point on the sphere that is closest to the given `point`. /// /// If the point is outside the sphere, the returned point will be on the surface of the sphere.