From b483a5dd4a72f7d24ce818631dedb3f3c162e592 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 21 Mar 2022 17:24:54 +0100 Subject: [PATCH] Convert `Topology::triangles` into free function --- fj-app/src/main.rs | 11 +++++++---- fj-kernel/src/algorithms/mod.rs | 5 +++-- fj-kernel/src/algorithms/triangulation.rs | 17 +++++++++++++++-- fj-kernel/src/shape/topology.rs | 15 +-------------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/fj-app/src/main.rs b/fj-app/src/main.rs index cfbf2aee7..910805161 100644 --- a/fj-app/src/main.rs +++ b/fj-app/src/main.rs @@ -11,6 +11,7 @@ use std::{collections::HashMap, time::Instant}; use fj_debug::DebugInfo; use fj_host::Model; +use fj_kernel::algorithms::triangulate; use fj_math::{Aabb, Scalar, Triangle}; use fj_operations::ToShape as _; use futures::executor::block_on; @@ -296,10 +297,12 @@ impl ShapeProcessor { let mut debug_info = DebugInfo::new(); let mut triangles = Vec::new(); - shape - .to_shape(tolerance, &mut debug_info) - .topology() - .triangles(tolerance, &mut triangles, &mut debug_info); + triangulate( + shape.to_shape(tolerance, &mut debug_info), + tolerance, + &mut triangles, + &mut debug_info, + ); ProcessedShape { aabb, diff --git a/fj-kernel/src/algorithms/mod.rs b/fj-kernel/src/algorithms/mod.rs index c8d22fa98..5c2298dbb 100644 --- a/fj-kernel/src/algorithms/mod.rs +++ b/fj-kernel/src/algorithms/mod.rs @@ -8,6 +8,7 @@ mod sweep; mod triangulation; pub use self::{ - approximation::Approximation, sweep::sweep_shape, - triangulation::delaunay, + approximation::Approximation, + sweep::sweep_shape, + triangulation::{delaunay, triangulate}, }; diff --git a/fj-kernel/src/algorithms/triangulation.rs b/fj-kernel/src/algorithms/triangulation.rs index d288edfae..4e055a627 100644 --- a/fj-kernel/src/algorithms/triangulation.rs +++ b/fj-kernel/src/algorithms/triangulation.rs @@ -1,8 +1,21 @@ -use fj_math::Scalar; +use fj_debug::DebugInfo; +use fj_math::{Scalar, Triangle}; use parry2d_f64::utils::point_in_triangle::{corner_direction, Orientation}; use spade::HasPosition; -use crate::geometry; +use crate::{geometry, shape::Shape}; + +/// Triangulate a shape +pub fn triangulate( + mut shape: Shape, + tolerance: Scalar, + out: &mut Vec>, + debug_info: &mut DebugInfo, +) { + for face in shape.topology().faces() { + face.get().triangles(tolerance, out, debug_info); + } +} /// Create a Delaunay triangulation of all points pub fn delaunay( diff --git a/fj-kernel/src/shape/topology.rs b/fj-kernel/src/shape/topology.rs index 46cb5cc94..6f1866994 100644 --- a/fj-kernel/src/shape/topology.rs +++ b/fj-kernel/src/shape/topology.rs @@ -1,7 +1,6 @@ use std::collections::HashSet; -use fj_debug::DebugInfo; -use fj_math::{Point, Scalar, Triangle, Vector}; +use fj_math::{Point, Scalar, Vector}; use crate::{ geometry::{Circle, Curve, Line}, @@ -238,18 +237,6 @@ impl Topology<'_> { pub fn faces(&self) -> Iter { Iter::new(self.geometry.faces) } - - /// Triangulate the shape - pub fn triangles( - &self, - tolerance: Scalar, - out: &mut Vec>, - debug_info: &mut DebugInfo, - ) { - for face in &*self.geometry.faces { - face.get().triangles(tolerance, out, debug_info); - } - } } #[cfg(test)]