From 35a226ab6e58ade4d926e8148afb60f5fc2999c6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 01/28] Take full `Services` in `Shape::compute_brep` --- crates/fj-operations/src/difference_2d.rs | 19 +++++++------ crates/fj-operations/src/group.rs | 11 +++----- crates/fj-operations/src/lib.rs | 22 +++++++-------- crates/fj-operations/src/shape_processor.rs | 2 +- crates/fj-operations/src/sketch.rs | 30 +++++++++++++-------- crates/fj-operations/src/sweep.rs | 14 +++++----- crates/fj-operations/src/transform.rs | 11 ++++---- 7 files changed, 57 insertions(+), 52 deletions(-) diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 7fd07ff5f..79835487f 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -3,9 +3,9 @@ use std::ops::Deref; use fj_interop::{debug::DebugInfo, ext::ArrayExt, mesh::Color}; use fj_kernel::{ algorithms::reverse::Reverse, - objects::{Face, Objects, Sketch}, + objects::{Face, Sketch}, operations::Insert, - services::Service, + services::Services, }; use fj_math::Aabb; @@ -16,7 +16,7 @@ impl Shape for fj::Difference2d { fn compute_brep( &self, - objects: &mut Service, + services: &mut Services, debug_info: &mut DebugInfo, ) -> Self::Brep { // This method assumes that `b` is fully contained within `a`: @@ -30,7 +30,7 @@ impl Shape for fj::Difference2d { let [a, b] = self .shapes() .each_ref_ext() - .map(|shape| shape.compute_brep(objects, debug_info)); + .map(|shape| shape.compute_brep(services, debug_info)); if let Some(face) = a.faces().into_iter().next() { // If there's at least one face to subtract from, we can proceed. @@ -46,7 +46,8 @@ impl Shape for fj::Difference2d { exteriors.push(face.exterior().clone()); for cycle in face.interiors() { - interiors.push(cycle.clone().reverse(objects)); + interiors + .push(cycle.clone().reverse(&mut services.objects)); } } @@ -57,7 +58,9 @@ impl Shape for fj::Difference2d { "Trying to subtract faces with different surfaces.", ); - interiors.push(face.exterior().clone().reverse(objects)); + interiors.push( + face.exterior().clone().reverse(&mut services.objects), + ); } // Faces only support one exterior, while the code here comes from @@ -83,10 +86,10 @@ impl Shape for fj::Difference2d { interiors, Some(Color(self.color())), ); - faces.push(face.insert(objects)); + faces.push(face.insert(&mut services.objects)); } - let difference = Sketch::new(faces).insert(objects); + let difference = Sketch::new(faces).insert(&mut services.objects); difference.deref().clone() } diff --git a/crates/fj-operations/src/group.rs b/crates/fj-operations/src/group.rs index a91d2dd57..7b4e997f5 100644 --- a/crates/fj-operations/src/group.rs +++ b/crates/fj-operations/src/group.rs @@ -1,8 +1,5 @@ use fj_interop::debug::DebugInfo; -use fj_kernel::{ - objects::{FaceSet, Objects}, - services::Service, -}; +use fj_kernel::{objects::FaceSet, services::Services}; use fj_math::Aabb; use super::Shape; @@ -12,13 +9,13 @@ impl Shape for fj::Group { fn compute_brep( &self, - objects: &mut Service, + services: &mut Services, debug_info: &mut DebugInfo, ) -> Self::Brep { let mut faces = FaceSet::new(); - let a = self.a.compute_brep(objects, debug_info); - let b = self.b.compute_brep(objects, debug_info); + let a = self.a.compute_brep(services, debug_info); + let b = self.b.compute_brep(services, debug_info); faces.extend(a); faces.extend(b); diff --git a/crates/fj-operations/src/lib.rs b/crates/fj-operations/src/lib.rs index c266838f5..df6483338 100644 --- a/crates/fj-operations/src/lib.rs +++ b/crates/fj-operations/src/lib.rs @@ -26,8 +26,8 @@ mod transform; use fj_interop::debug::DebugInfo; use fj_kernel::{ - objects::{FaceSet, Objects, Sketch}, - services::Service, + objects::{FaceSet, Sketch}, + services::Services, }; use fj_math::Aabb; @@ -39,7 +39,7 @@ pub trait Shape { /// Compute the boundary representation of the shape fn compute_brep( &self, - objects: &mut Service, + services: &mut Services, debug_info: &mut DebugInfo, ) -> Self::Brep; @@ -55,16 +55,16 @@ impl Shape for fj::Shape { fn compute_brep( &self, - objects: &mut Service, + services: &mut Services, debug_info: &mut DebugInfo, ) -> Self::Brep { match self { Self::Shape2d(shape) => { - shape.compute_brep(objects, debug_info).faces().clone() + shape.compute_brep(services, debug_info).faces().clone() } - Self::Group(shape) => shape.compute_brep(objects, debug_info), + Self::Group(shape) => shape.compute_brep(services, debug_info), Self::Sweep(shape) => shape - .compute_brep(objects, debug_info) + .compute_brep(services, debug_info) .shells() .map(|shell| shell.faces().clone()) .reduce(|mut a, b| { @@ -72,7 +72,7 @@ impl Shape for fj::Shape { a }) .unwrap_or_default(), - Self::Transform(shape) => shape.compute_brep(objects, debug_info), + Self::Transform(shape) => shape.compute_brep(services, debug_info), } } @@ -91,12 +91,12 @@ impl Shape for fj::Shape2d { fn compute_brep( &self, - objects: &mut Service, + services: &mut Services, debug_info: &mut DebugInfo, ) -> Self::Brep { match self { - Self::Difference(shape) => shape.compute_brep(objects, debug_info), - Self::Sketch(shape) => shape.compute_brep(objects, debug_info), + Self::Difference(shape) => shape.compute_brep(services, debug_info), + Self::Sketch(shape) => shape.compute_brep(services, debug_info), } } diff --git a/crates/fj-operations/src/shape_processor.rs b/crates/fj-operations/src/shape_processor.rs index 28fc2e4c9..6b7a451ea 100644 --- a/crates/fj-operations/src/shape_processor.rs +++ b/crates/fj-operations/src/shape_processor.rs @@ -44,7 +44,7 @@ impl ShapeProcessor { let mut services = Services::new(); let mut debug_info = DebugInfo::new(); - let shape = shape.compute_brep(&mut services.objects, &mut debug_info); + let shape = shape.compute_brep(&mut services, &mut debug_info); let mesh = (&shape, tolerance).triangulate(); Ok(ProcessedShape { diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 4e03865b0..aade3cb5b 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -2,9 +2,9 @@ use std::ops::Deref; use fj_interop::{debug::DebugInfo, mesh::Color}; use fj_kernel::{ - objects::{Cycle, Face, HalfEdge, Objects, Sketch}, + objects::{Cycle, Face, HalfEdge, Sketch}, operations::{BuildCycle, BuildHalfEdge, Insert, UpdateCycle}, - services::Service, + services::Services, }; use fj_math::{Aabb, Point}; use itertools::Itertools; @@ -16,16 +16,18 @@ impl Shape for fj::Sketch { fn compute_brep( &self, - objects: &mut Service, + services: &mut Services, _: &mut DebugInfo, ) -> Self::Brep { - let surface = objects.surfaces.xy_plane(); + let surface = services.objects.surfaces.xy_plane(); let face = match self.chain() { fj::Chain::Circle(circle) => { let half_edge = - HalfEdge::circle(circle.radius(), objects).insert(objects); - let exterior = Cycle::new([half_edge]).insert(objects); + HalfEdge::circle(circle.radius(), &mut services.objects) + .insert(&mut services.objects); + let exterior = + Cycle::new([half_edge]).insert(&mut services.objects); Face::new( surface, @@ -59,19 +61,24 @@ impl Shape for fj::Sketch { HalfEdge::line_segment( [start, end], None, - objects, + &mut services.objects, ) } fj::SketchSegmentRoute::Arc { angle } => { - HalfEdge::arc(start, end, angle.rad(), objects) + HalfEdge::arc( + start, + end, + angle.rad(), + &mut services.objects, + ) } }; - let half_edge = half_edge.insert(objects); + let half_edge = half_edge.insert(&mut services.objects); cycle = cycle.add_half_edges([half_edge]); } - cycle.insert(objects) + cycle.insert(&mut services.objects) }; Face::new( @@ -83,7 +90,8 @@ impl Shape for fj::Sketch { } }; - let sketch = Sketch::new(vec![face.insert(objects)]).insert(objects); + let sketch = Sketch::new(vec![face.insert(&mut services.objects)]) + .insert(&mut services.objects); sketch.deref().clone() } diff --git a/crates/fj-operations/src/sweep.rs b/crates/fj-operations/src/sweep.rs index 21ccf566e..aada3088d 100644 --- a/crates/fj-operations/src/sweep.rs +++ b/crates/fj-operations/src/sweep.rs @@ -2,10 +2,8 @@ use std::ops::Deref; use fj_interop::debug::DebugInfo; use fj_kernel::{ - algorithms::sweep::Sweep, - objects::{Objects, Solid}, - operations::Insert, - services::Service, + algorithms::sweep::Sweep, objects::Solid, operations::Insert, + services::Services, }; use fj_math::{Aabb, Vector}; @@ -16,15 +14,15 @@ impl Shape for fj::Sweep { fn compute_brep( &self, - objects: &mut Service, + services: &mut Services, debug_info: &mut DebugInfo, ) -> Self::Brep { - let sketch = self.shape().compute_brep(objects, debug_info); - let sketch = sketch.insert(objects); + let sketch = self.shape().compute_brep(services, debug_info); + let sketch = sketch.insert(&mut services.objects); let path = Vector::from(self.path()); - let solid = sketch.sweep(path, objects); + let solid = sketch.sweep(path, &mut services.objects); solid.deref().clone() } diff --git a/crates/fj-operations/src/transform.rs b/crates/fj-operations/src/transform.rs index 48890ee77..d75dbe947 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::TransformObject, - objects::{FaceSet, Objects}, - services::Service, + algorithms::transform::TransformObject, objects::FaceSet, + services::Services, }; use fj_math::{Aabb, Transform, Vector}; @@ -13,12 +12,12 @@ impl Shape for fj::Transform { fn compute_brep( &self, - objects: &mut Service, + services: &mut Services, debug_info: &mut DebugInfo, ) -> Self::Brep { self.shape - .compute_brep(objects, debug_info) - .transform(&make_transform(self), objects) + .compute_brep(services, debug_info) + .transform(&make_transform(self), &mut services.objects) } fn bounding_volume(&self) -> Aabb<3> { From b5934813f5941d60275a9603063d29cfb82e5362 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 02/28] Take full `Services` in `Sweep::sweep` --- crates/fj-kernel/src/algorithms/sweep/mod.rs | 6 +++--- crates/fj-operations/src/sweep.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/mod.rs b/crates/fj-kernel/src/algorithms/sweep/mod.rs index 6cdc14430..2e34aa352 100644 --- a/crates/fj-kernel/src/algorithms/sweep/mod.rs +++ b/crates/fj-kernel/src/algorithms/sweep/mod.rs @@ -12,7 +12,7 @@ use fj_math::Vector; use crate::{ objects::{GlobalEdge, Objects, Vertex}, - services::Service, + services::{Service, Services}, storage::{Handle, ObjectId}, }; @@ -25,10 +25,10 @@ pub trait Sweep: Sized { fn sweep( self, path: impl Into>, - objects: &mut Service, + services: &mut Services, ) -> Self::Swept { let mut cache = SweepCache::default(); - self.sweep_with_cache(path, &mut cache, objects) + self.sweep_with_cache(path, &mut cache, &mut services.objects) } /// Sweep the object along the given path, using the provided cache diff --git a/crates/fj-operations/src/sweep.rs b/crates/fj-operations/src/sweep.rs index aada3088d..3cd5190b1 100644 --- a/crates/fj-operations/src/sweep.rs +++ b/crates/fj-operations/src/sweep.rs @@ -22,7 +22,7 @@ impl Shape for fj::Sweep { let path = Vector::from(self.path()); - let solid = sketch.sweep(path, &mut services.objects); + let solid = sketch.sweep(path, services); solid.deref().clone() } From dd223fc33c52cad4cf51916a2c3f5f3772dd36f5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:33:55 +0200 Subject: [PATCH 03/28] Inline redundant variable --- crates/fj-operations/src/sweep.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/fj-operations/src/sweep.rs b/crates/fj-operations/src/sweep.rs index 3cd5190b1..701617bd9 100644 --- a/crates/fj-operations/src/sweep.rs +++ b/crates/fj-operations/src/sweep.rs @@ -17,8 +17,10 @@ impl Shape for fj::Sweep { services: &mut Services, debug_info: &mut DebugInfo, ) -> Self::Brep { - let sketch = self.shape().compute_brep(services, debug_info); - let sketch = sketch.insert(&mut services.objects); + let sketch = self + .shape() + .compute_brep(services, debug_info) + .insert(&mut services.objects); let path = Vector::from(self.path()); From 679cc9cf472279897bc280af8c035733fd5a4121 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 04/28] Take full `Services` in `Sweep::sweep_with_cache` --- .../fj-kernel/src/algorithms/sweep/curve.rs | 9 ++--- crates/fj-kernel/src/algorithms/sweep/edge.rs | 20 +++++------ crates/fj-kernel/src/algorithms/sweep/face.rs | 33 +++++++++++-------- crates/fj-kernel/src/algorithms/sweep/mod.rs | 8 ++--- .../fj-kernel/src/algorithms/sweep/sketch.rs | 10 +++--- .../fj-kernel/src/algorithms/sweep/vertex.rs | 10 +++--- 6 files changed, 48 insertions(+), 42 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/curve.rs b/crates/fj-kernel/src/algorithms/sweep/curve.rs index 31cf95793..94cb55c89 100644 --- a/crates/fj-kernel/src/algorithms/sweep/curve.rs +++ b/crates/fj-kernel/src/algorithms/sweep/curve.rs @@ -5,9 +5,9 @@ use crate::{ curve::{Curve, GlobalPath}, surface::SurfaceGeometry, }, - objects::{Objects, Surface}, + objects::Surface, operations::Insert, - services::Service, + services::Services, storage::Handle, }; @@ -20,7 +20,7 @@ impl Sweep for (Curve, &Surface) { self, path: impl Into>, _: &mut SweepCache, - objects: &mut Service, + services: &mut Services, ) -> Self::Swept { let (curve, surface) = self; @@ -75,6 +75,7 @@ impl Sweep for (Curve, &Surface) { } }; - Surface::new(SurfaceGeometry { u, v: path.into() }).insert(objects) + Surface::new(SurfaceGeometry { u, v: path.into() }) + .insert(&mut services.objects) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 7b785e5a8..21ad13664 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -2,9 +2,9 @@ use fj_interop::{ext::ArrayExt, mesh::Color}; use fj_math::{Point, Scalar, Vector}; use crate::{ - objects::{Cycle, Face, HalfEdge, Objects, Surface, Vertex}, + objects::{Cycle, Face, HalfEdge, Surface, Vertex}, operations::{BuildHalfEdge, Insert, UpdateCycle, UpdateHalfEdge}, - services::Service, + services::Services, storage::Handle, }; @@ -17,7 +17,7 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { self, path: impl Into>, cache: &mut SweepCache, - objects: &mut Service, + services: &mut Services, ) -> Self::Swept { let (edge, next_vertex, surface, color) = self; let path = path.into(); @@ -27,9 +27,9 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { let (vertices, global_edges) = { let [a, b] = [edge.start_vertex(), next_vertex].map(Clone::clone); let (edge_up, [_, c]) = - b.clone().sweep_with_cache(path, cache, objects); + b.clone().sweep_with_cache(path, cache, services); let (edge_down, [_, d]) = - a.clone().sweep_with_cache(path, cache, objects); + a.clone().sweep_with_cache(path, cache, services); ( [a, b, c, d], @@ -81,7 +81,7 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { let half_edge = HalfEdge::line_segment( [start, end], Some(boundary), - objects, + &mut services.objects, ) .replace_start_vertex(start_vertex); @@ -91,7 +91,7 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { half_edge }; - half_edge.insert(objects) + half_edge.insert(&mut services.objects) }; exterior = Some( @@ -105,15 +105,15 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { }); let face = Face::new( - (edge.curve(), surface).sweep_with_cache(path, cache, objects), - exterior.unwrap().insert(objects), + (edge.curve(), surface).sweep_with_cache(path, cache, services), + exterior.unwrap().insert(&mut services.objects), Vec::new(), color, ); // And we're done creating the face! All that's left to do is build our // return values. - let face = face.insert(objects); + let face = face.insert(&mut services.objects); (face, edge_top) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 26dddd24e..c29357dcc 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -7,9 +7,9 @@ use crate::{ algorithms::{reverse::Reverse, transform::TransformObject}, builder::CycleBuilder, geometry::curve::GlobalPath, - objects::{Face, Objects, Shell}, + objects::{Face, Shell}, operations::Insert, - services::Service, + services::Services, storage::Handle, }; @@ -22,7 +22,7 @@ impl Sweep for Handle { self, path: impl Into>, cache: &mut SweepCache, - objects: &mut Service, + services: &mut Services, ) -> Self::Swept { let path = path.into(); @@ -47,19 +47,21 @@ impl Sweep for Handle { if is_negative_sweep { self.clone() } else { - self.clone().reverse(objects) + self.clone().reverse(&mut services.objects) } }; faces.push(bottom_face.clone()); - let top_surface = - bottom_face.surface().clone().translate(path, objects); + let top_surface = bottom_face + .surface() + .clone() + .translate(path, &mut services.objects); let mut exterior = None; let mut interiors = Vec::new(); for (i, cycle) in bottom_face.all_cycles().cloned().enumerate() { - let cycle = cycle.reverse(objects); + let cycle = cycle.reverse(&mut services.objects); let mut top_edges = Vec::new(); for (half_edge, next) in @@ -71,7 +73,7 @@ impl Sweep for Handle { self.surface().deref(), self.color(), ) - .sweep_with_cache(path, cache, objects); + .sweep_with_cache(path, cache, services); faces.push(face); @@ -82,22 +84,25 @@ impl Sweep for Handle { )); } - let top_cycle = CycleBuilder::connect_to_edges(top_edges, objects) - .build(objects); + let top_cycle = CycleBuilder::connect_to_edges( + top_edges, + &mut services.objects, + ) + .build(&mut services.objects); if i == 0 { - exterior = Some(top_cycle.insert(objects)); + exterior = Some(top_cycle.insert(&mut services.objects)); } else { - interiors.push(top_cycle.insert(objects)); + interiors.push(top_cycle.insert(&mut services.objects)); }; } let top_face = Face::new(top_surface, exterior.unwrap(), interiors, self.color()); - let top_face = top_face.insert(objects); + let top_face = top_face.insert(&mut services.objects); faces.push(top_face); - Shell::new(faces).insert(objects) + Shell::new(faces).insert(&mut services.objects) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/mod.rs b/crates/fj-kernel/src/algorithms/sweep/mod.rs index 2e34aa352..bbb40e278 100644 --- a/crates/fj-kernel/src/algorithms/sweep/mod.rs +++ b/crates/fj-kernel/src/algorithms/sweep/mod.rs @@ -11,8 +11,8 @@ use std::collections::BTreeMap; use fj_math::Vector; use crate::{ - objects::{GlobalEdge, Objects, Vertex}, - services::{Service, Services}, + objects::{GlobalEdge, Vertex}, + services::Services, storage::{Handle, ObjectId}, }; @@ -28,7 +28,7 @@ pub trait Sweep: Sized { services: &mut Services, ) -> Self::Swept { let mut cache = SweepCache::default(); - self.sweep_with_cache(path, &mut cache, &mut services.objects) + self.sweep_with_cache(path, &mut cache, services) } /// Sweep the object along the given path, using the provided cache @@ -36,7 +36,7 @@ pub trait Sweep: Sized { self, path: impl Into>, cache: &mut SweepCache, - objects: &mut Service, + services: &mut Services, ) -> Self::Swept; } diff --git a/crates/fj-kernel/src/algorithms/sweep/sketch.rs b/crates/fj-kernel/src/algorithms/sweep/sketch.rs index 0ff2c6fe5..04d30da21 100644 --- a/crates/fj-kernel/src/algorithms/sweep/sketch.rs +++ b/crates/fj-kernel/src/algorithms/sweep/sketch.rs @@ -1,9 +1,9 @@ use fj_math::Vector; use crate::{ - objects::{Objects, Sketch, Solid}, + objects::{Sketch, Solid}, operations::Insert, - services::Service, + services::Services, storage::Handle, }; @@ -16,16 +16,16 @@ impl Sweep for Handle { self, path: impl Into>, cache: &mut SweepCache, - objects: &mut Service, + services: &mut Services, ) -> Self::Swept { let path = path.into(); let mut shells = Vec::new(); for face in self.faces().clone() { - let shell = face.sweep_with_cache(path, cache, objects); + let shell = face.sweep_with_cache(path, cache, services); shells.push(shell); } - Solid::new(shells).insert(objects) + Solid::new(shells).insert(&mut services.objects) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 44d98010b..66416410a 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -1,9 +1,9 @@ use fj_math::Vector; use crate::{ - objects::{GlobalEdge, Objects, Vertex}, + objects::{GlobalEdge, Vertex}, operations::Insert, - services::Service, + services::Services, storage::Handle, }; @@ -16,20 +16,20 @@ impl Sweep for Handle { self, _: impl Into>, cache: &mut SweepCache, - objects: &mut Service, + services: &mut Services, ) -> Self::Swept { let a = self.clone(); let b = cache .global_vertex .entry(self.id()) - .or_insert_with(|| Vertex::new().insert(objects)) + .or_insert_with(|| Vertex::new().insert(&mut services.objects)) .clone(); let vertices = [a, b]; let global_edge = cache .global_edge .entry(self.id()) - .or_insert_with(|| GlobalEdge::new().insert(objects)) + .or_insert_with(|| GlobalEdge::new().insert(&mut services.objects)) .clone(); // The vertices of the returned `GlobalEdge` are in normalized order, From 8397c133207e9d99d74339c0fde661cbde1ba068 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 05/28] Take full `Services` in `Reverse::reverse` --- crates/fj-kernel/src/algorithms/reverse/cycle.rs | 10 +++++----- crates/fj-kernel/src/algorithms/reverse/face.rs | 13 +++++-------- crates/fj-kernel/src/algorithms/reverse/mod.rs | 4 ++-- crates/fj-kernel/src/algorithms/sweep/face.rs | 4 ++-- crates/fj-kernel/src/validate/face.rs | 2 +- crates/fj-operations/src/difference_2d.rs | 7 ++----- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/reverse/cycle.rs b/crates/fj-kernel/src/algorithms/reverse/cycle.rs index 0a8338bf6..0a2025201 100644 --- a/crates/fj-kernel/src/algorithms/reverse/cycle.rs +++ b/crates/fj-kernel/src/algorithms/reverse/cycle.rs @@ -1,16 +1,16 @@ use itertools::Itertools; use crate::{ - objects::{Cycle, HalfEdge, Objects}, + objects::{Cycle, HalfEdge}, operations::Insert, - services::Service, + services::Services, storage::Handle, }; use super::Reverse; impl Reverse for Handle { - fn reverse(self, objects: &mut Service) -> Self { + fn reverse(self, services: &mut Services) -> Self { let mut edges = self .half_edges() .cloned() @@ -27,12 +27,12 @@ impl Reverse for Handle { next.start_vertex().clone(), current.global_form().clone(), ) - .insert(objects) + .insert(&mut services.objects) }) .collect::>(); edges.reverse(); - Cycle::new(edges).insert(objects) + Cycle::new(edges).insert(&mut services.objects) } } diff --git a/crates/fj-kernel/src/algorithms/reverse/face.rs b/crates/fj-kernel/src/algorithms/reverse/face.rs index 9d486855f..307df617d 100644 --- a/crates/fj-kernel/src/algorithms/reverse/face.rs +++ b/crates/fj-kernel/src/algorithms/reverse/face.rs @@ -1,21 +1,18 @@ use crate::{ - objects::{Face, Objects}, - operations::Insert, - services::Service, - storage::Handle, + objects::Face, operations::Insert, services::Services, storage::Handle, }; use super::Reverse; impl Reverse for Handle { - fn reverse(self, objects: &mut Service) -> Self { - let exterior = self.exterior().clone().reverse(objects); + fn reverse(self, services: &mut Services) -> Self { + let exterior = self.exterior().clone().reverse(services); let interiors = self .interiors() - .map(|cycle| cycle.clone().reverse(objects)) + .map(|cycle| cycle.clone().reverse(services)) .collect::>(); Face::new(self.surface().clone(), exterior, interiors, self.color()) - .insert(objects) + .insert(&mut services.objects) } } diff --git a/crates/fj-kernel/src/algorithms/reverse/mod.rs b/crates/fj-kernel/src/algorithms/reverse/mod.rs index a54fd71ee..76a1f74d9 100644 --- a/crates/fj-kernel/src/algorithms/reverse/mod.rs +++ b/crates/fj-kernel/src/algorithms/reverse/mod.rs @@ -1,6 +1,6 @@ //! Reverse the direction/orientation of objects -use crate::{objects::Objects, services::Service}; +use crate::services::Services; mod cycle; mod face; @@ -8,5 +8,5 @@ mod face; /// Reverse the direction/orientation of an object pub trait Reverse: Sized { /// Reverse the direction/orientation of the object - fn reverse(self, objects: &mut Service) -> Self; + fn reverse(self, services: &mut Services) -> Self; } diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index c29357dcc..90c010932 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -47,7 +47,7 @@ impl Sweep for Handle { if is_negative_sweep { self.clone() } else { - self.clone().reverse(&mut services.objects) + self.clone().reverse(services) } }; faces.push(bottom_face.clone()); @@ -61,7 +61,7 @@ impl Sweep for Handle { let mut interiors = Vec::new(); for (i, cycle) in bottom_face.all_cycles().cloned().enumerate() { - let cycle = cycle.reverse(&mut services.objects); + let cycle = cycle.reverse(services); let mut top_edges = Vec::new(); for (half_edge, next) in diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 1dc0c8be1..e637ed507 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -97,7 +97,7 @@ mod tests { let interiors = valid .interiors() .cloned() - .map(|cycle| cycle.reverse(&mut services.objects)) + .map(|cycle| cycle.reverse(&mut services)) .collect::>(); Face::new( diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 79835487f..4bf32f6a1 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -46,8 +46,7 @@ impl Shape for fj::Difference2d { exteriors.push(face.exterior().clone()); for cycle in face.interiors() { - interiors - .push(cycle.clone().reverse(&mut services.objects)); + interiors.push(cycle.clone().reverse(services)); } } @@ -58,9 +57,7 @@ impl Shape for fj::Difference2d { "Trying to subtract faces with different surfaces.", ); - interiors.push( - face.exterior().clone().reverse(&mut services.objects), - ); + interiors.push(face.exterior().clone().reverse(services)); } // Faces only support one exterior, while the code here comes from From 1a4b8cac0db243bbc41597bc059897dcfc412ba1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 06/28] Take full `Services` in `TransformObject::rotate` --- crates/fj-kernel/src/algorithms/transform/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/mod.rs b/crates/fj-kernel/src/algorithms/transform/mod.rs index e00d029bb..438f353bf 100644 --- a/crates/fj-kernel/src/algorithms/transform/mod.rs +++ b/crates/fj-kernel/src/algorithms/transform/mod.rs @@ -17,7 +17,7 @@ use type_map::TypeMap; use crate::{ objects::Objects, operations::Insert, - services::Service, + services::{Service, Services}, storage::{Handle, ObjectId}, }; @@ -66,9 +66,9 @@ pub trait TransformObject: Sized { fn rotate( self, axis_angle: impl Into>, - objects: &mut Service, + services: &mut Services, ) -> Self { - self.transform(&Transform::rotation(axis_angle), objects) + self.transform(&Transform::rotation(axis_angle), &mut services.objects) } } From 3f0636728d23152089e7bcabf99d4e6205d0b709 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 07/28] Take full `Services` in `translate` --- .../fj-kernel/src/algorithms/intersect/ray_face.rs | 12 ++++++------ crates/fj-kernel/src/algorithms/sweep/face.rs | 6 ++---- crates/fj-kernel/src/algorithms/transform/mod.rs | 4 ++-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index 837529f7e..4902d173c 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -168,7 +168,7 @@ mod tests { &mut services.objects, )) .build(&mut services.objects); - let face = face.translate([-1., 0., 0.], &mut services.objects); + let face = face.translate([-1., 0., 0.], &mut services); assert_eq!((&ray, &face).intersect(), None); } @@ -185,7 +185,7 @@ mod tests { &mut services.objects, )) .build(&mut services.objects); - let face = face.translate([1., 0., 0.], &mut services.objects); + let face = face.translate([1., 0., 0.], &mut services); assert_eq!( (&ray, &face).intersect(), @@ -205,7 +205,7 @@ mod tests { &mut services.objects, )) .build(&mut services.objects); - let face = face.translate([0., 0., 2.], &mut services.objects); + let face = face.translate([0., 0., 2.], &mut services); assert_eq!((&ray, &face).intersect(), None); } @@ -222,7 +222,7 @@ mod tests { &mut services.objects, )) .build(&mut services.objects); - let face = face.translate([1., 1., 0.], &mut services.objects); + let face = face.translate([1., 1., 0.], &mut services); let edge = face .exterior() @@ -247,7 +247,7 @@ mod tests { &mut services.objects, )) .build(&mut services.objects); - let face = face.translate([1., 1., 1.], &mut services.objects); + let face = face.translate([1., 1., 1.], &mut services); let vertex = face .exterior() @@ -294,7 +294,7 @@ mod tests { &mut services.objects, )) .build(&mut services.objects); - let face = face.translate([0., 0., 1.], &mut services.objects); + let face = face.translate([0., 0., 1.], &mut services); assert_eq!((&ray, &face).intersect(), None); } diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 90c010932..8a92c425b 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -52,10 +52,8 @@ impl Sweep for Handle { }; faces.push(bottom_face.clone()); - let top_surface = bottom_face - .surface() - .clone() - .translate(path, &mut services.objects); + let top_surface = + bottom_face.surface().clone().translate(path, services); let mut exterior = None; let mut interiors = Vec::new(); diff --git a/crates/fj-kernel/src/algorithms/transform/mod.rs b/crates/fj-kernel/src/algorithms/transform/mod.rs index 438f353bf..b72b59c03 100644 --- a/crates/fj-kernel/src/algorithms/transform/mod.rs +++ b/crates/fj-kernel/src/algorithms/transform/mod.rs @@ -55,9 +55,9 @@ pub trait TransformObject: Sized { fn translate( self, offset: impl Into>, - objects: &mut Service, + services: &mut Services, ) -> Self { - self.transform(&Transform::translation(offset), objects) + self.transform(&Transform::translation(offset), &mut services.objects) } /// Rotate the object From 35b3287d8759731b3f90024bc5a8732c7cf397ed Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 08/28] Take full `Services` in `transform` --- .../src/algorithms/intersect/surface_surface.rs | 2 +- crates/fj-kernel/src/algorithms/transform/mod.rs | 12 ++++-------- crates/fj-operations/src/transform.rs | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs index 5dfbef44b..77c9cb3ed 100644 --- a/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs +++ b/crates/fj-kernel/src/algorithms/intersect/surface_surface.rs @@ -94,7 +94,7 @@ mod tests { xy.clone(), xy.clone().transform( &Transform::translation([0., 0., 1.],), - &mut services.objects + &mut services ) ],), None, diff --git a/crates/fj-kernel/src/algorithms/transform/mod.rs b/crates/fj-kernel/src/algorithms/transform/mod.rs index b72b59c03..511ce0d78 100644 --- a/crates/fj-kernel/src/algorithms/transform/mod.rs +++ b/crates/fj-kernel/src/algorithms/transform/mod.rs @@ -32,13 +32,9 @@ use crate::{ /// hasn't been done so far, is that no one has put in the work yet. pub trait TransformObject: Sized { /// Transform the object - fn transform( - self, - transform: &Transform, - objects: &mut Service, - ) -> Self { + fn transform(self, transform: &Transform, services: &mut Services) -> Self { let mut cache = TransformCache::default(); - self.transform_with_cache(transform, objects, &mut cache) + self.transform_with_cache(transform, &mut services.objects, &mut cache) } /// Transform the object using the provided cache @@ -57,7 +53,7 @@ pub trait TransformObject: Sized { offset: impl Into>, services: &mut Services, ) -> Self { - self.transform(&Transform::translation(offset), &mut services.objects) + self.transform(&Transform::translation(offset), services) } /// Rotate the object @@ -68,7 +64,7 @@ pub trait TransformObject: Sized { axis_angle: impl Into>, services: &mut Services, ) -> Self { - self.transform(&Transform::rotation(axis_angle), &mut services.objects) + self.transform(&Transform::rotation(axis_angle), services) } } diff --git a/crates/fj-operations/src/transform.rs b/crates/fj-operations/src/transform.rs index d75dbe947..e97306818 100644 --- a/crates/fj-operations/src/transform.rs +++ b/crates/fj-operations/src/transform.rs @@ -17,7 +17,7 @@ impl Shape for fj::Transform { ) -> Self::Brep { self.shape .compute_brep(services, debug_info) - .transform(&make_transform(self), &mut services.objects) + .transform(&make_transform(self), services) } fn bounding_volume(&self) -> Aabb<3> { From 0a58b7860358ad10326082a01430c6988471a34d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 09/28] Take full `Services` in `transform_with_cache` --- .../fj-kernel/src/algorithms/transform/cycle.rs | 9 +++------ .../fj-kernel/src/algorithms/transform/edge.rs | 12 ++++++------ .../fj-kernel/src/algorithms/transform/face.rs | 16 ++++++++-------- crates/fj-kernel/src/algorithms/transform/mod.rs | 13 ++++++------- .../fj-kernel/src/algorithms/transform/shell.rs | 9 +++------ .../fj-kernel/src/algorithms/transform/sketch.rs | 9 +++------ .../fj-kernel/src/algorithms/transform/solid.rs | 14 +++++--------- .../src/algorithms/transform/surface.rs | 7 ++----- .../fj-kernel/src/algorithms/transform/vertex.rs | 7 ++----- 9 files changed, 38 insertions(+), 58 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/cycle.rs b/crates/fj-kernel/src/algorithms/transform/cycle.rs index 5fbc6eb32..67e88fa64 100644 --- a/crates/fj-kernel/src/algorithms/transform/cycle.rs +++ b/crates/fj-kernel/src/algorithms/transform/cycle.rs @@ -1,9 +1,6 @@ use fj_math::Transform; -use crate::{ - objects::{Cycle, Objects}, - services::Service, -}; +use crate::{objects::Cycle, services::Services}; use super::{TransformCache, TransformObject}; @@ -11,13 +8,13 @@ impl TransformObject for Cycle { fn transform_with_cache( self, transform: &Transform, - objects: &mut Service, + services: &mut Services, cache: &mut TransformCache, ) -> Self { let half_edges = self.half_edges().map(|half_edge| { half_edge .clone() - .transform_with_cache(transform, objects, cache) + .transform_with_cache(transform, services, cache) }); Self::new(half_edges) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 1d5d78109..d1518ddd5 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -1,8 +1,8 @@ use fj_math::Transform; use crate::{ - objects::{GlobalEdge, HalfEdge, Objects}, - services::Service, + objects::{GlobalEdge, HalfEdge}, + services::Services, }; use super::{TransformCache, TransformObject}; @@ -11,7 +11,7 @@ impl TransformObject for HalfEdge { fn transform_with_cache( self, transform: &Transform, - objects: &mut Service, + services: &mut Services, cache: &mut TransformCache, ) -> Self { // Don't need to transform curve, as that's defined in surface @@ -21,11 +21,11 @@ impl TransformObject for HalfEdge { let start_vertex = self .start_vertex() .clone() - .transform_with_cache(transform, objects, cache); + .transform_with_cache(transform, services, cache); let global_form = self .global_form() .clone() - .transform_with_cache(transform, objects, cache); + .transform_with_cache(transform, services, cache); Self::new(curve, boundary, start_vertex, global_form) } @@ -35,7 +35,7 @@ impl TransformObject for GlobalEdge { fn transform_with_cache( self, _: &Transform, - _: &mut Service, + _: &mut Services, _: &mut TransformCache, ) -> Self { // There's nothing to actually transform here, as `GlobalEdge` holds no diff --git a/crates/fj-kernel/src/algorithms/transform/face.rs b/crates/fj-kernel/src/algorithms/transform/face.rs index fb4a58906..cd3c5cd81 100644 --- a/crates/fj-kernel/src/algorithms/transform/face.rs +++ b/crates/fj-kernel/src/algorithms/transform/face.rs @@ -1,8 +1,8 @@ use fj_math::Transform; use crate::{ - objects::{Face, FaceSet, Objects}, - services::Service, + objects::{Face, FaceSet}, + services::Services, }; use super::{TransformCache, TransformObject}; @@ -11,7 +11,7 @@ impl TransformObject for Face { fn transform_with_cache( self, transform: &Transform, - objects: &mut Service, + services: &mut Services, cache: &mut TransformCache, ) -> Self { // Color does not need to be transformed. @@ -20,13 +20,13 @@ impl TransformObject for Face { let surface = self .surface() .clone() - .transform_with_cache(transform, objects, cache); + .transform_with_cache(transform, services, cache); let exterior = self .exterior() .clone() - .transform_with_cache(transform, objects, cache); + .transform_with_cache(transform, services, cache); let interiors = self.interiors().cloned().map(|interior| { - interior.transform_with_cache(transform, objects, cache) + interior.transform_with_cache(transform, services, cache) }); Self::new(surface, exterior, interiors, color) @@ -37,13 +37,13 @@ impl TransformObject for FaceSet { fn transform_with_cache( self, transform: &Transform, - objects: &mut Service, + services: &mut Services, cache: &mut TransformCache, ) -> Self { let mut faces = Self::new(); faces.extend( self.into_iter().map(|face| { - face.transform_with_cache(transform, objects, cache) + face.transform_with_cache(transform, services, cache) }), ); faces diff --git a/crates/fj-kernel/src/algorithms/transform/mod.rs b/crates/fj-kernel/src/algorithms/transform/mod.rs index 511ce0d78..5cf7a73ea 100644 --- a/crates/fj-kernel/src/algorithms/transform/mod.rs +++ b/crates/fj-kernel/src/algorithms/transform/mod.rs @@ -15,9 +15,8 @@ use fj_math::{Transform, Vector}; use type_map::TypeMap; use crate::{ - objects::Objects, operations::Insert, - services::{Service, Services}, + services::Services, storage::{Handle, ObjectId}, }; @@ -34,14 +33,14 @@ pub trait TransformObject: Sized { /// Transform the object fn transform(self, transform: &Transform, services: &mut Services) -> Self { let mut cache = TransformCache::default(); - self.transform_with_cache(transform, &mut services.objects, &mut cache) + self.transform_with_cache(transform, services, &mut cache) } /// Transform the object using the provided cache fn transform_with_cache( self, transform: &Transform, - objects: &mut Service, + services: &mut Services, cache: &mut TransformCache, ) -> Self; @@ -75,7 +74,7 @@ where fn transform_with_cache( self, transform: &Transform, - objects: &mut Service, + services: &mut Services, cache: &mut TransformCache, ) -> Self { if let Some(object) = cache.get(&self) { @@ -84,8 +83,8 @@ where let transformed = self .clone_object() - .transform_with_cache(transform, objects, cache) - .insert(objects); + .transform_with_cache(transform, services, cache) + .insert(&mut services.objects); cache.insert(self.clone(), transformed.clone()); diff --git a/crates/fj-kernel/src/algorithms/transform/shell.rs b/crates/fj-kernel/src/algorithms/transform/shell.rs index 705e2785b..a8d91e0f9 100644 --- a/crates/fj-kernel/src/algorithms/transform/shell.rs +++ b/crates/fj-kernel/src/algorithms/transform/shell.rs @@ -1,9 +1,6 @@ use fj_math::Transform; -use crate::{ - objects::{Objects, Shell}, - services::Service, -}; +use crate::{objects::Shell, services::Services}; use super::{TransformCache, TransformObject}; @@ -11,12 +8,12 @@ impl TransformObject for Shell { fn transform_with_cache( self, transform: &Transform, - objects: &mut Service, + services: &mut Services, cache: &mut TransformCache, ) -> Self { let faces = self.faces().clone().into_iter().map(|face| { - face.transform_with_cache(transform, objects, cache) + face.transform_with_cache(transform, services, cache) }); Self::new(faces) diff --git a/crates/fj-kernel/src/algorithms/transform/sketch.rs b/crates/fj-kernel/src/algorithms/transform/sketch.rs index 5aca6243c..03b0e1387 100644 --- a/crates/fj-kernel/src/algorithms/transform/sketch.rs +++ b/crates/fj-kernel/src/algorithms/transform/sketch.rs @@ -1,9 +1,6 @@ use fj_math::Transform; -use crate::{ - objects::{Objects, Sketch}, - services::Service, -}; +use crate::{objects::Sketch, services::Services}; use super::{TransformCache, TransformObject}; @@ -11,12 +8,12 @@ impl TransformObject for Sketch { fn transform_with_cache( self, transform: &Transform, - objects: &mut Service, + services: &mut Services, cache: &mut TransformCache, ) -> Self { let faces = self.faces().into_iter().cloned().map(|face| { - face.transform_with_cache(transform, objects, cache) + face.transform_with_cache(transform, services, cache) }); Self::new(faces) diff --git a/crates/fj-kernel/src/algorithms/transform/solid.rs b/crates/fj-kernel/src/algorithms/transform/solid.rs index f0179dad5..fa9c243a5 100644 --- a/crates/fj-kernel/src/algorithms/transform/solid.rs +++ b/crates/fj-kernel/src/algorithms/transform/solid.rs @@ -1,9 +1,6 @@ use fj_math::Transform; -use crate::{ - objects::{Objects, Solid}, - services::Service, -}; +use crate::{objects::Solid, services::Services}; use super::{TransformCache, TransformObject}; @@ -11,13 +8,12 @@ impl TransformObject for Solid { fn transform_with_cache( self, transform: &Transform, - objects: &mut Service, + services: &mut Services, cache: &mut TransformCache, ) -> Self { - let shells = self - .shells() - .cloned() - .map(|shell| shell.transform_with_cache(transform, objects, cache)); + let shells = self.shells().cloned().map(|shell| { + shell.transform_with_cache(transform, services, cache) + }); Self::new(shells) } diff --git a/crates/fj-kernel/src/algorithms/transform/surface.rs b/crates/fj-kernel/src/algorithms/transform/surface.rs index 369ab538f..9d7cf7ca3 100644 --- a/crates/fj-kernel/src/algorithms/transform/surface.rs +++ b/crates/fj-kernel/src/algorithms/transform/surface.rs @@ -1,9 +1,6 @@ use fj_math::Transform; -use crate::{ - objects::{Objects, Surface}, - services::Service, -}; +use crate::{objects::Surface, services::Services}; use super::{TransformCache, TransformObject}; @@ -11,7 +8,7 @@ impl TransformObject for Surface { fn transform_with_cache( self, transform: &Transform, - _: &mut Service, + _: &mut Services, _: &mut TransformCache, ) -> Self { let geometry = self.geometry().transform(transform); diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 1b1eef6a8..95601597e 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -1,9 +1,6 @@ use fj_math::Transform; -use crate::{ - objects::{Objects, Vertex}, - services::Service, -}; +use crate::{objects::Vertex, services::Services}; use super::{TransformCache, TransformObject}; @@ -11,7 +8,7 @@ impl TransformObject for Vertex { fn transform_with_cache( self, _: &Transform, - _: &mut Service, + _: &mut Services, _: &mut TransformCache, ) -> Self { // There's nothing to actually transform here, as `Vertex` holds no From f5ed63db0b46be1d5f1497fc32ef3c1abee00d3b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 10/28] Take full `Services` in `connect_to_edges` --- crates/fj-kernel/src/algorithms/sweep/face.rs | 7 ++----- crates/fj-kernel/src/builder/cycle.rs | 9 +++------ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 8a92c425b..4db71ec7b 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -82,11 +82,8 @@ impl Sweep for Handle { )); } - let top_cycle = CycleBuilder::connect_to_edges( - top_edges, - &mut services.objects, - ) - .build(&mut services.objects); + let top_cycle = CycleBuilder::connect_to_edges(top_edges, services) + .build(&mut services.objects); if i == 0 { exterior = Some(top_cycle.insert(&mut services.objects)); diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 3fff2c6b4..ce1fe385c 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -5,7 +5,7 @@ use crate::{ geometry::curve::Curve, objects::{Cycle, HalfEdge, Objects}, operations::{BuildHalfEdge, Insert, UpdateHalfEdge}, - services::Service, + services::{Service, Services}, storage::Handle, }; @@ -28,10 +28,7 @@ impl CycleBuilder { /// /// Assumes that the provided half-edges, once translated into local /// equivalents of this cycle, form a cycle themselves. - pub fn connect_to_edges( - edges: Es, - objects: &mut Service, - ) -> Self + pub fn connect_to_edges(edges: Es, services: &mut Services) -> Self where Es: IntoIterator, Curve, [Point<1>; 2])>, Es::IntoIter: Clone + ExactSizeIterator, @@ -40,7 +37,7 @@ impl CycleBuilder { .into_iter() .circular_tuple_windows() .map(|((prev, _, _), (half_edge, curve, boundary))| { - HalfEdge::unjoined(curve, boundary, objects) + HalfEdge::unjoined(curve, boundary, &mut services.objects) .replace_start_vertex(prev.start_vertex().clone()) .replace_global_form(half_edge.global_form().clone()) }) From 36f3cb6981a4ac8917742d6cb5b49cfa8436321b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 11/28] Take full `Services` in `CycleBuilder::polygon` --- .../src/algorithms/intersect/curve_face.rs | 4 ++-- .../src/algorithms/intersect/face_face.rs | 10 ++-------- .../src/algorithms/intersect/face_point.rs | 16 ++++++++-------- .../src/algorithms/intersect/ray_face.rs | 14 +++++++------- .../fj-kernel/src/algorithms/triangulate/mod.rs | 17 ++++------------- crates/fj-kernel/src/builder/cycle.rs | 8 ++++++-- crates/fj-kernel/src/validate/cycle.rs | 2 +- crates/fj-kernel/src/validate/face.rs | 4 ++-- 8 files changed, 32 insertions(+), 43 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 4ff2c6c08..bbaa838c1 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -181,11 +181,11 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon( exterior_points, - &mut services.objects, + &mut services, )) .with_interior(CycleBuilder::polygon( interior_points, - &mut services.objects, + &mut services, )) .build(&mut services.objects); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index dbee4285e..0799235b4 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -86,10 +86,7 @@ mod tests { ] .map(|surface| { FaceBuilder::new(surface) - .with_exterior(CycleBuilder::polygon( - points, - &mut services.objects, - )) + .with_exterior(CycleBuilder::polygon(points, &mut services)) .build(&mut services.objects) }); @@ -115,10 +112,7 @@ mod tests { ]; let [a, b] = surfaces.clone().map(|surface| { FaceBuilder::new(surface) - .with_exterior(CycleBuilder::polygon( - points, - &mut services.objects, - )) + .with_exterior(CycleBuilder::polygon(points, &mut services)) .build(&mut services.objects) }); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 5f8c9202b..139897385 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -149,7 +149,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon( [[0., 0.], [1., 1.], [0., 2.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let point = Point::from([2., 1.]); @@ -165,7 +165,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon( [[0., 0.], [2., 1.], [0., 2.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let point = Point::from([1., 1.]); @@ -184,7 +184,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon( [[4., 2.], [0., 4.], [0., 0.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let point = Point::from([1., 2.]); @@ -203,7 +203,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon( [[0., 0.], [2., 1.], [3., 0.], [3., 4.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let point = Point::from([1., 1.]); @@ -222,7 +222,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon( [[0., 0.], [2., 1.], [3., 1.], [0., 2.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let point = Point::from([1., 1.]); @@ -241,7 +241,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon( [[0., 0.], [2., 1.], [3., 1.], [4., 0.], [4., 5.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let point = Point::from([1., 1.]); @@ -260,7 +260,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon( [[0., 0.], [2., 0.], [0., 1.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let point = Point::from([1., 0.]); @@ -285,7 +285,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon( [[0., 0.], [1., 0.], [0., 1.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let point = Point::from([1., 0.]); diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index 4902d173c..e9de917ec 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -165,7 +165,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.yz_plane()) .with_exterior(CycleBuilder::polygon( [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let face = face.translate([-1., 0., 0.], &mut services); @@ -182,7 +182,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.yz_plane()) .with_exterior(CycleBuilder::polygon( [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let face = face.translate([1., 0., 0.], &mut services); @@ -202,7 +202,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.yz_plane()) .with_exterior(CycleBuilder::polygon( [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let face = face.translate([0., 0., 2.], &mut services); @@ -219,7 +219,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.yz_plane()) .with_exterior(CycleBuilder::polygon( [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let face = face.translate([1., 1., 0.], &mut services); @@ -244,7 +244,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.yz_plane()) .with_exterior(CycleBuilder::polygon( [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let face = face.translate([1., 1., 1.], &mut services); @@ -272,7 +272,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon( [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); @@ -291,7 +291,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon( [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let face = face.translate([0., 0., 1.], &mut services); diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 18889bb75..3060c9954 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -96,10 +96,7 @@ mod tests { let d = [0., 1.]; let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) - .with_exterior(CycleBuilder::polygon( - [a, b, c, d], - &mut services.objects, - )) + .with_exterior(CycleBuilder::polygon([a, b, c, d], &mut services)) .build(&mut services.objects); let a = Point::from(a).to_xyz(); @@ -134,14 +131,8 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let face = FaceBuilder::new(surface.clone()) - .with_exterior(CycleBuilder::polygon( - [a, b, c, d], - &mut services.objects, - )) - .with_interior(CycleBuilder::polygon( - [e, f, g, h], - &mut services.objects, - )) + .with_exterior(CycleBuilder::polygon([a, b, c, d], &mut services)) + .with_interior(CycleBuilder::polygon([e, f, g, h], &mut services)) .build(&mut services.objects); let triangles = triangulate(face)?; @@ -200,7 +191,7 @@ mod tests { let face = FaceBuilder::new(surface.clone()) .with_exterior(CycleBuilder::polygon( [a, b, c, d, e], - &mut services.objects, + &mut services, )) .build(&mut services.objects); diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index ce1fe385c..ac2698283 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -47,7 +47,7 @@ impl CycleBuilder { } /// Create a polygon - pub fn polygon(points: Ps, objects: &mut Service) -> Self + pub fn polygon(points: Ps, services: &mut Services) -> Self where P: Into>, Ps: IntoIterator, @@ -58,7 +58,11 @@ impl CycleBuilder { .map(Into::into) .circular_tuple_windows() .map(|(start, end)| { - HalfEdge::line_segment([start, end], None, objects) + HalfEdge::line_segment( + [start, end], + None, + &mut services.objects, + ) }) .collect(); diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index b1ae299d7..3b01b05c0 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -109,7 +109,7 @@ mod tests { let valid = CycleBuilder::polygon( [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]], - &mut services.objects, + &mut services, ) .build(&mut services.objects); diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index e637ed507..ba6d2d62c 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -86,11 +86,11 @@ mod tests { let valid = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon( [[0., 0.], [3., 0.], [0., 3.]], - &mut services.objects, + &mut services, )) .with_interior(CycleBuilder::polygon( [[1., 1.], [1., 2.], [2., 1.]], - &mut services.objects, + &mut services, )) .build(&mut services.objects); let invalid = { From a7e90336bcfd50730ca1d089d65045d80e2396bb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 12/28] Take full `Services` in `FaceBuilder::build` --- .../src/algorithms/intersect/curve_face.rs | 2 +- .../src/algorithms/intersect/face_face.rs | 4 ++-- .../src/algorithms/intersect/face_point.rs | 16 +++++++-------- .../src/algorithms/intersect/ray_face.rs | 14 ++++++------- .../src/algorithms/triangulate/mod.rs | 6 +++--- crates/fj-kernel/src/builder/face.rs | 20 +++++++++++-------- crates/fj-kernel/src/validate/face.rs | 2 +- 7 files changed, 34 insertions(+), 30 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index bbaa838c1..856f76b29 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -187,7 +187,7 @@ mod tests { interior_points, &mut services, )) - .build(&mut services.objects); + .build(&mut services); let expected = CurveFaceIntersection::from_intervals([[[1.], [2.]], [[4.], [5.]]]); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index 0799235b4..931af8fc8 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -87,7 +87,7 @@ mod tests { .map(|surface| { FaceBuilder::new(surface) .with_exterior(CycleBuilder::polygon(points, &mut services)) - .build(&mut services.objects) + .build(&mut services) }); let intersection = FaceFaceIntersection::compute([&a, &b]); @@ -113,7 +113,7 @@ mod tests { let [a, b] = surfaces.clone().map(|surface| { FaceBuilder::new(surface) .with_exterior(CycleBuilder::polygon(points, &mut services)) - .build(&mut services.objects) + .build(&mut services) }); let intersection = FaceFaceIntersection::compute([&a, &b]); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 139897385..109543316 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -151,7 +151,7 @@ mod tests { [[0., 0.], [1., 1.], [0., 2.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let point = Point::from([2., 1.]); let intersection = (&face, &point).intersect(); @@ -167,7 +167,7 @@ mod tests { [[0., 0.], [2., 1.], [0., 2.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let point = Point::from([1., 1.]); let intersection = (&face, &point).intersect(); @@ -186,7 +186,7 @@ mod tests { [[4., 2.], [0., 4.], [0., 0.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let point = Point::from([1., 2.]); let intersection = (&face, &point).intersect(); @@ -205,7 +205,7 @@ mod tests { [[0., 0.], [2., 1.], [3., 0.], [3., 4.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let point = Point::from([1., 1.]); let intersection = (&face, &point).intersect(); @@ -224,7 +224,7 @@ mod tests { [[0., 0.], [2., 1.], [3., 1.], [0., 2.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let point = Point::from([1., 1.]); let intersection = (&face, &point).intersect(); @@ -243,7 +243,7 @@ mod tests { [[0., 0.], [2., 1.], [3., 1.], [4., 0.], [4., 5.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let point = Point::from([1., 1.]); let intersection = (&face, &point).intersect(); @@ -262,7 +262,7 @@ mod tests { [[0., 0.], [2., 0.], [0., 1.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let point = Point::from([1., 0.]); let intersection = (&face, &point).intersect(); @@ -287,7 +287,7 @@ mod tests { [[0., 0.], [1., 0.], [0., 1.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let point = Point::from([1., 0.]); let intersection = (&face, &point).intersect(); diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index e9de917ec..97afca4f5 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -167,7 +167,7 @@ mod tests { [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let face = face.translate([-1., 0., 0.], &mut services); assert_eq!((&ray, &face).intersect(), None); @@ -184,7 +184,7 @@ mod tests { [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let face = face.translate([1., 0., 0.], &mut services); assert_eq!( @@ -204,7 +204,7 @@ mod tests { [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let face = face.translate([0., 0., 2.], &mut services); assert_eq!((&ray, &face).intersect(), None); @@ -221,7 +221,7 @@ mod tests { [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let face = face.translate([1., 1., 0.], &mut services); let edge = face @@ -246,7 +246,7 @@ mod tests { [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let face = face.translate([1., 1., 1.], &mut services); let vertex = face @@ -274,7 +274,7 @@ mod tests { [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); assert_eq!( (&ray, &face).intersect(), @@ -293,7 +293,7 @@ mod tests { [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let face = face.translate([0., 0., 1.], &mut services); assert_eq!((&ray, &face).intersect(), None); diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 3060c9954..7e8f5b731 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -97,7 +97,7 @@ mod tests { let face = FaceBuilder::new(services.objects.surfaces.xy_plane()) .with_exterior(CycleBuilder::polygon([a, b, c, d], &mut services)) - .build(&mut services.objects); + .build(&mut services); let a = Point::from(a).to_xyz(); let b = Point::from(b).to_xyz(); @@ -133,7 +133,7 @@ mod tests { let face = FaceBuilder::new(surface.clone()) .with_exterior(CycleBuilder::polygon([a, b, c, d], &mut services)) .with_interior(CycleBuilder::polygon([e, f, g, h], &mut services)) - .build(&mut services.objects); + .build(&mut services); let triangles = triangulate(face)?; @@ -193,7 +193,7 @@ mod tests { [a, b, c, d, e], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let triangles = triangulate(face)?; diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 3dc980233..1ac8ad2f7 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -1,9 +1,9 @@ use fj_interop::mesh::Color; use crate::{ - objects::{Face, Objects, Surface}, + objects::{Face, Surface}, operations::Insert, - services::Service, + services::Services, storage::Handle, }; @@ -46,12 +46,16 @@ impl FaceBuilder { } /// Build the face - pub fn build(self, objects: &mut Service) -> Face { - let exterior = self.exterior.build(objects).insert(objects); - let interiors = self - .interiors - .into_iter() - .map(|cycle| cycle.build(objects).insert(objects)); + pub fn build(self, services: &mut Services) -> Face { + let exterior = self + .exterior + .build(&mut services.objects) + .insert(&mut services.objects); + let interiors = self.interiors.into_iter().map(|cycle| { + cycle + .build(&mut services.objects) + .insert(&mut services.objects) + }); Face::new(self.surface, exterior, interiors, self.color) } diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index ba6d2d62c..7b45fd64a 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -92,7 +92,7 @@ mod tests { [[1., 1.], [1., 2.], [2., 1.]], &mut services, )) - .build(&mut services.objects); + .build(&mut services); let invalid = { let interiors = valid .interiors() From 184b0d264607badbafe57282aea26224bd5ba4d2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 13/28] Take full `Services` in `CycleBuilder::build` --- crates/fj-kernel/src/algorithms/sweep/face.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 8 ++++---- crates/fj-kernel/src/builder/face.rs | 15 ++++++--------- crates/fj-kernel/src/validate/cycle.rs | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 4db71ec7b..cd7eb197a 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -83,7 +83,7 @@ impl Sweep for Handle { } let top_cycle = CycleBuilder::connect_to_edges(top_edges, services) - .build(&mut services.objects); + .build(services); if i == 0 { exterior = Some(top_cycle.insert(&mut services.objects)); diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index ac2698283..a9c33cfea 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -3,9 +3,9 @@ use itertools::Itertools; use crate::{ geometry::curve::Curve, - objects::{Cycle, HalfEdge, Objects}, + objects::{Cycle, HalfEdge}, operations::{BuildHalfEdge, Insert, UpdateHalfEdge}, - services::{Service, Services}, + services::Services, storage::Handle, }; @@ -70,11 +70,11 @@ impl CycleBuilder { } /// Build the cycle - pub fn build(self, objects: &mut Service) -> Cycle { + pub fn build(self, services: &mut Services) -> Cycle { let half_edges = self .half_edges .into_iter() - .map(|half_edge| half_edge.insert(objects)); + .map(|half_edge| half_edge.insert(&mut services.objects)); Cycle::new(half_edges) } } diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 1ac8ad2f7..285f0d82e 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -47,15 +47,12 @@ impl FaceBuilder { /// Build the face pub fn build(self, services: &mut Services) -> Face { - let exterior = self - .exterior - .build(&mut services.objects) - .insert(&mut services.objects); - let interiors = self.interiors.into_iter().map(|cycle| { - cycle - .build(&mut services.objects) - .insert(&mut services.objects) - }); + let exterior = + self.exterior.build(services).insert(&mut services.objects); + let interiors = self + .interiors + .into_iter() + .map(|cycle| cycle.build(services).insert(&mut services.objects)); Face::new(self.surface, exterior, interiors, self.color) } diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index 3b01b05c0..d16029df5 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -111,7 +111,7 @@ mod tests { [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]], &mut services, ) - .build(&mut services.objects); + .build(&mut services); valid.validate_and_return_first_error()?; From 31c8572918474d602303ed82e82ba969f2656bb8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 14/28] Take full `Services` in `BuildHalfEdge::arc` --- crates/fj-kernel/src/operations/build/edge.rs | 6 +++--- crates/fj-operations/src/sketch.rs | 7 +------ 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/operations/build/edge.rs b/crates/fj-kernel/src/operations/build/edge.rs index cacd54cda..294fa6641 100644 --- a/crates/fj-kernel/src/operations/build/edge.rs +++ b/crates/fj-kernel/src/operations/build/edge.rs @@ -5,7 +5,7 @@ use crate::{ geometry::curve::Curve, objects::{GlobalEdge, HalfEdge, Objects, Surface, Vertex}, operations::Insert, - services::Service, + services::{Service, Services}, }; /// Build a [`HalfEdge`] @@ -31,7 +31,7 @@ pub trait BuildHalfEdge { start: impl Into>, end: impl Into>, angle_rad: impl Into, - objects: &mut Service, + services: &mut Services, ) -> HalfEdge { let angle_rad = angle_rad.into(); if angle_rad <= -Scalar::TAU || angle_rad >= Scalar::TAU { @@ -45,7 +45,7 @@ pub trait BuildHalfEdge { let boundary = [arc.start_angle, arc.end_angle].map(|coord| Point::from([coord])); - HalfEdge::unjoined(curve, boundary, objects) + HalfEdge::unjoined(curve, boundary, &mut services.objects) } /// Create a circle diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index aade3cb5b..fdeb93cbc 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -65,12 +65,7 @@ impl Shape for fj::Sketch { ) } fj::SketchSegmentRoute::Arc { angle } => { - HalfEdge::arc( - start, - end, - angle.rad(), - &mut services.objects, - ) + HalfEdge::arc(start, end, angle.rad(), services) } }; let half_edge = half_edge.insert(&mut services.objects); From 5afa720c74a439c6d55fe3a58e9cdced590c7483 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 15/28] Take full `Services` in `BuildHalfEdge::circle` --- crates/fj-kernel/src/algorithms/approx/edge.rs | 2 +- crates/fj-kernel/src/operations/build/edge.rs | 7 ++----- crates/fj-operations/src/sketch.rs | 5 ++--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 2dfdbbf1e..167a8802c 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -346,7 +346,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xz_plane(); - let half_edge = HalfEdge::circle(1., &mut services.objects); + let half_edge = HalfEdge::circle(1., &mut services); let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); diff --git a/crates/fj-kernel/src/operations/build/edge.rs b/crates/fj-kernel/src/operations/build/edge.rs index 294fa6641..791d98a0b 100644 --- a/crates/fj-kernel/src/operations/build/edge.rs +++ b/crates/fj-kernel/src/operations/build/edge.rs @@ -49,15 +49,12 @@ pub trait BuildHalfEdge { } /// Create a circle - fn circle( - radius: impl Into, - objects: &mut Service, - ) -> HalfEdge { + fn circle(radius: impl Into, services: &mut Services) -> HalfEdge { let curve = Curve::circle_from_radius(radius); let boundary = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); - HalfEdge::unjoined(curve, boundary, objects) + HalfEdge::unjoined(curve, boundary, &mut services.objects) } /// Create a line segment diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index fdeb93cbc..bbda44c94 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -23,9 +23,8 @@ impl Shape for fj::Sketch { let face = match self.chain() { fj::Chain::Circle(circle) => { - let half_edge = - HalfEdge::circle(circle.radius(), &mut services.objects) - .insert(&mut services.objects); + let half_edge = HalfEdge::circle(circle.radius(), services) + .insert(&mut services.objects); let exterior = Cycle::new([half_edge]).insert(&mut services.objects); From 75e078371d0667e99d7ea9052a5c5e5944c598d8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 16/28] Take full `Services` in `BuildShell::tetrahedron` --- .../fj-kernel/src/operations/build/shell.rs | 92 ++++++++++++------- crates/fj-kernel/src/validate/shell.rs | 4 +- 2 files changed, 62 insertions(+), 34 deletions(-) diff --git a/crates/fj-kernel/src/operations/build/shell.rs b/crates/fj-kernel/src/operations/build/shell.rs index 0f2628921..e8bb8541a 100644 --- a/crates/fj-kernel/src/operations/build/shell.rs +++ b/crates/fj-kernel/src/operations/build/shell.rs @@ -1,9 +1,9 @@ use fj_math::Point; use crate::{ - objects::{Face, Objects, Shell}, + objects::{Face, Shell}, operations::{Insert, JoinCycle, UpdateFace}, - services::Service, + services::Services, storage::Handle, }; @@ -31,40 +31,68 @@ pub trait BuildShell { /// build a correct tetrahedron, regardless of that order. fn tetrahedron( points: [impl Into>; 4], - objects: &mut Service, + services: &mut Services, ) -> Tetrahedron { let [a, b, c, d] = points.map(Into::into); - let abc = Face::triangle([a, b, c], objects).face; - let bad = - Face::triangle([b, a, d], objects) - .face - .update_exterior(|cycle| { - cycle - .join_to(abc.exterior(), 0..=0, 0..=0, objects) - .insert(objects) - }); - let dac = - Face::triangle([d, a, c], objects) - .face - .update_exterior(|cycle| { - cycle - .join_to(abc.exterior(), 1..=1, 2..=2, objects) - .join_to(bad.exterior(), 0..=0, 1..=1, objects) - .insert(objects) - }); - let cbd = - Face::triangle([c, b, d], objects) - .face - .update_exterior(|cycle| { - cycle - .join_to(abc.exterior(), 0..=0, 1..=1, objects) - .join_to(bad.exterior(), 1..=1, 2..=2, objects) - .join_to(dac.exterior(), 2..=2, 2..=2, objects) - .insert(objects) - }); + let abc = Face::triangle([a, b, c], &mut services.objects).face; + let bad = Face::triangle([b, a, d], &mut services.objects) + .face + .update_exterior(|cycle| { + cycle + .join_to( + abc.exterior(), + 0..=0, + 0..=0, + &mut services.objects, + ) + .insert(&mut services.objects) + }); + let dac = Face::triangle([d, a, c], &mut services.objects) + .face + .update_exterior(|cycle| { + cycle + .join_to( + abc.exterior(), + 1..=1, + 2..=2, + &mut services.objects, + ) + .join_to( + bad.exterior(), + 0..=0, + 1..=1, + &mut services.objects, + ) + .insert(&mut services.objects) + }); + let cbd = Face::triangle([c, b, d], &mut services.objects) + .face + .update_exterior(|cycle| { + cycle + .join_to( + abc.exterior(), + 0..=0, + 1..=1, + &mut services.objects, + ) + .join_to( + bad.exterior(), + 1..=1, + 2..=2, + &mut services.objects, + ) + .join_to( + dac.exterior(), + 2..=2, + 2..=2, + &mut services.objects, + ) + .insert(&mut services.objects) + }); - let faces = [abc, bad, dac, cbd].map(|face| face.insert(objects)); + let faces = + [abc, bad, dac, cbd].map(|face| face.insert(&mut services.objects)); let shell = Shell::new(faces.clone()); let [abc, bad, dac, cbd] = faces; diff --git a/crates/fj-kernel/src/validate/shell.rs b/crates/fj-kernel/src/validate/shell.rs index d9c557ad5..607a8a44b 100644 --- a/crates/fj-kernel/src/validate/shell.rs +++ b/crates/fj-kernel/src/validate/shell.rs @@ -208,7 +208,7 @@ mod tests { let valid = Shell::tetrahedron( [[0., 0., 0.], [0., 1., 0.], [1., 0., 0.], [0., 0., 1.]], - &mut services.objects, + &mut services, ); let invalid = valid.shell.update_face(&valid.abc, |face| { face.update_exterior(|cycle| { @@ -241,7 +241,7 @@ mod tests { let valid = Shell::tetrahedron( [[0., 0., 0.], [0., 1., 0.], [1., 0., 0.], [0., 0., 1.]], - &mut services.objects, + &mut services, ); let invalid = valid.shell.remove_face(&valid.abc); From c032d25593dd399306f70bf7c9b067218b686b63 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 17/28] Take full `Services` in `BuildFace::triangle` --- crates/fj-kernel/src/operations/build/face.rs | 19 +-- .../fj-kernel/src/operations/build/shell.rs | 113 +++++++++--------- 2 files changed, 70 insertions(+), 62 deletions(-) diff --git a/crates/fj-kernel/src/operations/build/face.rs b/crates/fj-kernel/src/operations/build/face.rs index d83536c88..7f21d1b53 100644 --- a/crates/fj-kernel/src/operations/build/face.rs +++ b/crates/fj-kernel/src/operations/build/face.rs @@ -2,9 +2,9 @@ use fj_interop::ext::ArrayExt; use fj_math::Point; use crate::{ - objects::{Cycle, Face, HalfEdge, Objects, Surface, Vertex}, + objects::{Cycle, Face, HalfEdge, Surface, Vertex}, operations::Insert, - services::Service, + services::Services, storage::Handle, }; @@ -15,24 +15,29 @@ pub trait BuildFace { /// Build a triangle fn triangle( points: [impl Into>; 3], - objects: &mut Service, + services: &mut Services, ) -> Polygon<3> { let [a, b, c] = points.map(Into::into); - let surface = Surface::plane_from_points([a, b, c]).insert(objects); + let surface = + Surface::plane_from_points([a, b, c]).insert(&mut services.objects); let (exterior, edges, vertices) = { let half_edges = [[a, b], [b, c], [c, a]].map(|points| { let half_edge = HalfEdge::line_segment_from_global_points( - points, &surface, None, objects, + points, + &surface, + None, + &mut services.objects, ); - half_edge.insert(objects) + half_edge.insert(&mut services.objects) }); let vertices = half_edges .each_ref_ext() .map(|half_edge| half_edge.start_vertex().clone()); - let cycle = Cycle::new(half_edges.clone()).insert(objects); + let cycle = + Cycle::new(half_edges.clone()).insert(&mut services.objects); (cycle, half_edges, vertices) }; diff --git a/crates/fj-kernel/src/operations/build/shell.rs b/crates/fj-kernel/src/operations/build/shell.rs index e8bb8541a..f6071b866 100644 --- a/crates/fj-kernel/src/operations/build/shell.rs +++ b/crates/fj-kernel/src/operations/build/shell.rs @@ -35,61 +35,64 @@ pub trait BuildShell { ) -> Tetrahedron { let [a, b, c, d] = points.map(Into::into); - let abc = Face::triangle([a, b, c], &mut services.objects).face; - let bad = Face::triangle([b, a, d], &mut services.objects) - .face - .update_exterior(|cycle| { - cycle - .join_to( - abc.exterior(), - 0..=0, - 0..=0, - &mut services.objects, - ) - .insert(&mut services.objects) - }); - let dac = Face::triangle([d, a, c], &mut services.objects) - .face - .update_exterior(|cycle| { - cycle - .join_to( - abc.exterior(), - 1..=1, - 2..=2, - &mut services.objects, - ) - .join_to( - bad.exterior(), - 0..=0, - 1..=1, - &mut services.objects, - ) - .insert(&mut services.objects) - }); - let cbd = Face::triangle([c, b, d], &mut services.objects) - .face - .update_exterior(|cycle| { - cycle - .join_to( - abc.exterior(), - 0..=0, - 1..=1, - &mut services.objects, - ) - .join_to( - bad.exterior(), - 1..=1, - 2..=2, - &mut services.objects, - ) - .join_to( - dac.exterior(), - 2..=2, - 2..=2, - &mut services.objects, - ) - .insert(&mut services.objects) - }); + let abc = Face::triangle([a, b, c], services).face; + let bad = + Face::triangle([b, a, d], services) + .face + .update_exterior(|cycle| { + cycle + .join_to( + abc.exterior(), + 0..=0, + 0..=0, + &mut services.objects, + ) + .insert(&mut services.objects) + }); + let dac = + Face::triangle([d, a, c], services) + .face + .update_exterior(|cycle| { + cycle + .join_to( + abc.exterior(), + 1..=1, + 2..=2, + &mut services.objects, + ) + .join_to( + bad.exterior(), + 0..=0, + 1..=1, + &mut services.objects, + ) + .insert(&mut services.objects) + }); + let cbd = + Face::triangle([c, b, d], services) + .face + .update_exterior(|cycle| { + cycle + .join_to( + abc.exterior(), + 0..=0, + 1..=1, + &mut services.objects, + ) + .join_to( + bad.exterior(), + 1..=1, + 2..=2, + &mut services.objects, + ) + .join_to( + dac.exterior(), + 2..=2, + 2..=2, + &mut services.objects, + ) + .insert(&mut services.objects) + }); let faces = [abc, bad, dac, cbd].map(|face| face.insert(&mut services.objects)); From 3b10ee43c312ccf831076bfa79b9a8879e3a57a5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 18/28] Take full `Services` in `BuildHalfEdge` method --- crates/fj-kernel/src/operations/build/edge.rs | 4 ++-- crates/fj-kernel/src/operations/build/face.rs | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/operations/build/edge.rs b/crates/fj-kernel/src/operations/build/edge.rs index 791d98a0b..88f95448f 100644 --- a/crates/fj-kernel/src/operations/build/edge.rs +++ b/crates/fj-kernel/src/operations/build/edge.rs @@ -77,11 +77,11 @@ pub trait BuildHalfEdge { points_global: [impl Into>; 2], surface: &Surface, boundary: Option<[Point<1>; 2]>, - objects: &mut Service, + services: &mut Services, ) -> HalfEdge { let points_surface = points_global .map(|point| surface.geometry().project_global_point(point)); - HalfEdge::line_segment(points_surface, boundary, objects) + HalfEdge::line_segment(points_surface, boundary, &mut services.objects) } } diff --git a/crates/fj-kernel/src/operations/build/face.rs b/crates/fj-kernel/src/operations/build/face.rs index 7f21d1b53..0f363f3da 100644 --- a/crates/fj-kernel/src/operations/build/face.rs +++ b/crates/fj-kernel/src/operations/build/face.rs @@ -24,10 +24,7 @@ pub trait BuildFace { let (exterior, edges, vertices) = { let half_edges = [[a, b], [b, c], [c, a]].map(|points| { let half_edge = HalfEdge::line_segment_from_global_points( - points, - &surface, - None, - &mut services.objects, + points, &surface, None, services, ); half_edge.insert(&mut services.objects) From d19474cd415085eeb66f8bf07dcd1ffc67942f06 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 19/28] Take full `Services` in `line_segment` --- crates/fj-kernel/src/algorithms/approx/edge.rs | 16 +++++----------- .../src/algorithms/intersect/curve_edge.rs | 18 ++++++------------ crates/fj-kernel/src/algorithms/sweep/edge.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 6 +----- crates/fj-kernel/src/operations/build/edge.rs | 6 +++--- crates/fj-kernel/src/validate/cycle.rs | 4 ++-- crates/fj-kernel/src/validate/edge.rs | 7 ++----- crates/fj-operations/src/sketch.rs | 2 +- 8 files changed, 21 insertions(+), 40 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 167a8802c..ada576161 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -273,11 +273,8 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xz_plane(); - let half_edge = HalfEdge::line_segment( - [[1., 1.], [2., 1.]], - None, - &mut services.objects, - ); + let half_edge = + HalfEdge::line_segment([[1., 1.], [2., 1.]], None, &mut services); let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); @@ -294,11 +291,8 @@ mod tests { v: [0., 0., 1.].into(), }) .insert(&mut services.objects); - let half_edge = HalfEdge::line_segment( - [[1., 1.], [2., 1.]], - None, - &mut services.objects, - ); + let half_edge = + HalfEdge::line_segment([[1., 1.], [2., 1.]], None, &mut services); let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); @@ -321,7 +315,7 @@ mod tests { let half_edge = HalfEdge::line_segment( [[0., 1.], [TAU, 1.]], Some(range.boundary), - &mut services.objects, + &mut services, ); let tolerance = 1.; diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs index c5b759c41..e59a9f97e 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -83,11 +83,8 @@ mod tests { let mut services = Services::new(); let curve = Curve::u_axis(); - let half_edge = HalfEdge::line_segment( - [[1., -1.], [1., 1.]], - None, - &mut services.objects, - ); + let half_edge = + HalfEdge::line_segment([[1., -1.], [1., 1.]], None, &mut services); let intersection = CurveEdgeIntersection::compute(&curve, &half_edge); @@ -107,7 +104,7 @@ mod tests { let half_edge = HalfEdge::line_segment( [[-1., -1.], [-1., 1.]], None, - &mut services.objects, + &mut services, ); let intersection = CurveEdgeIntersection::compute(&curve, &half_edge); @@ -128,7 +125,7 @@ mod tests { let half_edge = HalfEdge::line_segment( [[-1., -1.], [1., -1.]], None, - &mut services.objects, + &mut services, ); let intersection = CurveEdgeIntersection::compute(&curve, &half_edge); @@ -141,11 +138,8 @@ mod tests { let mut services = Services::new(); let curve = Curve::u_axis(); - let half_edge = HalfEdge::line_segment( - [[-1., 0.], [1., 0.]], - None, - &mut services.objects, - ); + let half_edge = + HalfEdge::line_segment([[-1., 0.], [1., 0.]], None, &mut services); let intersection = CurveEdgeIntersection::compute(&curve, &half_edge); diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 21ad13664..16e665d80 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -81,7 +81,7 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { let half_edge = HalfEdge::line_segment( [start, end], Some(boundary), - &mut services.objects, + services, ) .replace_start_vertex(start_vertex); diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index a9c33cfea..60789fe07 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -58,11 +58,7 @@ impl CycleBuilder { .map(Into::into) .circular_tuple_windows() .map(|(start, end)| { - HalfEdge::line_segment( - [start, end], - None, - &mut services.objects, - ) + HalfEdge::line_segment([start, end], None, services) }) .collect(); diff --git a/crates/fj-kernel/src/operations/build/edge.rs b/crates/fj-kernel/src/operations/build/edge.rs index 88f95448f..c9c36c04e 100644 --- a/crates/fj-kernel/src/operations/build/edge.rs +++ b/crates/fj-kernel/src/operations/build/edge.rs @@ -61,7 +61,7 @@ pub trait BuildHalfEdge { fn line_segment( points_surface: [impl Into>; 2], boundary: Option<[Point<1>; 2]>, - objects: &mut Service, + services: &mut Services, ) -> HalfEdge { let boundary = boundary.unwrap_or_else(|| [[0.], [1.]].map(Point::from)); @@ -69,7 +69,7 @@ pub trait BuildHalfEdge { boundary.zip_ext(points_surface), ); - HalfEdge::unjoined(curve, boundary, objects) + HalfEdge::unjoined(curve, boundary, &mut services.objects) } /// Create a line segment from global points @@ -81,7 +81,7 @@ pub trait BuildHalfEdge { ) -> HalfEdge { let points_surface = points_global .map(|point| surface.geometry().project_global_point(point)); - HalfEdge::line_segment(points_surface, boundary, &mut services.objects) + HalfEdge::line_segment(points_surface, boundary, services) } } diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index d16029df5..67adc1fdc 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -120,12 +120,12 @@ mod tests { HalfEdge::line_segment( [[0., 0.], [1., 0.]], None, - &mut services.objects, + &mut services, ), HalfEdge::line_segment( [[0., 0.], [1., 0.]], None, - &mut services.objects, + &mut services, ), ]; let half_edges = half_edges diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 053cc3c3d..890599a10 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -87,11 +87,8 @@ mod tests { fn half_edge_vertices_are_coincident() -> anyhow::Result<()> { let mut services = Services::new(); - let valid = HalfEdge::line_segment( - [[0., 0.], [1., 0.]], - None, - &mut services.objects, - ); + let valid = + HalfEdge::line_segment([[0., 0.], [1., 0.]], None, &mut services); let invalid = { let boundary = [Point::from([0.]); 2]; diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index bbda44c94..82628e6a4 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -60,7 +60,7 @@ impl Shape for fj::Sketch { HalfEdge::line_segment( [start, end], None, - &mut services.objects, + services, ) } fj::SketchSegmentRoute::Arc { angle } => { From d3627139a537075dbbe1d43ceedde7c56752c2ee Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 20/28] Take full `Services` in `BuildHalfEdge::unjoined` --- crates/fj-kernel/src/builder/cycle.rs | 2 +- crates/fj-kernel/src/operations/build/edge.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 60789fe07..8f0647211 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -37,7 +37,7 @@ impl CycleBuilder { .into_iter() .circular_tuple_windows() .map(|((prev, _, _), (half_edge, curve, boundary))| { - HalfEdge::unjoined(curve, boundary, &mut services.objects) + HalfEdge::unjoined(curve, boundary, services) .replace_start_vertex(prev.start_vertex().clone()) .replace_global_form(half_edge.global_form().clone()) }) diff --git a/crates/fj-kernel/src/operations/build/edge.rs b/crates/fj-kernel/src/operations/build/edge.rs index c9c36c04e..badd6c084 100644 --- a/crates/fj-kernel/src/operations/build/edge.rs +++ b/crates/fj-kernel/src/operations/build/edge.rs @@ -3,9 +3,9 @@ use fj_math::{Arc, Point, Scalar}; use crate::{ geometry::curve::Curve, - objects::{GlobalEdge, HalfEdge, Objects, Surface, Vertex}, + objects::{GlobalEdge, HalfEdge, Surface, Vertex}, operations::Insert, - services::{Service, Services}, + services::Services, }; /// Build a [`HalfEdge`] @@ -14,10 +14,10 @@ pub trait BuildHalfEdge { fn unjoined( curve: Curve, boundary: [Point<1>; 2], - objects: &mut Service, + services: &mut Services, ) -> HalfEdge { - let start_vertex = Vertex::new().insert(objects); - let global_form = GlobalEdge::new().insert(objects); + let start_vertex = Vertex::new().insert(&mut services.objects); + let global_form = GlobalEdge::new().insert(&mut services.objects); HalfEdge::new(curve, boundary, start_vertex, global_form) } @@ -45,7 +45,7 @@ pub trait BuildHalfEdge { let boundary = [arc.start_angle, arc.end_angle].map(|coord| Point::from([coord])); - HalfEdge::unjoined(curve, boundary, &mut services.objects) + HalfEdge::unjoined(curve, boundary, services) } /// Create a circle @@ -54,7 +54,7 @@ pub trait BuildHalfEdge { let boundary = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); - HalfEdge::unjoined(curve, boundary, &mut services.objects) + HalfEdge::unjoined(curve, boundary, services) } /// Create a line segment @@ -69,7 +69,7 @@ pub trait BuildHalfEdge { boundary.zip_ext(points_surface), ); - HalfEdge::unjoined(curve, boundary, &mut services.objects) + HalfEdge::unjoined(curve, boundary, services) } /// Create a line segment from global points From b47450068be076abe0f448a3bf51b8558727a214 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 21/28] Take full `Services` in `JoinCycle::join_to` --- .../fj-kernel/src/operations/build/shell.rs | 42 +++---------------- crates/fj-kernel/src/operations/join/cycle.rs | 15 +++---- 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/crates/fj-kernel/src/operations/build/shell.rs b/crates/fj-kernel/src/operations/build/shell.rs index f6071b866..b74328ad5 100644 --- a/crates/fj-kernel/src/operations/build/shell.rs +++ b/crates/fj-kernel/src/operations/build/shell.rs @@ -41,12 +41,7 @@ pub trait BuildShell { .face .update_exterior(|cycle| { cycle - .join_to( - abc.exterior(), - 0..=0, - 0..=0, - &mut services.objects, - ) + .join_to(abc.exterior(), 0..=0, 0..=0, services) .insert(&mut services.objects) }); let dac = @@ -54,18 +49,8 @@ pub trait BuildShell { .face .update_exterior(|cycle| { cycle - .join_to( - abc.exterior(), - 1..=1, - 2..=2, - &mut services.objects, - ) - .join_to( - bad.exterior(), - 0..=0, - 1..=1, - &mut services.objects, - ) + .join_to(abc.exterior(), 1..=1, 2..=2, services) + .join_to(bad.exterior(), 0..=0, 1..=1, services) .insert(&mut services.objects) }); let cbd = @@ -73,24 +58,9 @@ pub trait BuildShell { .face .update_exterior(|cycle| { cycle - .join_to( - abc.exterior(), - 0..=0, - 1..=1, - &mut services.objects, - ) - .join_to( - bad.exterior(), - 1..=1, - 2..=2, - &mut services.objects, - ) - .join_to( - dac.exterior(), - 2..=2, - 2..=2, - &mut services.objects, - ) + .join_to(abc.exterior(), 0..=0, 1..=1, services) + .join_to(bad.exterior(), 1..=1, 2..=2, services) + .join_to(dac.exterior(), 2..=2, 2..=2, services) .insert(&mut services.objects) }); diff --git a/crates/fj-kernel/src/operations/join/cycle.rs b/crates/fj-kernel/src/operations/join/cycle.rs index 6e579d57f..99b53afaa 100644 --- a/crates/fj-kernel/src/operations/join/cycle.rs +++ b/crates/fj-kernel/src/operations/join/cycle.rs @@ -1,9 +1,9 @@ use std::ops::RangeInclusive; use crate::{ - objects::{Cycle, Objects}, + objects::Cycle, operations::{Insert, UpdateCycle, UpdateHalfEdge}, - services::Service, + services::Services, }; /// Join a [`Cycle`] to another @@ -42,7 +42,7 @@ pub trait JoinCycle { other: &Cycle, range: RangeInclusive, other_range: RangeInclusive, - objects: &mut Service, + services: &mut Services, ) -> Self; } @@ -52,7 +52,7 @@ impl JoinCycle for Cycle { other: &Cycle, range: RangeInclusive, range_other: RangeInclusive, - objects: &mut Service, + services: &mut Services, ) -> Self { assert_eq!( range.end() - range.start(), @@ -86,9 +86,10 @@ impl JoinCycle for Cycle { let this_joined = half_edge .replace_start_vertex(vertex_a) .replace_global_form(half_edge_other.global_form().clone()) - .insert(objects); - let next_joined = - next_edge.replace_start_vertex(vertex_b).insert(objects); + .insert(&mut services.objects); + let next_joined = next_edge + .replace_start_vertex(vertex_b) + .insert(&mut services.objects); cycle = cycle .replace_half_edge(half_edge, this_joined) From dcfe94b9504d16f04095d12cdf30bfa5c46a23f0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 10:32:22 +0200 Subject: [PATCH 22/28] Take full `Services` in `Insert::insert` --- crates/fj-kernel/src/algorithms/approx/edge.rs | 4 ++-- crates/fj-kernel/src/algorithms/reverse/cycle.rs | 4 ++-- crates/fj-kernel/src/algorithms/reverse/face.rs | 2 +- crates/fj-kernel/src/algorithms/sweep/curve.rs | 3 +-- crates/fj-kernel/src/algorithms/sweep/edge.rs | 6 +++--- crates/fj-kernel/src/algorithms/sweep/face.rs | 8 ++++---- crates/fj-kernel/src/algorithms/sweep/sketch.rs | 2 +- crates/fj-kernel/src/algorithms/sweep/vertex.rs | 4 ++-- crates/fj-kernel/src/algorithms/transform/mod.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 2 +- crates/fj-kernel/src/builder/face.rs | 5 ++--- crates/fj-kernel/src/operations/build/edge.rs | 4 ++-- crates/fj-kernel/src/operations/build/face.rs | 8 +++----- crates/fj-kernel/src/operations/build/shell.rs | 9 ++++----- crates/fj-kernel/src/operations/insert.rs | 15 ++++++++------- crates/fj-kernel/src/operations/join/cycle.rs | 7 +++---- crates/fj-kernel/src/validate/cycle.rs | 4 ++-- crates/fj-kernel/src/validate/shell.rs | 8 ++++---- crates/fj-operations/src/difference_2d.rs | 4 ++-- crates/fj-operations/src/sketch.rs | 12 +++++------- crates/fj-operations/src/sweep.rs | 2 +- 21 files changed, 54 insertions(+), 61 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index ada576161..a52659fc0 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -290,7 +290,7 @@ mod tests { u: GlobalPath::circle_from_radius(1.), v: [0., 0., 1.].into(), }) - .insert(&mut services.objects); + .insert(&mut services); let half_edge = HalfEdge::line_segment([[1., 1.], [2., 1.]], None, &mut services); @@ -311,7 +311,7 @@ mod tests { u: path, v: [0., 0., 1.].into(), }) - .insert(&mut services.objects); + .insert(&mut services); let half_edge = HalfEdge::line_segment( [[0., 1.], [TAU, 1.]], Some(range.boundary), diff --git a/crates/fj-kernel/src/algorithms/reverse/cycle.rs b/crates/fj-kernel/src/algorithms/reverse/cycle.rs index 0a2025201..5bef5fa7f 100644 --- a/crates/fj-kernel/src/algorithms/reverse/cycle.rs +++ b/crates/fj-kernel/src/algorithms/reverse/cycle.rs @@ -27,12 +27,12 @@ impl Reverse for Handle { next.start_vertex().clone(), current.global_form().clone(), ) - .insert(&mut services.objects) + .insert(services) }) .collect::>(); edges.reverse(); - Cycle::new(edges).insert(&mut services.objects) + Cycle::new(edges).insert(services) } } diff --git a/crates/fj-kernel/src/algorithms/reverse/face.rs b/crates/fj-kernel/src/algorithms/reverse/face.rs index 307df617d..a12043af5 100644 --- a/crates/fj-kernel/src/algorithms/reverse/face.rs +++ b/crates/fj-kernel/src/algorithms/reverse/face.rs @@ -13,6 +13,6 @@ impl Reverse for Handle { .collect::>(); Face::new(self.surface().clone(), exterior, interiors, self.color()) - .insert(&mut services.objects) + .insert(services) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/curve.rs b/crates/fj-kernel/src/algorithms/sweep/curve.rs index 94cb55c89..b52516ee5 100644 --- a/crates/fj-kernel/src/algorithms/sweep/curve.rs +++ b/crates/fj-kernel/src/algorithms/sweep/curve.rs @@ -75,7 +75,6 @@ impl Sweep for (Curve, &Surface) { } }; - Surface::new(SurfaceGeometry { u, v: path.into() }) - .insert(&mut services.objects) + Surface::new(SurfaceGeometry { u, v: path.into() }).insert(services) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 16e665d80..1868d1eb8 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -91,7 +91,7 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { half_edge }; - half_edge.insert(&mut services.objects) + half_edge.insert(services) }; exterior = Some( @@ -106,14 +106,14 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { let face = Face::new( (edge.curve(), surface).sweep_with_cache(path, cache, services), - exterior.unwrap().insert(&mut services.objects), + exterior.unwrap().insert(services), Vec::new(), color, ); // And we're done creating the face! All that's left to do is build our // return values. - let face = face.insert(&mut services.objects); + let face = face.insert(services); (face, edge_top) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index cd7eb197a..47441023a 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -86,18 +86,18 @@ impl Sweep for Handle { .build(services); if i == 0 { - exterior = Some(top_cycle.insert(&mut services.objects)); + exterior = Some(top_cycle.insert(services)); } else { - interiors.push(top_cycle.insert(&mut services.objects)); + interiors.push(top_cycle.insert(services)); }; } let top_face = Face::new(top_surface, exterior.unwrap(), interiors, self.color()); - let top_face = top_face.insert(&mut services.objects); + let top_face = top_face.insert(services); faces.push(top_face); - Shell::new(faces).insert(&mut services.objects) + Shell::new(faces).insert(services) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/sketch.rs b/crates/fj-kernel/src/algorithms/sweep/sketch.rs index 04d30da21..4e8fb5789 100644 --- a/crates/fj-kernel/src/algorithms/sweep/sketch.rs +++ b/crates/fj-kernel/src/algorithms/sweep/sketch.rs @@ -26,6 +26,6 @@ impl Sweep for Handle { shells.push(shell); } - Solid::new(shells).insert(&mut services.objects) + Solid::new(shells).insert(services) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 66416410a..bb4ad6ba0 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -22,14 +22,14 @@ impl Sweep for Handle { let b = cache .global_vertex .entry(self.id()) - .or_insert_with(|| Vertex::new().insert(&mut services.objects)) + .or_insert_with(|| Vertex::new().insert(services)) .clone(); let vertices = [a, b]; let global_edge = cache .global_edge .entry(self.id()) - .or_insert_with(|| GlobalEdge::new().insert(&mut services.objects)) + .or_insert_with(|| GlobalEdge::new().insert(services)) .clone(); // The vertices of the returned `GlobalEdge` are in normalized order, diff --git a/crates/fj-kernel/src/algorithms/transform/mod.rs b/crates/fj-kernel/src/algorithms/transform/mod.rs index 5cf7a73ea..c61c5234e 100644 --- a/crates/fj-kernel/src/algorithms/transform/mod.rs +++ b/crates/fj-kernel/src/algorithms/transform/mod.rs @@ -84,7 +84,7 @@ where let transformed = self .clone_object() .transform_with_cache(transform, services, cache) - .insert(&mut services.objects); + .insert(services); cache.insert(self.clone(), transformed.clone()); diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 8f0647211..c0a848daf 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -70,7 +70,7 @@ impl CycleBuilder { let half_edges = self .half_edges .into_iter() - .map(|half_edge| half_edge.insert(&mut services.objects)); + .map(|half_edge| half_edge.insert(services)); Cycle::new(half_edges) } } diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 285f0d82e..7dd955e9c 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -47,12 +47,11 @@ impl FaceBuilder { /// Build the face pub fn build(self, services: &mut Services) -> Face { - let exterior = - self.exterior.build(services).insert(&mut services.objects); + let exterior = self.exterior.build(services).insert(services); let interiors = self .interiors .into_iter() - .map(|cycle| cycle.build(services).insert(&mut services.objects)); + .map(|cycle| cycle.build(services).insert(services)); Face::new(self.surface, exterior, interiors, self.color) } diff --git a/crates/fj-kernel/src/operations/build/edge.rs b/crates/fj-kernel/src/operations/build/edge.rs index badd6c084..c2fd80032 100644 --- a/crates/fj-kernel/src/operations/build/edge.rs +++ b/crates/fj-kernel/src/operations/build/edge.rs @@ -16,8 +16,8 @@ pub trait BuildHalfEdge { boundary: [Point<1>; 2], services: &mut Services, ) -> HalfEdge { - let start_vertex = Vertex::new().insert(&mut services.objects); - let global_form = GlobalEdge::new().insert(&mut services.objects); + let start_vertex = Vertex::new().insert(services); + let global_form = GlobalEdge::new().insert(services); HalfEdge::new(curve, boundary, start_vertex, global_form) } diff --git a/crates/fj-kernel/src/operations/build/face.rs b/crates/fj-kernel/src/operations/build/face.rs index 0f363f3da..047b1232a 100644 --- a/crates/fj-kernel/src/operations/build/face.rs +++ b/crates/fj-kernel/src/operations/build/face.rs @@ -19,22 +19,20 @@ pub trait BuildFace { ) -> Polygon<3> { let [a, b, c] = points.map(Into::into); - let surface = - Surface::plane_from_points([a, b, c]).insert(&mut services.objects); + let surface = Surface::plane_from_points([a, b, c]).insert(services); let (exterior, edges, vertices) = { let half_edges = [[a, b], [b, c], [c, a]].map(|points| { let half_edge = HalfEdge::line_segment_from_global_points( points, &surface, None, services, ); - half_edge.insert(&mut services.objects) + half_edge.insert(services) }); let vertices = half_edges .each_ref_ext() .map(|half_edge| half_edge.start_vertex().clone()); - let cycle = - Cycle::new(half_edges.clone()).insert(&mut services.objects); + let cycle = Cycle::new(half_edges.clone()).insert(services); (cycle, half_edges, vertices) }; diff --git a/crates/fj-kernel/src/operations/build/shell.rs b/crates/fj-kernel/src/operations/build/shell.rs index b74328ad5..24cea846b 100644 --- a/crates/fj-kernel/src/operations/build/shell.rs +++ b/crates/fj-kernel/src/operations/build/shell.rs @@ -42,7 +42,7 @@ pub trait BuildShell { .update_exterior(|cycle| { cycle .join_to(abc.exterior(), 0..=0, 0..=0, services) - .insert(&mut services.objects) + .insert(services) }); let dac = Face::triangle([d, a, c], services) @@ -51,7 +51,7 @@ pub trait BuildShell { cycle .join_to(abc.exterior(), 1..=1, 2..=2, services) .join_to(bad.exterior(), 0..=0, 1..=1, services) - .insert(&mut services.objects) + .insert(services) }); let cbd = Face::triangle([c, b, d], services) @@ -61,11 +61,10 @@ pub trait BuildShell { .join_to(abc.exterior(), 0..=0, 1..=1, services) .join_to(bad.exterior(), 1..=1, 2..=2, services) .join_to(dac.exterior(), 2..=2, 2..=2, services) - .insert(&mut services.objects) + .insert(services) }); - let faces = - [abc, bad, dac, cbd].map(|face| face.insert(&mut services.objects)); + let faces = [abc, bad, dac, cbd].map(|face| face.insert(services)); let shell = Shell::new(faces.clone()); let [abc, bad, dac, cbd] = faces; diff --git a/crates/fj-kernel/src/operations/insert.rs b/crates/fj-kernel/src/operations/insert.rs index ee1c77bf3..f62b35ebd 100644 --- a/crates/fj-kernel/src/operations/insert.rs +++ b/crates/fj-kernel/src/operations/insert.rs @@ -1,9 +1,9 @@ use crate::{ objects::{ - Cycle, Face, GlobalEdge, HalfEdge, Objects, Shell, Sketch, Solid, - Surface, Vertex, + Cycle, Face, GlobalEdge, HalfEdge, Shell, Sketch, Solid, Surface, + Vertex, }, - services::{Operation, Service}, + services::{Operation, Services}, storage::Handle, }; @@ -13,18 +13,19 @@ use crate::{ /// `Service`. All other operations are built on top of it. pub trait Insert: Sized { /// Insert the object into its respective store - fn insert(self, objects: &mut Service) -> Handle; + fn insert(self, services: &mut Services) -> Handle; } macro_rules! impl_insert { ($($ty:ty, $store:ident;)*) => { $( impl Insert for $ty { - fn insert(self, objects: &mut Service) -> Handle + fn insert(self, services: &mut Services,) -> Handle { - let handle = objects.$store.reserve(); + let handle = services.objects.$store.reserve(); let object = (handle.clone(), self).into(); - objects.execute(Operation::InsertObject { object }); + services.objects + .execute(Operation::InsertObject { object }); handle } } diff --git a/crates/fj-kernel/src/operations/join/cycle.rs b/crates/fj-kernel/src/operations/join/cycle.rs index 99b53afaa..52b6ddb4f 100644 --- a/crates/fj-kernel/src/operations/join/cycle.rs +++ b/crates/fj-kernel/src/operations/join/cycle.rs @@ -86,10 +86,9 @@ impl JoinCycle for Cycle { let this_joined = half_edge .replace_start_vertex(vertex_a) .replace_global_form(half_edge_other.global_form().clone()) - .insert(&mut services.objects); - let next_joined = next_edge - .replace_start_vertex(vertex_b) - .insert(&mut services.objects); + .insert(services); + let next_joined = + next_edge.replace_start_vertex(vertex_b).insert(services); cycle = cycle .replace_half_edge(half_edge, this_joined) diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index 67adc1fdc..599df865a 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -128,8 +128,8 @@ mod tests { &mut services, ), ]; - let half_edges = half_edges - .map(|half_edge| half_edge.insert(&mut services.objects)); + let half_edges = + half_edges.map(|half_edge| half_edge.insert(&mut services)); Cycle::empty().add_half_edges(half_edges) }; diff --git a/crates/fj-kernel/src/validate/shell.rs b/crates/fj-kernel/src/validate/shell.rs index 607a8a44b..ed5d214b6 100644 --- a/crates/fj-kernel/src/validate/shell.rs +++ b/crates/fj-kernel/src/validate/shell.rs @@ -215,14 +215,14 @@ mod tests { cycle .update_nth_half_edge(0, |half_edge| { let global_form = - GlobalEdge::new().insert(&mut services.objects); + GlobalEdge::new().insert(&mut services); half_edge .replace_global_form(global_form) - .insert(&mut services.objects) + .insert(&mut services) }) - .insert(&mut services.objects) + .insert(&mut services) }) - .insert(&mut services.objects) + .insert(&mut services) }); valid.shell.validate_and_return_first_error()?; diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 4bf32f6a1..ad501f0d9 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -83,10 +83,10 @@ impl Shape for fj::Difference2d { interiors, Some(Color(self.color())), ); - faces.push(face.insert(&mut services.objects)); + faces.push(face.insert(services)); } - let difference = Sketch::new(faces).insert(&mut services.objects); + let difference = Sketch::new(faces).insert(services); difference.deref().clone() } diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 82628e6a4..35b097ae3 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -24,9 +24,8 @@ impl Shape for fj::Sketch { let face = match self.chain() { fj::Chain::Circle(circle) => { let half_edge = HalfEdge::circle(circle.radius(), services) - .insert(&mut services.objects); - let exterior = - Cycle::new([half_edge]).insert(&mut services.objects); + .insert(services); + let exterior = Cycle::new([half_edge]).insert(services); Face::new( surface, @@ -67,12 +66,12 @@ impl Shape for fj::Sketch { HalfEdge::arc(start, end, angle.rad(), services) } }; - let half_edge = half_edge.insert(&mut services.objects); + let half_edge = half_edge.insert(services); cycle = cycle.add_half_edges([half_edge]); } - cycle.insert(&mut services.objects) + cycle.insert(services) }; Face::new( @@ -84,8 +83,7 @@ impl Shape for fj::Sketch { } }; - let sketch = Sketch::new(vec![face.insert(&mut services.objects)]) - .insert(&mut services.objects); + let sketch = Sketch::new(vec![face.insert(services)]).insert(services); sketch.deref().clone() } diff --git a/crates/fj-operations/src/sweep.rs b/crates/fj-operations/src/sweep.rs index 701617bd9..ea32ea7d8 100644 --- a/crates/fj-operations/src/sweep.rs +++ b/crates/fj-operations/src/sweep.rs @@ -20,7 +20,7 @@ impl Shape for fj::Sweep { let sketch = self .shape() .compute_brep(services, debug_info) - .insert(&mut services.objects); + .insert(services); let path = Vector::from(self.path()); From 9e32ee3a681dec9c0e6987e0882a76328590f51e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 11:21:38 +0200 Subject: [PATCH 23/28] Update formatting --- crates/fj-kernel/src/operations/insert.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/operations/insert.rs b/crates/fj-kernel/src/operations/insert.rs index f62b35ebd..7b5242693 100644 --- a/crates/fj-kernel/src/operations/insert.rs +++ b/crates/fj-kernel/src/operations/insert.rs @@ -20,8 +20,7 @@ macro_rules! impl_insert { ($($ty:ty, $store:ident;)*) => { $( impl Insert for $ty { - fn insert(self, services: &mut Services,) -> Handle - { + fn insert(self, services: &mut Services) -> Handle { let handle = services.objects.$store.reserve(); let object = (handle.clone(), self).into(); services.objects From 8ccc7906a790a611089974bd74f1fd0d05abba47 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 11:24:33 +0200 Subject: [PATCH 24/28] Add `Services::insert_object` This is preparation for simplifying services subscriptions. --- crates/fj-kernel/src/operations/insert.rs | 5 ++--- crates/fj-kernel/src/services/mod.rs | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/operations/insert.rs b/crates/fj-kernel/src/operations/insert.rs index 7b5242693..fc98e5273 100644 --- a/crates/fj-kernel/src/operations/insert.rs +++ b/crates/fj-kernel/src/operations/insert.rs @@ -3,7 +3,7 @@ use crate::{ Cycle, Face, GlobalEdge, HalfEdge, Shell, Sketch, Solid, Surface, Vertex, }, - services::{Operation, Services}, + services::Services, storage::Handle, }; @@ -23,8 +23,7 @@ macro_rules! impl_insert { fn insert(self, services: &mut Services) -> Handle { let handle = services.objects.$store.reserve(); let object = (handle.clone(), self).into(); - services.objects - .execute(Operation::InsertObject { object }); + services.insert_object(object); handle } } diff --git a/crates/fj-kernel/src/services/mod.rs b/crates/fj-kernel/src/services/mod.rs index d40d4a825..08ffae249 100644 --- a/crates/fj-kernel/src/services/mod.rs +++ b/crates/fj-kernel/src/services/mod.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use parking_lot::Mutex; -use crate::objects::Objects; +use crate::objects::{Object, Objects, WithHandle}; pub use self::{ objects::{InsertObject, Operation}, @@ -44,6 +44,11 @@ impl Services { validation, } } + + /// Insert an object into the stores + pub fn insert_object(&mut self, object: Object) { + self.objects.execute(Operation::InsertObject { object }); + } } impl Default for Services { From 4ea1495bb18c2bf0080cb7884dda73b05b82f6ca Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 11:40:48 +0200 Subject: [PATCH 25/28] Don't store service events Eventually, this will be needed to display history in the app. But for now, it's not being used, and it's getting in the way of other changes I'm making. It can be re-added later, as needed, and then, it'll hopefully be clearer how to better integrate it with the rest of the design. --- crates/fj-kernel/src/services/service.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/crates/fj-kernel/src/services/service.rs b/crates/fj-kernel/src/services/service.rs index b03e6f09f..8de910bfc 100644 --- a/crates/fj-kernel/src/services/service.rs +++ b/crates/fj-kernel/src/services/service.rs @@ -23,7 +23,6 @@ use parking_lot::Mutex; /// pub struct Service { state: S, - events: Vec, subscribers: Vec>>>, } @@ -32,7 +31,6 @@ impl Service { pub fn new(state: S) -> Self { Self { state, - events: Vec::new(), subscribers: Vec::new(), } } @@ -61,13 +59,6 @@ impl Service { subscriber.handle_event(event); } } - - self.events.extend(events); - } - - /// Access the events - pub fn events(&self) -> impl Iterator { - self.events.iter() } /// Replay the provided events on the given state From f0b2008ccdd924c0ffdaa9854f5556ac7e153fc7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 11:42:42 +0200 Subject: [PATCH 26/28] Refactor to prepare for follow-on change --- crates/fj-kernel/src/services/mod.rs | 4 +++- crates/fj-kernel/src/services/service.rs | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/services/mod.rs b/crates/fj-kernel/src/services/mod.rs index 08ffae249..baacee2b6 100644 --- a/crates/fj-kernel/src/services/mod.rs +++ b/crates/fj-kernel/src/services/mod.rs @@ -47,7 +47,9 @@ impl Services { /// Insert an object into the stores pub fn insert_object(&mut self, object: Object) { - self.objects.execute(Operation::InsertObject { object }); + let mut object_events = Vec::new(); + self.objects + .execute(Operation::InsertObject { object }, &mut object_events); } } diff --git a/crates/fj-kernel/src/services/service.rs b/crates/fj-kernel/src/services/service.rs index 8de910bfc..623115269 100644 --- a/crates/fj-kernel/src/services/service.rs +++ b/crates/fj-kernel/src/services/service.rs @@ -47,11 +47,10 @@ impl Service { /// /// The command is executed synchronously. When this method returns, the /// state has been updated and any events have been logged. - pub fn execute(&mut self, command: S::Command) { - let mut events = Vec::new(); - self.state.decide(command, &mut events); + pub fn execute(&mut self, command: S::Command, events: &mut Vec) { + self.state.decide(command, events); - for event in &events { + for event in events { self.state.evolve(event); for subscriber in &self.subscribers { @@ -96,7 +95,7 @@ where S::Command: Clone, { fn handle_event(&mut self, event: &S::Command) { - self.execute(event.clone()); + self.execute(event.clone(), &mut Vec::new()); } } From e14393c1f4ed336c0377ef872b5060990df0c854 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 11:46:26 +0200 Subject: [PATCH 27/28] Simplify service subscription --- crates/fj-kernel/src/services/mod.rs | 10 +++++-- crates/fj-kernel/src/services/service.rs | 36 ++---------------------- 2 files changed, 9 insertions(+), 37 deletions(-) diff --git a/crates/fj-kernel/src/services/mod.rs b/crates/fj-kernel/src/services/mod.rs index baacee2b6..951da1f33 100644 --- a/crates/fj-kernel/src/services/mod.rs +++ b/crates/fj-kernel/src/services/mod.rs @@ -34,11 +34,9 @@ pub struct Services { impl Services { /// Construct an instance of `Services` pub fn new() -> Self { - let mut objects = Service::::default(); + let objects = Service::::default(); let validation = Arc::new(Mutex::new(Service::default())); - objects.subscribe(validation.clone()); - Self { objects, validation, @@ -50,6 +48,12 @@ impl Services { let mut object_events = Vec::new(); self.objects .execute(Operation::InsertObject { object }, &mut object_events); + + for object_event in object_events { + self.validation + .lock() + .execute(object_event, &mut Vec::new()); + } } } diff --git a/crates/fj-kernel/src/services/service.rs b/crates/fj-kernel/src/services/service.rs index 623115269..4317fa61d 100644 --- a/crates/fj-kernel/src/services/service.rs +++ b/crates/fj-kernel/src/services/service.rs @@ -1,6 +1,4 @@ -use std::{ops::Deref, sync::Arc}; - -use parking_lot::Mutex; +use std::ops::Deref; /// A service that controls access to some state /// @@ -23,24 +21,12 @@ use parking_lot::Mutex; /// pub struct Service { state: S, - subscribers: Vec>>>, } impl Service { /// Create an instance of `Service` pub fn new(state: S) -> Self { - Self { - state, - subscribers: Vec::new(), - } - } - - /// Add a subscriber - pub fn subscribe( - &mut self, - subscriber: Arc>>, - ) { - self.subscribers.push(subscriber); + Self { state } } /// Execute a command @@ -52,11 +38,6 @@ impl Service { for event in events { self.state.evolve(event); - - for subscriber in &self.subscribers { - let mut subscriber = subscriber.lock(); - subscriber.handle_event(event); - } } } @@ -90,15 +71,6 @@ where } } -impl Subscriber for Service -where - S::Command: Clone, -{ - fn handle_event(&mut self, event: &S::Command) { - self.execute(event.clone(), &mut Vec::new()); - } -} - /// Implemented for state that can be wrapped by a [`Service`] /// /// See [`Service`] for a detailed explanation. @@ -130,7 +102,3 @@ pub trait State { /// [`State::decide`], and encoded into the event. fn evolve(&mut self, event: &Self::Event); } - -pub trait Subscriber { - fn handle_event(&mut self, event: &T); -} From 36e698dcfeb56fd5d7a1e238b9da37717d047a33 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 26 Apr 2023 11:48:50 +0200 Subject: [PATCH 28/28] Simplify storage of validation service The complexity is no longer needed, thanks to the simplified subscription model. --- crates/fj-kernel/src/services/mod.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/services/mod.rs b/crates/fj-kernel/src/services/mod.rs index 951da1f33..561a5acfc 100644 --- a/crates/fj-kernel/src/services/mod.rs +++ b/crates/fj-kernel/src/services/mod.rs @@ -6,10 +6,6 @@ mod objects; mod service; mod validation; -use std::sync::Arc; - -use parking_lot::Mutex; - use crate::objects::{Object, Objects, WithHandle}; pub use self::{ @@ -28,14 +24,14 @@ pub struct Services { /// The validation service /// /// Validates objects that are inserted using the objects service. - pub validation: Arc>>, + pub validation: Service, } impl Services { /// Construct an instance of `Services` pub fn new() -> Self { let objects = Service::::default(); - let validation = Arc::new(Mutex::new(Service::default())); + let validation = Service::default(); Self { objects, @@ -50,9 +46,7 @@ impl Services { .execute(Operation::InsertObject { object }, &mut object_events); for object_event in object_events { - self.validation - .lock() - .execute(object_event, &mut Vec::new()); + self.validation.execute(object_event, &mut Vec::new()); } } }