From 552aea5dd1c98c27f7f56203a03d9591a954fe32 Mon Sep 17 00:00:00 2001 From: "Alexis \"spectria\" Horizon" <118812919+spectria-limina@users.noreply.github.com> Date: Sat, 9 Mar 2024 03:35:46 -0500 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Joona Aalto Co-authored-by: Alice Cecile --- .../src/bounding/bounded2d/primitive_impls.rs | 14 ++++--------- crates/bevy_math/src/primitives/dim2.rs | 20 +++++++++---------- .../bevy_render/src/mesh/primitives/dim2.rs | 6 +++--- examples/2d/mesh2d_circular.rs | 1 - 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/crates/bevy_math/src/bounding/bounded2d/primitive_impls.rs b/crates/bevy_math/src/bounding/bounded2d/primitive_impls.rs index 414cc5875fa3d..fca5d55a39d79 100644 --- a/crates/bevy_math/src/bounding/bounded2d/primitive_impls.rs +++ b/crates/bevy_math/src/bounding/bounded2d/primitive_impls.rs @@ -37,7 +37,7 @@ fn arc_bounding_points(arc: Arc2d, rotation: f32) -> SmallVec<[Vec2; 7]> { bounds.push(arc.left_endpoint().rotate(rotation_vec)); bounds.push(arc.right_endpoint().rotate(rotation_vec)); - // The half-angles are measured from a starting point of π/2, being the angle of Vec::Y. + // The half-angles are measured from a starting point of π/2, being the angle of Vec2::Y. // Compute the normalized angles of the endpoints with the rotation taken into account, and then // check if we are looking for an angle that is between or outside them. let left_angle = (PI / 2.0 + arc.half_angle + rotation).rem_euclid(2.0 * PI); @@ -62,10 +62,7 @@ impl Bounded2d for Arc2d { fn aabb_2d(&self, translation: Vec2, rotation: f32) -> Aabb2d { // If our arc covers more than a circle, just return the bounding box of the circle. if self.half_angle >= PI { - return Circle { - radius: self.radius, - } - .aabb_2d(translation, rotation); + return Circle::new(self.radius).aabb_2d(translation, rotation); } Aabb2d::from_point_cloud(translation, 0.0, &arc_bounding_points(*self, rotation)) @@ -90,13 +87,10 @@ impl Bounded2d for CircularSector { fn aabb_2d(&self, translation: Vec2, rotation: f32) -> Aabb2d { // If our sector covers more than a circle, just return the bounding box of the circle. if self.half_angle() >= PI { - return Circle { - radius: self.radius(), - } - .aabb_2d(translation, rotation); + return Circle::new(self.radius()).aabb_2d(translation, rotation); } - // Otherwise, we use the same logic as for Arc2d, above, just with the circle's cetner as an additional possibility. + // Otherwise, we use the same logic as for Arc2d, above, just with the circle's center as an additional possibility. let mut bounds = arc_bounding_points(self.arc, rotation); bounds.push(Vec2::ZERO); diff --git a/crates/bevy_math/src/primitives/dim2.rs b/crates/bevy_math/src/primitives/dim2.rs index 30f951a63c84d..b7a3b135e540b 100644 --- a/crates/bevy_math/src/primitives/dim2.rs +++ b/crates/bevy_math/src/primitives/dim2.rs @@ -71,16 +71,16 @@ const HALF_PI: f32 = PI / 2.0; /// /// An arc has no area. /// If you want to include the portion of a circle's area swept out by the arc, -/// use [`CircularSector`]. +/// use the pie-shaped [`CircularSector`]. /// If you want to include only the space inside the convex hull of the arc, -/// use [`CircularSegment`]. +/// use the bowl-shaped [`CircularSegment`]. /// /// The arc is drawn starting from [`Vec2::Y`], extending by `half_angle` radians on /// either side. The center of the circle is the origin [`Vec2::ZERO`]. Note that this /// means that the origin may not be within the `Arc2d`'s convex hull. /// /// **Warning:** Arcs with negative angle or radius, or with angle greater than an entire circle, are not officially supported. -/// We recommend normalizing arcs to have an angle in [0, 2π]. +/// It is recommended to normalize arcs to have an angle in [0, 2π]. #[derive(Clone, Copy, Debug, PartialEq)] #[doc(alias("CircularArc", "CircleArc"))] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] @@ -103,7 +103,7 @@ impl Default for Arc2d { } impl Arc2d { - /// Create a new [`Arc2d`] from a `radius`, and a `half_angle` + /// Create a new [`Arc2d`] from a `radius` and a `half_angle` #[inline(always)] pub fn new(radius: f32, half_angle: f32) -> Self { Self { radius, half_angle } @@ -258,7 +258,7 @@ pub struct CircularSector { impl Primitive2d for CircularSector {} impl Default for CircularSector { - /// Returns the default [`CircularSector`] with radius `0.5` and covering a quarter circle + /// Returns the default [`CircularSector`] with radius `0.5` and covering a third of a circle fn default() -> Self { Self::from(Arc2d::default()) } @@ -271,7 +271,7 @@ impl From for CircularSector { } impl CircularSector { - /// Create a new [`CircularSector`] from a `radius`, and an `angle` + /// Create a new [`CircularSector`] from a `radius` and an `angle` #[inline(always)] pub fn new(radius: f32, angle: f32) -> Self { Self::from(Arc2d::new(radius, angle)) @@ -391,7 +391,7 @@ pub struct CircularSegment { impl Primitive2d for CircularSegment {} impl Default for CircularSegment { - /// Returns the default [`CircularSegment`] with radius `0.5` and covering a quarter circle. + /// Returns the default [`CircularSegment`] with radius `0.5` and covering a third of a circle. fn default() -> Self { Self::from(Arc2d::default()) } @@ -462,14 +462,14 @@ impl CircularSegment { Vec2::ZERO } - /// Get half the length of the chord of the segment, which is the segment's base + /// Get half the length of the chord, which is the segment's base #[inline(always)] #[doc(alias = "half_base_length")] pub fn half_chord_length(&self) -> f32 { self.arc.half_chord_length() } - /// Get the length of the chord of the segment, which is the segment's base + /// Get the length of the chord, which is the segment's base #[inline(always)] #[doc(alias = "base_length")] #[doc(alias = "base")] @@ -477,7 +477,7 @@ impl CircularSegment { self.arc.chord_length() } - /// Get the midpoint of the chord of the segment, which is the segment's base + /// Get the midpoint of the chord, which is the segment's base #[inline(always)] #[doc(alias = "base_midpoint")] pub fn chord_midpoint(&self) -> Vec2 { diff --git a/crates/bevy_render/src/mesh/primitives/dim2.rs b/crates/bevy_render/src/mesh/primitives/dim2.rs index 2e0bc1fa90cb6..974b9ea37f988 100644 --- a/crates/bevy_render/src/mesh/primitives/dim2.rs +++ b/crates/bevy_render/src/mesh/primitives/dim2.rs @@ -82,7 +82,7 @@ impl From for Mesh { } } -/// Specifies how to generate UV-mappings for [`CircularSector`] and [`CircularSegment`] shapes. +/// Specifies how to generate UV-mappings for the [`CircularSector`] and [`CircularSegment`] shapes. #[derive(Copy, Clone, Debug, PartialEq)] pub enum CircularMeshUvMode { /// Treats the shape as a mask over a circle of equal size and radius, @@ -102,7 +102,7 @@ impl Default for CircularMeshUvMode { /// A builder used for creating a [`Mesh`] with a [`CircularSector`] shape. /// /// The resulting mesh will have a UV-map such that the center of the circle is -/// at the centure of the texture. +/// at the center of the texture. #[derive(Clone, Debug)] pub struct CircularSectorMeshBuilder { /// The sector shape. @@ -225,7 +225,7 @@ impl From for Mesh { /// A builder used for creating a [`Mesh`] with a [`CircularSegment`] shape. /// /// The resulting mesh will have a UV-map such that the center of the circle is -/// at the centure of the texture. +/// at the center of the texture. #[derive(Clone, Copy, Debug)] pub struct CircularSegmentMeshBuilder { /// The segment shape. diff --git a/examples/2d/mesh2d_circular.rs b/examples/2d/mesh2d_circular.rs index d83027035c129..af203b1e1560f 100644 --- a/examples/2d/mesh2d_circular.rs +++ b/examples/2d/mesh2d_circular.rs @@ -118,7 +118,6 @@ fn draw_bounds( gizmos.rect_2d(aabb.center(), 0.0, aabb.half_size() * 2.0, Color::RED); let bounding_circle = shape.0.bounding_circle(translation, rotation); - dbg!(bounding_circle); gizmos.circle_2d( bounding_circle.center, bounding_circle.radius(),