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:
Joona Aalto 2024-07-15 19:08:35 +03:00 committed by GitHub
parent 36b521d069
commit cf1b7fa4cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,9 +2,9 @@
use crate::{
primitives::{
Arc2d, BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, CircularSector, CircularSegment,
Ellipse, Line2d, Plane2d, Polygon, Polyline2d, Rectangle, RegularPolygon, Rhombus,
Segment2d, Triangle2d,
Annulus, Arc2d, BoxedPolygon, BoxedPolyline2d, Capsule2d, Circle, CircularSector,
CircularSegment, Ellipse, Line2d, Plane2d, Polygon, Polyline2d, Rectangle, RegularPolygon,
Rhombus, Segment2d, Triangle2d,
},
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 {
fn aabb_2d(&self, translation: Vec2, rotation: impl Into<Rot2>) -> Aabb2d {
let rotation_mat = rotation.into();
@ -406,8 +416,9 @@ mod tests {
use crate::{
bounding::Bounded2d,
primitives::{
Arc2d, Capsule2d, Circle, CircularSector, CircularSegment, Ellipse, Line2d, Plane2d,
Polygon, Polyline2d, Rectangle, RegularPolygon, Rhombus, Segment2d, Triangle2d,
Annulus, Arc2d, Capsule2d, Circle, CircularSector, CircularSegment, Ellipse, Line2d,
Plane2d, Polygon, Polyline2d, Rectangle, RegularPolygon, Rhombus, Segment2d,
Triangle2d,
},
Dir2,
};
@ -728,6 +739,20 @@ mod tests {
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]
fn rhombus() {
let rhombus = Rhombus::new(2.0, 1.0);