From faf7876dc2d29897b17b0c89e3fb1075d0934087 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 20 Sep 2022 20:14:46 +0200 Subject: [PATCH] Simplify `Triangulate` trait Remove argument that isn't needed by all implementations. --- .../src/algorithms/triangulate/mod.rs | 33 +++++++------------ crates/fj-operations/src/shape_processor.rs | 2 +- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index e5f254128..5b9e39476 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -13,9 +13,9 @@ use super::approx::{face::FaceApprox, Approx, Tolerance}; /// Triangulate a shape pub trait Triangulate: Sized { /// Triangulate the shape - fn triangulate(self, tolerance: impl Into) -> Mesh> { + fn triangulate(self) -> Mesh> { let mut mesh = Mesh::new(); - self.triangulate_into_mesh(tolerance, &mut mesh); + self.triangulate_into_mesh(&mut mesh); mesh } @@ -23,38 +23,27 @@ pub trait Triangulate: Sized { /// /// This is a low-level method, intended for implementation of /// `Triangulate`. Most callers should prefer [`Triangulate::triangulate`]. - fn triangulate_into_mesh( - self, - tolerance: impl Into, - mesh: &mut Mesh>, - ); + fn triangulate_into_mesh(self, mesh: &mut Mesh>); } -impl Triangulate for T +impl Triangulate for (T, Tolerance) where T: Approx, T::Approximation: IntoIterator, { - fn triangulate_into_mesh( - self, - tolerance: impl Into, - mesh: &mut Mesh>, - ) { - let tolerance = tolerance.into(); - let approx = self.approx(tolerance); + fn triangulate_into_mesh(self, mesh: &mut Mesh>) { + let (approx, tolerance) = self; + + let approx = approx.approx(tolerance); for approx in approx { - approx.triangulate_into_mesh(tolerance, mesh); + approx.triangulate_into_mesh(mesh); } } } impl Triangulate for FaceApprox { - fn triangulate_into_mesh( - self, - _: impl Into, - mesh: &mut Mesh>, - ) { + fn triangulate_into_mesh(self, mesh: &mut Mesh>) { let points: Vec<_> = self .points() .into_iter() @@ -221,6 +210,6 @@ mod tests { fn triangulate(face: impl Into) -> anyhow::Result>> { let tolerance = Tolerance::from_scalar(Scalar::ONE)?; - Ok(face.into().approx(tolerance).triangulate(tolerance)) + Ok(face.into().approx(tolerance).triangulate()) } } diff --git a/crates/fj-operations/src/shape_processor.rs b/crates/fj-operations/src/shape_processor.rs index 9a86e38d5..e66f89bd3 100644 --- a/crates/fj-operations/src/shape_processor.rs +++ b/crates/fj-operations/src/shape_processor.rs @@ -46,7 +46,7 @@ impl ShapeProcessor { let stores = Stores::new(); let mut debug_info = DebugInfo::new(); let shape = shape.compute_brep(&config, &stores, &mut debug_info)?; - let mesh = shape.into_inner().triangulate(tolerance); + let mesh = (&shape.into_inner(), tolerance).triangulate(); Ok(ProcessedShape { aabb,