From 8b1ecfe95f9c5cd7eae89ec14926388017ca6b2e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 28 Jun 2022 15:23:45 +0200 Subject: [PATCH] Return `Vec` from `ToShape::to_shape` --- crates/fj-operations/src/circle.rs | 18 ++++++++++-------- crates/fj-operations/src/difference_2d.rs | 6 +++--- crates/fj-operations/src/group.rs | 10 +++++----- crates/fj-operations/src/lib.rs | 6 +++--- crates/fj-operations/src/shape_processor.rs | 8 ++------ crates/fj-operations/src/sketch.rs | 9 +++++---- crates/fj-operations/src/sweep.rs | 15 ++++----------- crates/fj-operations/src/transform.rs | 13 +++---------- 8 files changed, 35 insertions(+), 50 deletions(-) diff --git a/crates/fj-operations/src/circle.rs b/crates/fj-operations/src/circle.rs index f80703a16..38526d92e 100644 --- a/crates/fj-operations/src/circle.rs +++ b/crates/fj-operations/src/circle.rs @@ -15,7 +15,7 @@ impl ToShape for fj::Circle { config: &ValidationConfig, _: Tolerance, _: &mut DebugInfo, - ) -> Result, ValidationError> { + ) -> Result>, ValidationError> { let mut shape = Shape::new(); // Circles have just a single round edge with no vertices. So none need @@ -30,14 +30,16 @@ impl ToShape for fj::Circle { let cycle_canonical = shape.insert(Cycle::new(vec![edge.canonical()])); let surface = shape.insert(Surface::xy_plane()); - shape.insert(Face::new( - surface, - vec![LocalForm::new(cycle_local, cycle_canonical)], - Vec::new(), - self.color(), - )); + let face = shape + .insert(Face::new( + surface, + vec![LocalForm::new(cycle_local, cycle_canonical)], + Vec::new(), + self.color(), + )) + .get(); - let shape = validate(shape, config)?; + let shape = validate(vec![face], config)?; Ok(shape) } diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 99ccda653..7837d9e36 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -16,11 +16,11 @@ impl ToShape for fj::Difference2d { config: &ValidationConfig, tolerance: Tolerance, debug_info: &mut DebugInfo, - ) -> Result, ValidationError> { + ) -> Result>, ValidationError> { // This method assumes that `b` is fully contained within `a`: // https://github.com/hannobraun/Fornjot/issues/92 - let mut difference = Shape::new(); + let mut difference = Vec::new(); let mut exteriors = Vec::new(); let mut interiors = Vec::new(); @@ -72,7 +72,7 @@ impl ToShape for fj::Difference2d { } } - difference.merge(Face::new( + difference.push(Face::new( surface, exteriors, interiors, diff --git a/crates/fj-operations/src/group.rs b/crates/fj-operations/src/group.rs index 560584cd7..ac7a55c98 100644 --- a/crates/fj-operations/src/group.rs +++ b/crates/fj-operations/src/group.rs @@ -1,7 +1,7 @@ use fj_interop::debug::DebugInfo; use fj_kernel::{ algorithms::Tolerance, - shape::Shape, + objects::Face, validation::{validate, Validated, ValidationConfig, ValidationError}, }; use fj_math::Aabb; @@ -14,14 +14,14 @@ impl ToShape for fj::Group { config: &ValidationConfig, tolerance: Tolerance, debug_info: &mut DebugInfo, - ) -> Result, ValidationError> { - let mut shape = Shape::new(); + ) -> Result>, ValidationError> { + let mut shape = Vec::new(); let a = self.a.to_shape(config, tolerance, debug_info)?; let b = self.b.to_shape(config, tolerance, debug_info)?; - shape.merge_shape(&a); - shape.merge_shape(&b); + shape.extend(a.into_inner()); + shape.extend(b.into_inner()); let shape = validate(shape, config)?; diff --git a/crates/fj-operations/src/lib.rs b/crates/fj-operations/src/lib.rs index f8836bf30..bcd294fd8 100644 --- a/crates/fj-operations/src/lib.rs +++ b/crates/fj-operations/src/lib.rs @@ -28,7 +28,7 @@ mod transform; use fj_interop::debug::DebugInfo; use fj_kernel::{ algorithms::Tolerance, - shape::Shape, + objects::Face, validation::{Validated, ValidationConfig, ValidationError}, }; use fj_math::Aabb; @@ -41,7 +41,7 @@ pub trait ToShape { config: &ValidationConfig, tolerance: Tolerance, debug_info: &mut DebugInfo, - ) -> Result, ValidationError>; + ) -> Result>, ValidationError>; /// Access the axis-aligned bounding box of a shape /// @@ -94,6 +94,6 @@ dispatch! { config: &ValidationConfig, tolerance: Tolerance, debug_info: &mut DebugInfo, - ) -> Result, ValidationError>; + ) -> Result>, ValidationError>; bounding_volume() -> Aabb<3>; } diff --git a/crates/fj-operations/src/shape_processor.rs b/crates/fj-operations/src/shape_processor.rs index c17e052fe..de2d67c82 100644 --- a/crates/fj-operations/src/shape_processor.rs +++ b/crates/fj-operations/src/shape_processor.rs @@ -3,7 +3,6 @@ use fj_interop::{debug::DebugInfo, mesh::Mesh}; use fj_kernel::{ algorithms::{triangulate, InvalidTolerance, Tolerance}, - iter::ObjectIters, validation::{ValidationConfig, ValidationError}, }; use fj_math::{Aabb, Point, Scalar}; @@ -41,11 +40,8 @@ impl ShapeProcessor { let config = ValidationConfig::default(); let mut debug_info = DebugInfo::new(); - let shape = shape - .to_shape(&config, tolerance, &mut debug_info)? - .face_iter() - .collect(); - let mesh = triangulate(shape, tolerance, &mut debug_info); + let shape = shape.to_shape(&config, tolerance, &mut debug_info)?; + let mesh = triangulate(shape.into_inner(), tolerance, &mut debug_info); Ok(ProcessedShape { aabb, diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 772873fa8..0c26e061b 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -15,18 +15,19 @@ impl ToShape for fj::Sketch { config: &ValidationConfig, _: Tolerance, _: &mut DebugInfo, - ) -> Result, ValidationError> { + ) -> Result>, ValidationError> { let mut shape = Shape::new(); let surface = Surface::xy_plane(); let points = self.to_points().into_iter().map(Point::from); - Face::builder(surface, &mut shape) + let sketch = Face::builder(surface, &mut shape) .with_exterior_polygon(points) .with_color(self.color()) - .build(); + .build() + .get(); - let shape = validate(shape, config)?; + let shape = validate(vec![sketch], config)?; Ok(shape) } diff --git a/crates/fj-operations/src/sweep.rs b/crates/fj-operations/src/sweep.rs index 90c3bd915..cbfe53d65 100644 --- a/crates/fj-operations/src/sweep.rs +++ b/crates/fj-operations/src/sweep.rs @@ -1,8 +1,7 @@ use fj_interop::debug::DebugInfo; use fj_kernel::{ algorithms::{sweep, Tolerance}, - iter::ObjectIters, - shape::Shape, + objects::Face, validation::{validate, Validated, ValidationConfig, ValidationError}, }; use fj_math::{Aabb, Vector}; @@ -15,20 +14,14 @@ impl ToShape for fj::Sweep { config: &ValidationConfig, tolerance: Tolerance, debug_info: &mut DebugInfo, - ) -> Result, ValidationError> { + ) -> Result>, ValidationError> { let shape = self.shape().to_shape(config, tolerance, debug_info)?; let path = Vector::from(self.path()); let color = self.shape().color(); - let shape = shape.face_iter().collect::>(); - let swept = sweep(shape, path, tolerance, color); + let swept = sweep(shape.into_inner(), path, tolerance, color); - let mut shape = Shape::new(); - for face in swept { - shape.merge(face); - } - - let swept = validate(shape, config)?; + let swept = validate(swept, config)?; Ok(swept) } diff --git a/crates/fj-operations/src/transform.rs b/crates/fj-operations/src/transform.rs index 39eb98380..c3050ddbc 100644 --- a/crates/fj-operations/src/transform.rs +++ b/crates/fj-operations/src/transform.rs @@ -1,8 +1,7 @@ use fj_interop::debug::DebugInfo; use fj_kernel::{ algorithms::{transform, Tolerance}, - iter::ObjectIters, - shape::Shape, + objects::Face, validation::{validate, Validated, ValidationConfig, ValidationError}, }; use fj_math::{Aabb, Transform, Vector}; @@ -15,19 +14,13 @@ impl ToShape for fj::Transform { config: &ValidationConfig, tolerance: Tolerance, debug_info: &mut DebugInfo, - ) -> Result, ValidationError> { + ) -> Result>, ValidationError> { let shape = self.shape.to_shape(config, tolerance, debug_info)?; let shape = shape.into_inner(); - let shape = shape.face_iter().collect::>(); let faces = transform(&shape, &make_transform(self)); - let mut target = Shape::new(); - for face in faces { - target.merge(face); - } - - let shape = validate(target, config)?; + let shape = validate(faces, config)?; Ok(shape) }