Skip to content

Commit

Permalink
Merge pull request #1888 from hannobraun/aabb
Browse files Browse the repository at this point in the history
Support AABB computation for arcs and curved faces
  • Loading branch information
hannobraun authored Jun 19, 2023
2 parents db40c13 + a69a65f commit 048bc95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
18 changes: 12 additions & 6 deletions crates/fj-core/src/algorithms/bounding_volume/edge.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
use fj_math::Aabb;
use fj_math::{Aabb, Vector};

use crate::{geometry::curve::Curve, objects::HalfEdge};

impl super::BoundingVolume<2> for HalfEdge {
fn aabb(&self) -> Option<Aabb<2>> {
match self.curve() {
Curve::Circle(_) => {
// I don't currently have an example model to test this with.
// This should change soon, and then this will panic and can be
// addressed.
todo!("Computing AABB of arc is not supported yet")
Curve::Circle(circle) => {
// Just calculate the AABB of the whole circle. This is not the
// most precise, but it should do for now.

let center_to_min_max =
Vector::from([circle.radius(), circle.radius()]);

Some(Aabb {
min: circle.center() - center_to_min_max,
max: circle.center() + center_to_min_max,
})
}
Curve::Line(_) => {
let points = self.boundary().map(|point_curve| {
Expand Down
16 changes: 11 additions & 5 deletions crates/fj-core/src/algorithms/bounding_volume/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ impl super::BoundingVolume<3> for Face {
let surface = self.surface().geometry();

match surface.u {
GlobalPath::Circle(_) => {
// I don't currently have an example model to test this
// with. This should change soon, and then this will panic
// and can be addressed.
todo!("Computing AABB of curved face is not supported yet")
GlobalPath::Circle(circle) => {
// This is not the most precise way to calculate the AABB,
// doing it for the whole circle, but it should do.

let aabb_bottom = circle.aabb();
let aabb_top = Aabb {
min: aabb_bottom.min + surface.v,
max: aabb_bottom.max + surface.v,
};

aabb_bottom.merged(&aabb_top)
}
GlobalPath::Line(_) => Aabb {
min: surface.point_from_surface_coords(aabb2.min),
Expand Down

0 comments on commit 048bc95

Please sign in to comment.