mirror of
https://github.com/hannobraun/Fornjot
synced 2025-11-22 23:42:12 +00:00
Merge pull request #2298 from hannobraun/geometry
Make some cleanups in `BoundingVolume` code
This commit is contained in:
commit
54eef7687c
@ -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)));
|
||||
}
|
||||
|
||||
|
||||
@ -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());
|
||||
|
||||
|
||||
@ -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))
|
||||
@ -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>>;
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user