-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1871 from hannobraun/aabb
Compute AABB from boundary representation
- Loading branch information
Showing
8 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use fj_math::Aabb; | ||
|
||
use crate::objects::Cycle; | ||
|
||
impl super::BoundingVolume<2> for Cycle { | ||
fn aabb(&self) -> Option<Aabb<2>> { | ||
let mut aabb: Option<Aabb<2>> = None; | ||
|
||
for half_edge in self.half_edges() { | ||
let new_aabb = half_edge | ||
.aabb() | ||
.expect("`HalfEdge` can always compute AABB"); | ||
aabb = Some(aabb.map_or(new_aabb, |aabb| aabb.merged(&new_aabb))); | ||
} | ||
|
||
aabb | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use fj_math::Aabb; | ||
|
||
use crate::objects::HalfEdge; | ||
|
||
impl super::BoundingVolume<2> for HalfEdge { | ||
fn aabb(&self) -> Option<Aabb<2>> { | ||
let points = self.boundary().map(|point_curve| { | ||
self.curve().point_from_path_coords(point_curve) | ||
}); | ||
|
||
Some(Aabb::<2>::from_points(points)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use fj_math::Aabb; | ||
|
||
use crate::{geometry::curve::GlobalPath, objects::Face}; | ||
|
||
impl super::BoundingVolume<3> for Face { | ||
fn aabb(&self) -> Option<Aabb<3>> { | ||
self.exterior().aabb().map(|aabb2| { | ||
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::Line(_) => Aabb { | ||
min: surface.point_from_surface_coords(aabb2.min), | ||
max: surface.point_from_surface_coords(aabb2.max), | ||
}, | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//! Compute a bounding volume for an object | ||
mod cycle; | ||
mod edge; | ||
mod face; | ||
mod shell; | ||
mod solid; | ||
|
||
use fj_math::Aabb; | ||
|
||
/// Compute a bounding volume for an object | ||
pub trait BoundingVolume<const D: usize> { | ||
/// Compute an axis-aligned bounding box (AABB) | ||
/// | ||
/// Return `None`, if no AABB can be computed (if the object is empty). | ||
fn aabb(&self) -> Option<Aabb<D>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use fj_math::Aabb; | ||
|
||
use crate::objects::Shell; | ||
|
||
impl super::BoundingVolume<3> for Shell { | ||
fn aabb(&self) -> Option<Aabb<3>> { | ||
let mut aabb: Option<Aabb<3>> = None; | ||
|
||
for face in self.faces() { | ||
let new_aabb = face.aabb(); | ||
aabb = aabb.map_or(new_aabb, |aabb| match new_aabb { | ||
Some(new_aabb) => Some(aabb.merged(&new_aabb)), | ||
None => Some(aabb), | ||
}); | ||
} | ||
|
||
aabb | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use fj_math::Aabb; | ||
|
||
use crate::objects::Solid; | ||
|
||
impl super::BoundingVolume<3> for Solid { | ||
fn aabb(&self) -> Option<Aabb<3>> { | ||
let mut aabb: Option<Aabb<3>> = None; | ||
|
||
for shell in self.shells() { | ||
let new_aabb = shell.aabb(); | ||
aabb = aabb.map_or(new_aabb, |aabb| match new_aabb { | ||
Some(new_aabb) => Some(aabb.merged(&new_aabb)), | ||
None => Some(aabb), | ||
}); | ||
} | ||
|
||
aabb | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters