diff --git a/crates/fj-kernel/src/algorithms/transform.rs b/crates/fj-kernel/src/algorithms/transform.rs index 233b2e429..11e11683f 100644 --- a/crates/fj-kernel/src/algorithms/transform.rs +++ b/crates/fj-kernel/src/algorithms/transform.rs @@ -3,8 +3,8 @@ use fj_math::{Transform, Vector}; use crate::objects::{ - Curve, Cycle, Edge, Face, GlobalCurve, GlobalVertex, Shell, Sketch, Solid, - Surface, SurfaceVertex, Vertex, + Curve, Cycle, Edge, Face, Faces, GlobalCurve, GlobalVertex, Shell, Sketch, + Solid, Surface, SurfaceVertex, Vertex, }; /// Transform an object @@ -90,6 +90,14 @@ impl TransformObject for Face { } } +impl TransformObject for Faces { + fn transform(self, transform: &Transform) -> Self { + let mut faces = Faces::new(); + faces.extend(self.into_iter().map(|face| face.transform(transform))); + faces + } +} + impl TransformObject for GlobalCurve { fn transform(self, transform: &Transform) -> Self { let kind = self.kind().transform(transform); @@ -162,13 +170,6 @@ impl TransformObject for Vertex { } } -/// Transform a shape -pub fn transform_faces(faces: &mut Vec, transform: &Transform) { - for face in faces { - *face = face.clone().transform(transform); - } -} - fn transform_cycles<'a>( cycles: impl IntoIterator + 'a, transform: &'a Transform, diff --git a/crates/fj-operations/src/group.rs b/crates/fj-operations/src/group.rs index 03e465533..b4c441855 100644 --- a/crates/fj-operations/src/group.rs +++ b/crates/fj-operations/src/group.rs @@ -4,14 +4,14 @@ use fj_kernel::{ approx::Tolerance, validate::{Validate, Validated, ValidationConfig, ValidationError}, }, - objects::Face, + objects::Faces, }; use fj_math::Aabb; use super::Shape; impl Shape for fj::Group { - type Brep = Vec; + type Brep = Faces; fn compute_brep( &self, @@ -19,7 +19,7 @@ impl Shape for fj::Group { tolerance: Tolerance, debug_info: &mut DebugInfo, ) -> Result, ValidationError> { - let mut faces = Vec::new(); + let mut faces = Faces::new(); let a = self.a.compute_brep(config, tolerance, debug_info)?; let b = self.b.compute_brep(config, tolerance, debug_info)?; diff --git a/crates/fj-operations/src/lib.rs b/crates/fj-operations/src/lib.rs index 7fcbff25a..8e1783d5b 100644 --- a/crates/fj-operations/src/lib.rs +++ b/crates/fj-operations/src/lib.rs @@ -30,7 +30,7 @@ use fj_kernel::{ approx::Tolerance, validate::{Validate, Validated, ValidationConfig, ValidationError}, }, - objects::{Face, Sketch}, + objects::{Faces, Sketch}, }; use fj_math::Aabb; @@ -55,7 +55,7 @@ pub trait Shape { } impl Shape for fj::Shape { - type Brep = Vec; + type Brep = Faces; fn compute_brep( &self, @@ -68,8 +68,6 @@ impl Shape for fj::Shape { .compute_brep(config, tolerance, debug_info)? .into_inner() .into_faces() - .into_iter() - .collect::>() .validate_with_config(config), Self::Group(shape) => { shape.compute_brep(config, tolerance, debug_info) @@ -78,8 +76,12 @@ impl Shape for fj::Shape { .compute_brep(config, tolerance, debug_info)? .into_inner() .into_shells() - .flat_map(|shell| shell.into_faces()) - .collect::>() + .map(|shell| shell.into_faces()) + .reduce(|mut a, b| { + a.extend(b); + a + }) + .unwrap_or_default() .validate_with_config(config), Self::Transform(shape) => { shape.compute_brep(config, tolerance, debug_info) diff --git a/crates/fj-operations/src/transform.rs b/crates/fj-operations/src/transform.rs index c3a118572..8175c1d0d 100644 --- a/crates/fj-operations/src/transform.rs +++ b/crates/fj-operations/src/transform.rs @@ -2,17 +2,17 @@ use fj_interop::debug::DebugInfo; use fj_kernel::{ algorithms::{ approx::Tolerance, - transform::transform_faces, + transform::TransformObject, validate::{Validate, Validated, ValidationConfig, ValidationError}, }, - objects::Face, + objects::Faces, }; use fj_math::{Aabb, Transform, Vector}; use super::Shape; impl Shape for fj::Transform { - type Brep = Vec; + type Brep = Faces; fn compute_brep( &self, @@ -20,12 +20,11 @@ impl Shape for fj::Transform { tolerance: Tolerance, debug_info: &mut DebugInfo, ) -> Result, ValidationError> { - let mut faces = self + let faces = self .shape .compute_brep(config, tolerance, debug_info)? - .into_inner(); - - transform_faces(&mut faces, &make_transform(self)); + .into_inner() + .transform(&make_transform(self)); faces.validate_with_config(config) }