From 160d031da367a7980a185db2381a21097842734f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20B=C3=BCttgenbach?= <62256001+solis-lumine-vorago@users.noreply.github.com> Date: Tue, 7 May 2024 01:20:27 +0200 Subject: [PATCH 1/7] Add `Measured2d` and `Measured3d` --- crates/bevy_math/src/primitives/dim2.rs | 156 +++++++++++++----------- crates/bevy_math/src/primitives/mod.rs | 17 +++ 2 files changed, 100 insertions(+), 73 deletions(-) diff --git a/crates/bevy_math/src/primitives/dim2.rs b/crates/bevy_math/src/primitives/dim2.rs index 14660edc5b03b..16177bbd8db43 100644 --- a/crates/bevy_math/src/primitives/dim2.rs +++ b/crates/bevy_math/src/primitives/dim2.rs @@ -1,6 +1,6 @@ use std::f32::consts::PI; -use super::{Primitive2d, WindingOrder}; +use super::{Measured2d, Primitive2d, WindingOrder}; use crate::{Dir2, Vec2}; /// A circle primitive @@ -32,19 +32,6 @@ impl Circle { 2.0 * self.radius } - /// Get the area of the circle - #[inline(always)] - pub fn area(&self) -> f32 { - PI * self.radius.powi(2) - } - - /// Get the perimeter or circumference of the circle - #[inline(always)] - #[doc(alias = "circumference")] - pub fn perimeter(&self) -> f32 { - 2.0 * PI * 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. @@ -65,6 +52,21 @@ impl Circle { } } +impl Measured2d for Circle { + /// Get the area of the circle + #[inline(always)] + fn area(&self) -> f32 { + PI * self.radius.powi(2) + } + + /// Get the perimeter or circumference of the circle + #[inline(always)] + #[doc(alias = "circumference")] + fn perimeter(&self) -> f32 { + 2.0 * PI * self.radius + } +} + /// An ellipse primitive #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] @@ -181,20 +183,6 @@ impl Annulus { self.outer_circle.radius - self.inner_circle.radius } - /// Get the area of the annulus - #[inline(always)] - pub fn area(&self) -> f32 { - PI * (self.outer_circle.radius.powi(2) - self.inner_circle.radius.powi(2)) - } - - /// Get the perimeter or circumference of the annulus, - /// which is the sum of the perimeters of the inner and outer circles. - #[inline(always)] - #[doc(alias = "circumference")] - pub fn perimeter(&self) -> f32 { - 2.0 * PI * (self.outer_circle.radius + self.inner_circle.radius) - } - /// Finds the point on the annulus that is closest to the given `point`: /// /// - If the point is outside of the annulus completely, the returned point will be on the outer perimeter. @@ -223,6 +211,22 @@ impl Annulus { } } +impl Measured2d for Annulus { + /// Get the area of the annulus + #[inline(always)] + fn area(&self) -> f32 { + PI * (self.outer_circle.radius.powi(2) - self.inner_circle.radius.powi(2)) + } + + /// Get the perimeter or circumference of the annulus, + /// which is the sum of the perimeters of the inner and outer circles. + #[inline(always)] + #[doc(alias = "circumference")] + fn perimeter(&self) -> f32 { + 2.0 * PI * (self.outer_circle.radius + self.inner_circle.radius) + } +} + /// An unbounded plane in 2D space. It forms a separating surface through the origin, /// stretching infinitely far #[derive(Clone, Copy, Debug, PartialEq)] @@ -404,25 +408,6 @@ impl Triangle2d { } } - /// Get the area of the triangle - #[inline(always)] - pub fn area(&self) -> f32 { - let [a, b, c] = self.vertices; - (a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y)).abs() / 2.0 - } - - /// Get the perimeter of the triangle - #[inline(always)] - pub fn perimeter(&self) -> f32 { - let [a, b, c] = self.vertices; - - let ab = a.distance(b); - let bc = b.distance(c); - let ca = c.distance(a); - - ab + bc + ca - } - /// Get the [`WindingOrder`] of the triangle #[inline(always)] #[doc(alias = "orientation")] @@ -481,6 +466,27 @@ impl Triangle2d { } } +impl Measured2d for Triangle2d { + /// Get the area of the triangle + #[inline(always)] + fn area(&self) -> f32 { + let [a, b, c] = self.vertices; + (a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y)).abs() / 2.0 + } + + /// Get the perimeter of the triangle + #[inline(always)] + fn perimeter(&self) -> f32 { + let [a, b, c] = self.vertices; + + let ab = a.distance(b); + let bc = b.distance(c); + let ca = c.distance(a); + + ab + bc + ca + } +} + /// A rectangle primitive #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] @@ -538,18 +544,6 @@ impl Rectangle { 2.0 * self.half_size } - /// Get the area of the rectangle - #[inline(always)] - pub fn area(&self) -> f32 { - 4.0 * self.half_size.x * self.half_size.y - } - - /// Get the perimeter of the rectangle - #[inline(always)] - pub fn perimeter(&self) -> f32 { - 4.0 * (self.half_size.x + self.half_size.y) - } - /// Finds the point on the rectangle that is closest to the given `point`. /// /// If the point is outside the rectangle, the returned point will be on the perimeter of the rectangle. @@ -561,6 +555,20 @@ impl Rectangle { } } +impl Measured2d for Rectangle { + /// Get the area of the rectangle + #[inline(always)] + fn area(&self) -> f32 { + 4.0 * self.half_size.x * self.half_size.y + } + + /// Get the perimeter of the rectangle + #[inline(always)] + fn perimeter(&self) -> f32 { + 4.0 * (self.half_size.x + self.half_size.y) + } +} + /// A polygon with N vertices. /// /// For a version without generics: [`BoxedPolygon`] @@ -682,20 +690,6 @@ impl RegularPolygon { 2.0 * self.circumradius() * (PI / self.sides as f32).sin() } - /// Get the area of the regular polygon - #[inline(always)] - pub fn area(&self) -> f32 { - let angle: f32 = 2.0 * PI / (self.sides as f32); - (self.sides as f32) * self.circumradius().powi(2) * angle.sin() / 2.0 - } - - /// Get the perimeter of the regular polygon. - /// This is the sum of its sides - #[inline(always)] - pub fn perimeter(&self) -> f32 { - self.sides as f32 * self.side_length() - } - /// Get the internal angle of the regular polygon in degrees. /// /// This is the angle formed by two adjacent sides with points @@ -749,6 +743,22 @@ impl RegularPolygon { } } +impl Measured2d for RegularPolygon { + /// Get the area of the regular polygon + #[inline(always)] + fn area(&self) -> f32 { + let angle: f32 = 2.0 * PI / (self.sides as f32); + (self.sides as f32) * self.circumradius().powi(2) * angle.sin() / 2.0 + } + + /// Get the perimeter of the regular polygon. + /// This is the sum of its sides + #[inline(always)] + fn perimeter(&self) -> f32 { + self.sides as f32 * self.side_length() + } +} + /// A 2D capsule primitive, also known as a stadium or pill shape. /// /// A two-dimensional capsule is defined as a neighborhood of points at a distance (radius) from a line diff --git a/crates/bevy_math/src/primitives/mod.rs b/crates/bevy_math/src/primitives/mod.rs index 8fda6924ec5e8..debb1300e025b 100644 --- a/crates/bevy_math/src/primitives/mod.rs +++ b/crates/bevy_math/src/primitives/mod.rs @@ -29,3 +29,20 @@ pub enum WindingOrder { #[doc(alias("Degenerate", "Collinear"))] Invalid, } + +/// A trait for getting measurements of 2D shapes +pub trait Measured2d { + /// Get the perimeter of the shape + fn perimeter(&self) -> f32; + + /// Get the area of the shape + fn area(&self) -> f32; +} + +/// A trait for getting measurements of 3D shapes +pub trait Measured3d { + /// Get the surface area of the shape + fn area(&self) -> f32; + /// Get the volume of the shape + fn volume(&self) -> f32; +} From dc6ec01946d99a94649e8a238213e5c103423fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20B=C3=BCttgenbach?= <62256001+solis-lumine-vorago@users.noreply.github.com> Date: Tue, 7 May 2024 01:26:32 +0200 Subject: [PATCH 2/7] implement `Measured3d` --- crates/bevy_math/src/primitives/dim3.rs | 158 +++++++++++++----------- 1 file changed, 87 insertions(+), 71 deletions(-) diff --git a/crates/bevy_math/src/primitives/dim3.rs b/crates/bevy_math/src/primitives/dim3.rs index b3308acbf8089..78944244a2585 100644 --- a/crates/bevy_math/src/primitives/dim3.rs +++ b/crates/bevy_math/src/primitives/dim3.rs @@ -1,6 +1,6 @@ use std::f32::consts::{FRAC_PI_3, PI}; -use super::{Circle, Primitive3d}; +use super::{Circle, Measured2d, Measured3d, Primitive3d}; use crate::{Dir3, InvalidDirectionError, Mat3, Vec2, Vec3}; /// A sphere primitive @@ -32,18 +32,6 @@ impl Sphere { 2.0 * self.radius } - /// Get the surface area of the sphere - #[inline(always)] - pub fn area(&self) -> f32 { - 4.0 * PI * self.radius.powi(2) - } - - /// Get the volume of the sphere - #[inline(always)] - pub fn volume(&self) -> f32 { - 4.0 * FRAC_PI_3 * self.radius.powi(3) - } - /// 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. @@ -64,6 +52,20 @@ impl Sphere { } } +impl Measured3d for Sphere { + /// Get the surface area of the sphere + #[inline(always)] + fn area(&self) -> f32 { + 4.0 * PI * self.radius.powi(2) + } + + /// Get the volume of the sphere + #[inline(always)] + fn volume(&self) -> f32 { + 4.0 * FRAC_PI_3 * self.radius.powi(3) + } +} + /// A bounded plane in 3D space. It forms a surface starting from the origin with a defined height and width. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] @@ -360,9 +362,21 @@ impl Cuboid { 2.0 * self.half_size } + /// Finds the point on the cuboid that is closest to the given `point`. + /// + /// If the point is outside the cuboid, the returned point will be on the surface of the cuboid. + /// Otherwise, it will be inside the cuboid and returned as is. + #[inline(always)] + pub fn closest_point(&self, point: Vec3) -> Vec3 { + // Clamp point coordinates to the cuboid + point.clamp(-self.half_size, self.half_size) + } +} + +impl Measured3d for Cuboid { /// Get the surface area of the cuboid #[inline(always)] - pub fn area(&self) -> f32 { + fn area(&self) -> f32 { 8.0 * (self.half_size.x * self.half_size.y + self.half_size.y * self.half_size.z + self.half_size.x * self.half_size.z) @@ -370,19 +384,9 @@ impl Cuboid { /// Get the volume of the cuboid #[inline(always)] - pub fn volume(&self) -> f32 { + fn volume(&self) -> f32 { 8.0 * self.half_size.x * self.half_size.y * self.half_size.z } - - /// Finds the point on the cuboid that is closest to the given `point`. - /// - /// If the point is outside the cuboid, the returned point will be on the surface of the cuboid. - /// Otherwise, it will be inside the cuboid and returned as is. - #[inline(always)] - pub fn closest_point(&self, point: Vec3) -> Vec3 { - // Clamp point coordinates to the cuboid - point.clamp(-self.half_size, self.half_size) - } } /// A cylinder primitive @@ -437,16 +441,18 @@ impl Cylinder { pub fn base_area(&self) -> f32 { PI * self.radius.powi(2) } +} +impl Measured3d for Cylinder { /// Get the total surface area of the cylinder #[inline(always)] - pub fn area(&self) -> f32 { + fn area(&self) -> f32 { 2.0 * PI * self.radius * (self.radius + 2.0 * self.half_height) } /// Get the volume of the cylinder #[inline(always)] - pub fn volume(&self) -> f32 { + fn volume(&self) -> f32 { self.base_area() * 2.0 * self.half_height } } @@ -492,17 +498,19 @@ impl Capsule3d { half_height: self.half_length, } } +} +impl Measured3d for Capsule3d { /// Get the surface area of the capsule #[inline(always)] - pub fn area(&self) -> f32 { + fn area(&self) -> f32 { // Modified version of 2pi * r * (2r + h) 4.0 * PI * self.radius * (self.radius + self.half_length) } /// Get the volume of the capsule #[inline(always)] - pub fn volume(&self) -> f32 { + fn volume(&self) -> f32 { // Modified version of pi * r^2 * (4/3 * r + a) let diameter = self.radius * 2.0; PI * self.radius * diameter * (diameter / 3.0 + self.half_length) @@ -550,16 +558,18 @@ impl Cone { pub fn base_area(&self) -> f32 { PI * self.radius.powi(2) } +} +impl Measured3d for Cone { /// Get the total surface area of the cone #[inline(always)] - pub fn area(&self) -> f32 { + fn area(&self) -> f32 { self.base_area() + self.lateral_area() } /// Get the volume of the cone #[inline(always)] - pub fn volume(&self) -> f32 { + fn volume(&self) -> f32 { (self.base_area() * self.height) / 3.0 } } @@ -681,18 +691,20 @@ impl Torus { std::cmp::Ordering::Less => TorusKind::Spindle, } } +} +impl Measured3d for Torus { /// Get the surface area of the torus. Note that this only produces /// the expected result when the torus has a ring and isn't self-intersecting #[inline(always)] - pub fn area(&self) -> f32 { + fn area(&self) -> f32 { 4.0 * PI.powi(2) * self.major_radius * self.minor_radius } /// Get the volume of the torus. Note that this only produces /// the expected result when the torus has a ring and isn't self-intersecting #[inline(always)] - pub fn volume(&self) -> f32 { + fn volume(&self) -> f32 { 2.0 * PI.powi(2) * self.major_radius * self.minor_radius.powi(2) } } @@ -729,22 +741,6 @@ impl Triangle3d { } } - /// Get the area of the triangle. - #[inline(always)] - pub fn area(&self) -> f32 { - let [a, b, c] = self.vertices; - let ab = b - a; - let ac = c - a; - ab.cross(ac).length() / 2.0 - } - - /// Get the perimeter of the triangle. - #[inline(always)] - pub fn perimeter(&self) -> f32 { - let [a, b, c] = self.vertices; - a.distance(b) + b.distance(c) + c.distance(a) - } - /// Get the normal of the triangle in the direction of the right-hand rule, assuming /// the vertices are ordered in a counter-clockwise direction. /// @@ -835,6 +831,24 @@ impl Triangle3d { } } +impl Measured2d for Triangle3d { + /// Get the area of the triangle. + #[inline(always)] + fn area(&self) -> f32 { + let [a, b, c] = self.vertices; + let ab = b - a; + let ac = c - a; + ab.cross(ac).length() / 2.0 + } + + /// Get the perimeter of the triangle. + #[inline(always)] + fn perimeter(&self) -> f32 { + let [a, b, c] = self.vertices; + a.distance(b) + b.distance(c) + c.distance(a) + } +} + /// A tetrahedron primitive. #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] @@ -868,28 +882,6 @@ impl Tetrahedron { } } - /// Get the surface area of the tetrahedron. - #[inline(always)] - pub fn area(&self) -> f32 { - let [a, b, c, d] = self.vertices; - let ab = b - a; - let ac = c - a; - let ad = d - a; - let bc = c - b; - let bd = d - b; - (ab.cross(ac).length() - + ab.cross(ad).length() - + ac.cross(ad).length() - + bc.cross(bd).length()) - / 2.0 - } - - /// Get the volume of the tetrahedron. - #[inline(always)] - pub fn volume(&self) -> f32 { - self.signed_volume().abs() - } - /// Get the signed volume of the tetrahedron. /// /// If it's negative, the normal vector of the face defined by @@ -915,6 +907,30 @@ impl Tetrahedron { } } +impl Measured3d for Tetrahedron { + /// Get the surface area of the tetrahedron. + #[inline(always)] + fn area(&self) -> f32 { + let [a, b, c, d] = self.vertices; + let ab = b - a; + let ac = c - a; + let ad = d - a; + let bc = c - b; + let bd = d - b; + (ab.cross(ac).length() + + ab.cross(ad).length() + + ac.cross(ad).length() + + bc.cross(bd).length()) + / 2.0 + } + + /// Get the volume of the tetrahedron. + #[inline(always)] + fn volume(&self) -> f32 { + self.signed_volume().abs() + } +} + #[cfg(test)] mod tests { // Reference values were computed by hand and/or with external tools From f54bcd002c2ae1050c0c55c1bf52e33d7ed6db4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20B=C3=BCttgenbach?= <62256001+solis-lumine-vorago@users.noreply.github.com> Date: Tue, 7 May 2024 01:37:20 +0200 Subject: [PATCH 3/7] Add `Extrusion` --- crates/bevy_math/src/primitives/dim3.rs | 38 ++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/crates/bevy_math/src/primitives/dim3.rs b/crates/bevy_math/src/primitives/dim3.rs index 78944244a2585..9726f7b910035 100644 --- a/crates/bevy_math/src/primitives/dim3.rs +++ b/crates/bevy_math/src/primitives/dim3.rs @@ -1,6 +1,6 @@ use std::f32::consts::{FRAC_PI_3, PI}; -use super::{Circle, Measured2d, Measured3d, Primitive3d}; +use super::{Circle, Measured2d, Measured3d, Primitive2d, Primitive3d}; use crate::{Dir3, InvalidDirectionError, Mat3, Vec2, Vec3}; /// A sphere primitive @@ -931,6 +931,42 @@ impl Measured3d for Tetrahedron { } } +/// A shape representiing an extruded `base_shape`. +/// +/// The resulting volumes are prisms. +#[doc(alias = "Prism")] +#[derive(Clone, Copy, Debug, PartialEq)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +pub struct Extrusion { + /// The base shape of the extrusion + pub base_shape: T, + /// Half of the depth of the extrusion + pub half_depth: f32, +} +impl Primitive3d for Extrusion {} + +impl Extrusion { + /// Create a new `Extrusion` from a given `base_shape` and `depth` + pub fn new(base_shape: T, depth: f32) -> Self { + Self { + base_shape, + half_depth: depth / 2., + } + } +} + +impl Measured3d for Extrusion { + /// Get the surface area of the extrusion + fn area(&self) -> f32 { + 2. * (self.base_shape.area() + self.half_depth * self.base_shape.perimeter()) + } + + /// Get the volume of the extrusion + fn volume(&self) -> f32 { + 2. * self.base_shape.area() * self.half_depth + } +} + #[cfg(test)] mod tests { // Reference values were computed by hand and/or with external tools From 66f78bed4d40d2c2b3c622e55120981e65c3cc08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20B=C3=BCttgenbach?= <62256001+solis-lumine-vorago@users.noreply.github.com> Date: Tue, 7 May 2024 10:22:49 +0200 Subject: [PATCH 4/7] Implement `Measured2d` for `Ellipse` --- crates/bevy_math/src/primitives/dim2.rs | 40 +++++++++++++------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/crates/bevy_math/src/primitives/dim2.rs b/crates/bevy_math/src/primitives/dim2.rs index b74aacb794855..eaedb9c099c50 100644 --- a/crates/bevy_math/src/primitives/dim2.rs +++ b/crates/bevy_math/src/primitives/dim2.rs @@ -131,11 +131,31 @@ impl Ellipse { (a * a - b * b).sqrt() } + /// Returns the length of the semi-major axis. This corresponds to the longest radius of the ellipse. + #[inline(always)] + pub fn semi_major(&self) -> f32 { + self.half_size.max_element() + } + + /// Returns the length of the semi-minor axis. This corresponds to the shortest radius of the ellipse. + #[inline(always)] + pub fn semi_minor(&self) -> f32 { + self.half_size.min_element() + } +} + +impl Measured2d for Ellipse { + /// Get the area of the ellipse + #[inline(always)] + fn area(&self) -> f32 { + PI * self.half_size.x * self.half_size.y + } + #[inline(always)] /// Get an approximation for the perimeter or circumference of the ellipse. /// /// The approximation is reasonably precise with a relative error less than 0.007%, getting more precise as the eccentricity of the ellipse decreases. - pub fn perimeter(&self) -> f32 { + fn perimeter(&self) -> f32 { let a = self.semi_major(); let b = self.semi_minor(); @@ -186,24 +206,6 @@ impl Ellipse { .map(|i| BINOMIAL_COEFFICIENTS[i] * h.powi(i as i32)) .sum::() } - - /// Returns the length of the semi-major axis. This corresponds to the longest radius of the ellipse. - #[inline(always)] - pub fn semi_major(&self) -> f32 { - self.half_size.max_element() - } - - /// Returns the length of the semi-minor axis. This corresponds to the shortest radius of the ellipse. - #[inline(always)] - pub fn semi_minor(&self) -> f32 { - self.half_size.min_element() - } - - /// Get the area of the ellipse - #[inline(always)] - pub fn area(&self) -> f32 { - PI * self.half_size.x * self.half_size.y - } } /// A primitive shape formed by the region between two circles, also known as a ring. From bc846913daa0671c557c06a087d7fee2e36b5acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20B=C3=BCttgenbach?= <62256001+solis-lumine-vorago@users.noreply.github.com> Date: Tue, 7 May 2024 10:33:10 +0200 Subject: [PATCH 5/7] Add tests --- crates/bevy_math/src/primitives/dim3.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/bevy_math/src/primitives/dim3.rs b/crates/bevy_math/src/primitives/dim3.rs index 9726f7b910035..d2163aeeb9968 100644 --- a/crates/bevy_math/src/primitives/dim3.rs +++ b/crates/bevy_math/src/primitives/dim3.rs @@ -1198,4 +1198,22 @@ mod tests { let degenerate = Triangle3d::new(Vec3::NEG_ONE, Vec3::ZERO, Vec3::ONE); assert!(degenerate.is_degenerate(), "did not find degenerate"); } + + #[test] + fn extrusion_math() { + let circle = Circle::new(0.75); + let cylinder = Extrusion::new(circle, 2.5); + assert_eq!(cylinder.area(), 15.315264, "incorrect surface area"); + assert_eq!(cylinder.volume(), 4.417865, "incorrect volume"); + + let annulus = crate::primitives::Annulus::new(0.25, 1.375); + let tube = Extrusion::new(annulus, 0.333); + assert_eq!(tube.area(), 14.886437, "incorrect surface area"); + assert_eq!(tube.volume(), 1.9124937, "incorrect volume"); + + let polygon = crate::primitives::RegularPolygon::new(3.8, 7); + let regular_prism = Extrusion::new(polygon, 1.25); + assert_eq!(regular_prism.area(), 107.8808, "incorrect surface area"); + assert_eq!(regular_prism.volume(), 49.392204, "incorrect volume"); + } } From c541aff06252984198a74b75f844ab7cf61bb936 Mon Sep 17 00:00:00 2001 From: Lynn <62256001+solis-lumine-vorago@users.noreply.github.com> Date: Tue, 7 May 2024 12:45:42 +0200 Subject: [PATCH 6/7] Improve docs Co-authored-by: Alice Cecile --- crates/bevy_math/src/primitives/dim3.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/bevy_math/src/primitives/dim3.rs b/crates/bevy_math/src/primitives/dim3.rs index d2163aeeb9968..2906492917387 100644 --- a/crates/bevy_math/src/primitives/dim3.rs +++ b/crates/bevy_math/src/primitives/dim3.rs @@ -931,9 +931,13 @@ impl Measured3d for Tetrahedron { } } -/// A shape representiing an extruded `base_shape`. +/// A 3D shape representing an extruded 2D `base_shape`. +/// +/// Extruding a shape effectively "thickens" a 2D shapes, +/// creating a shape with the same cross-section over the entire depth. /// /// The resulting volumes are prisms. +/// For example, a triangle becomes a triangular prism, while a circle becomes a cylinder. #[doc(alias = "Prism")] #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] From 16065e060e8b3eba9ba958ef82e3f2a5498cce43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20B=C3=BCttgenbach?= <62256001+solis-lumine-vorago@users.noreply.github.com> Date: Tue, 7 May 2024 13:31:38 +0200 Subject: [PATCH 7/7] Fix spacing --- crates/bevy_math/src/primitives/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_math/src/primitives/mod.rs b/crates/bevy_math/src/primitives/mod.rs index debb1300e025b..460e635867ecb 100644 --- a/crates/bevy_math/src/primitives/mod.rs +++ b/crates/bevy_math/src/primitives/mod.rs @@ -43,6 +43,7 @@ pub trait Measured2d { pub trait Measured3d { /// Get the surface area of the shape fn area(&self) -> f32; + /// Get the volume of the shape fn volume(&self) -> f32; }