Merge pull request #2298 from hannobraun/geometry

Make some cleanups in `BoundingVolume` code
This commit is contained in:
Hanno Braun 2024-03-26 12:29:55 +01:00 committed by GitHub
commit 54eef7687c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 27 additions and 21 deletions

View File

@ -2,13 +2,16 @@ use fj_math::Aabb;
use crate::{geometry::Geometry, topology::Cycle};
impl super::BoundingVolume<2> for Cycle {
fn aabb(&self, geometry: &Geometry) -> Option<Aabb<2>> {
impl super::BoundingVolume<2> for &Cycle {
fn aabb(self, geometry: &Geometry) -> Option<Aabb<2>> {
let cycle = self;
let mut aabb: Option<Aabb<2>> = None;
for edge in self.half_edges() {
let new_aabb =
edge.aabb(geometry).expect("`Edge` can always compute AABB");
for half_edge in cycle.half_edges() {
let new_aabb = half_edge
.aabb(geometry)
.expect("`HalfEdge` can always compute AABB");
aabb = Some(aabb.map_or(new_aabb, |aabb| aabb.merged(&new_aabb)));
}

View File

@ -5,8 +5,8 @@ use crate::{
topology::Face,
};
impl super::BoundingVolume<3> for Face {
fn aabb(&self, geometry: &Geometry) -> Option<Aabb<3>> {
impl super::BoundingVolume<3> for &Face {
fn aabb(self, geometry: &Geometry) -> Option<Aabb<3>> {
self.region().exterior().aabb(geometry).map(|aabb2| {
let surface = geometry.of_surface(self.surface());

View File

@ -6,9 +6,14 @@ use crate::{
topology::HalfEdge,
};
impl super::BoundingVolume<2> for Handle<HalfEdge> {
fn aabb(&self, geometry: &Geometry) -> Option<Aabb<2>> {
match geometry.of_half_edge(self).path {
impl super::BoundingVolume<2> for &Handle<HalfEdge> {
fn aabb(self, geometry: &Geometry) -> Option<Aabb<2>> {
let half_edge = self;
let half_edge = geometry.of_half_edge(half_edge);
let path = half_edge.path;
match path {
SurfacePath::Circle(circle) => {
// Just calculate the AABB of the whole circle. This is not the
// most precise, but it should do for now.
@ -22,10 +27,8 @@ impl super::BoundingVolume<2> for Handle<HalfEdge> {
})
}
SurfacePath::Line(_) => {
let geometry = geometry.of_half_edge(self);
let points = geometry.boundary.inner.map(|point_curve| {
geometry.path.point_from_path_coords(point_curve)
let points = half_edge.boundary.inner.map(|point_curve| {
path.point_from_path_coords(point_curve)
});
Some(Aabb::<2>::from_points(points))

View File

@ -1,8 +1,8 @@
//! Compute a bounding volume for an object
mod cycle;
mod edge;
mod face;
mod half_edge;
mod shell;
mod solid;
@ -15,5 +15,5 @@ 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, geometry: &Geometry) -> Option<Aabb<D>>;
fn aabb(self, geometry: &Geometry) -> Option<Aabb<D>>;
}

View File

@ -2,8 +2,8 @@ use fj_math::Aabb;
use crate::{geometry::Geometry, topology::Shell};
impl super::BoundingVolume<3> for Shell {
fn aabb(&self, geometry: &Geometry) -> Option<Aabb<3>> {
impl super::BoundingVolume<3> for &Shell {
fn aabb(self, geometry: &Geometry) -> Option<Aabb<3>> {
let mut aabb: Option<Aabb<3>> = None;
for face in self.faces() {

View File

@ -2,8 +2,8 @@ use fj_math::Aabb;
use crate::{geometry::Geometry, topology::Solid};
impl super::BoundingVolume<3> for Solid {
fn aabb(&self, geometry: &Geometry) -> Option<Aabb<3>> {
impl super::BoundingVolume<3> for &Solid {
fn aabb(self, geometry: &Geometry) -> Option<Aabb<3>> {
let mut aabb: Option<Aabb<3>> = None;
for shell in self.shells() {

View File

@ -47,7 +47,7 @@ impl Instance {
pub fn process_model<M>(&mut self, model: &M) -> Result
where
for<'r> (&'r M, Tolerance): Triangulate,
M: BoundingVolume<3>,
for<'r> &'r M: BoundingVolume<3>,
{
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())