mirror of
https://github.com/bevyengine/bevy
synced 2024-11-14 00:47:32 +00:00
Implement Bounded2d
for Annulus
(#14326)
# Objective `Annulus` is missing `Bounded2d` even though the implementation is trivial. ## Solution Implement `Bounded2d` for `Annulus`. ## Testing There is a basic test to verify that the produced bounding volumes are correct.
This commit is contained in:
parent
36b521d069
commit
cf1b7fa4cc
1 changed files with 30 additions and 5 deletions
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
primitives::{
|
primitives::{
|
||||||
Arc2d, BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, CircularSector, CircularSegment,
|
Annulus, Arc2d, BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, CircularSector,
|
||||||
Ellipse, Line2d, Plane2d, Polygon, Polyline2d, Rectangle, RegularPolygon, Rhombus,
|
CircularSegment, Ellipse, Line2d, Plane2d, Polygon, Polyline2d, Rectangle, RegularPolygon,
|
||||||
Segment2d, Triangle2d,
|
Rhombus, Segment2d, Triangle2d,
|
||||||
},
|
},
|
||||||
Dir2, Mat2, Rot2, Vec2,
|
Dir2, Mat2, Rot2, Vec2,
|
||||||
};
|
};
|
||||||
|
@ -163,6 +163,16 @@ impl Bounded2d for Ellipse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Bounded2d for Annulus {
|
||||||
|
fn aabb_2d(&self, translation: Vec2, _rotation: impl Into<Rot2>) -> Aabb2d {
|
||||||
|
Aabb2d::new(translation, Vec2::splat(self.outer_circle.radius))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bounding_circle(&self, translation: Vec2, _rotation: impl Into<Rot2>) -> BoundingCircle {
|
||||||
|
BoundingCircle::new(translation, self.outer_circle.radius)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Bounded2d for Rhombus {
|
impl Bounded2d for Rhombus {
|
||||||
fn aabb_2d(&self, translation: Vec2, rotation: impl Into<Rot2>) -> Aabb2d {
|
fn aabb_2d(&self, translation: Vec2, rotation: impl Into<Rot2>) -> Aabb2d {
|
||||||
let rotation_mat = rotation.into();
|
let rotation_mat = rotation.into();
|
||||||
|
@ -406,8 +416,9 @@ mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
bounding::Bounded2d,
|
bounding::Bounded2d,
|
||||||
primitives::{
|
primitives::{
|
||||||
Arc2d, Capsule2d, Circle, CircularSector, CircularSegment, Ellipse, Line2d, Plane2d,
|
Annulus, Arc2d, Capsule2d, Circle, CircularSector, CircularSegment, Ellipse, Line2d,
|
||||||
Polygon, Polyline2d, Rectangle, RegularPolygon, Rhombus, Segment2d, Triangle2d,
|
Plane2d, Polygon, Polyline2d, Rectangle, RegularPolygon, Rhombus, Segment2d,
|
||||||
|
Triangle2d,
|
||||||
},
|
},
|
||||||
Dir2,
|
Dir2,
|
||||||
};
|
};
|
||||||
|
@ -728,6 +739,20 @@ mod tests {
|
||||||
assert_eq!(bounding_circle.radius(), 1.0);
|
assert_eq!(bounding_circle.radius(), 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn annulus() {
|
||||||
|
let annulus = Annulus::new(1.0, 2.0);
|
||||||
|
let translation = Vec2::new(2.0, 1.0);
|
||||||
|
|
||||||
|
let aabb = annulus.aabb_2d(translation, 1.0);
|
||||||
|
assert_eq!(aabb.min, Vec2::new(0.0, -1.0));
|
||||||
|
assert_eq!(aabb.max, Vec2::new(4.0, 3.0));
|
||||||
|
|
||||||
|
let bounding_circle = annulus.bounding_circle(translation, 1.0);
|
||||||
|
assert_eq!(bounding_circle.center, translation);
|
||||||
|
assert_eq!(bounding_circle.radius(), 2.0);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rhombus() {
|
fn rhombus() {
|
||||||
let rhombus = Rhombus::new(2.0, 1.0);
|
let rhombus = Rhombus::new(2.0, 1.0);
|
||||||
|
|
Loading…
Reference in a new issue