diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 2dfdbbf1e..a52659fc0 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); @@ -293,12 +290,9 @@ mod tests { u: GlobalPath::circle_from_radius(1.), v: [0., 0., 1.].into(), }) - .insert(&mut services.objects); - let half_edge = HalfEdge::line_segment( - [[1., 1.], [2., 1.]], - None, - &mut services.objects, - ); + .insert(&mut services); + let half_edge = + HalfEdge::line_segment([[1., 1.], [2., 1.]], None, &mut services); let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); @@ -317,11 +311,11 @@ 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), - &mut services.objects, + &mut services, ); let tolerance = 1.; @@ -346,7 +340,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/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/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 4ff2c6c08..856f76b29 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -181,13 +181,13 @@ 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); + .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 dbee4285e..931af8fc8 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -86,11 +86,8 @@ mod tests { ] .map(|surface| { FaceBuilder::new(surface) - .with_exterior(CycleBuilder::polygon( - points, - &mut services.objects, - )) - .build(&mut services.objects) + .with_exterior(CycleBuilder::polygon(points, &mut services)) + .build(&mut services) }); let intersection = FaceFaceIntersection::compute([&a, &b]); @@ -115,11 +112,8 @@ mod tests { ]; let [a, b] = surfaces.clone().map(|surface| { FaceBuilder::new(surface) - .with_exterior(CycleBuilder::polygon( - points, - &mut services.objects, - )) - .build(&mut services.objects) + .with_exterior(CycleBuilder::polygon(points, &mut services)) + .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 5f8c9202b..109543316 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -149,9 +149,9 @@ 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); + .build(&mut services); let point = Point::from([2., 1.]); let intersection = (&face, &point).intersect(); @@ -165,9 +165,9 @@ 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); + .build(&mut services); let point = Point::from([1., 1.]); let intersection = (&face, &point).intersect(); @@ -184,9 +184,9 @@ 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); + .build(&mut services); let point = Point::from([1., 2.]); let intersection = (&face, &point).intersect(); @@ -203,9 +203,9 @@ 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); + .build(&mut services); let point = Point::from([1., 1.]); let intersection = (&face, &point).intersect(); @@ -222,9 +222,9 @@ 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); + .build(&mut services); let point = Point::from([1., 1.]); let intersection = (&face, &point).intersect(); @@ -241,9 +241,9 @@ 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); + .build(&mut services); let point = Point::from([1., 1.]); let intersection = (&face, &point).intersect(); @@ -260,9 +260,9 @@ 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); + .build(&mut services); let point = Point::from([1., 0.]); let intersection = (&face, &point).intersect(); @@ -285,9 +285,9 @@ 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); + .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 837529f7e..97afca4f5 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -165,10 +165,10 @@ 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.objects); + .build(&mut services); + let face = face.translate([-1., 0., 0.], &mut services); assert_eq!((&ray, &face).intersect(), None); } @@ -182,10 +182,10 @@ 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.objects); + .build(&mut services); + let face = face.translate([1., 0., 0.], &mut services); assert_eq!( (&ray, &face).intersect(), @@ -202,10 +202,10 @@ 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.objects); + .build(&mut services); + let face = face.translate([0., 0., 2.], &mut services); assert_eq!((&ray, &face).intersect(), None); } @@ -219,10 +219,10 @@ 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.objects); + .build(&mut services); + let face = face.translate([1., 1., 0.], &mut services); let edge = face .exterior() @@ -244,10 +244,10 @@ 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.objects); + .build(&mut services); + let face = face.translate([1., 1., 1.], &mut services); let vertex = face .exterior() @@ -272,9 +272,9 @@ 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); + .build(&mut services); assert_eq!( (&ray, &face).intersect(), @@ -291,10 +291,10 @@ 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.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/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/reverse/cycle.rs b/crates/fj-kernel/src/algorithms/reverse/cycle.rs index 0a8338bf6..5bef5fa7f 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(services) }) .collect::>(); edges.reverse(); - Cycle::new(edges).insert(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 9d486855f..a12043af5 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(services) } } 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/curve.rs b/crates/fj-kernel/src/algorithms/sweep/curve.rs index 31cf95793..b52516ee5 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,6 @@ impl Sweep for (Curve, &Surface) { } }; - Surface::new(SurfaceGeometry { u, v: path.into() }).insert(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 7b785e5a8..1868d1eb8 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, + services, ) .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(services) }; 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(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(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 26dddd24e..47441023a 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,19 @@ impl Sweep for Handle { if is_negative_sweep { self.clone() } else { - self.clone().reverse(objects) + self.clone().reverse(services) } }; faces.push(bottom_face.clone()); let top_surface = - bottom_face.surface().clone().translate(path, objects); + bottom_face.surface().clone().translate(path, services); 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(services); let mut top_edges = Vec::new(); for (half_edge, next) in @@ -71,7 +71,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 +82,22 @@ 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, services) + .build(services); if i == 0 { - exterior = Some(top_cycle.insert(objects)); + exterior = Some(top_cycle.insert(services)); } else { - interiors.push(top_cycle.insert(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(objects); + let top_face = top_face.insert(services); faces.push(top_face); - Shell::new(faces).insert(objects) + Shell::new(faces).insert(services) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/mod.rs b/crates/fj-kernel/src/algorithms/sweep/mod.rs index 6cdc14430..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, + objects::{GlobalEdge, Vertex}, + services::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, 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..4e8fb5789 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(services) } } diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 44d98010b..bb4ad6ba0 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(services)) .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(services)) .clone(); // The vertices of the returned `GlobalEdge` are in normalized order, 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 e00d029bb..c61c5234e 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, storage::{Handle, ObjectId}, }; @@ -32,20 +31,16 @@ 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, 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; @@ -55,9 +50,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), services) } /// Rotate the object @@ -66,9 +61,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), services) } } @@ -79,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) { @@ -88,8 +83,8 @@ where let transformed = self .clone_object() - .transform_with_cache(transform, objects, cache) - .insert(objects); + .transform_with_cache(transform, services, cache) + .insert(services); 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 diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 18889bb75..7e8f5b731 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -96,11 +96,8 @@ 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, - )) - .build(&mut services.objects); + .with_exterior(CycleBuilder::polygon([a, b, c, d], &mut services)) + .build(&mut services); let a = Point::from(a).to_xyz(); let b = Point::from(b).to_xyz(); @@ -134,15 +131,9 @@ 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, - )) - .build(&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); let triangles = triangulate(face)?; @@ -200,9 +191,9 @@ 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); + .build(&mut services); let triangles = triangulate(face)?; diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 3fff2c6b4..c0a848daf 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, 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, services) .replace_start_vertex(prev.start_vertex().clone()) .replace_global_form(half_edge.global_form().clone()) }) @@ -50,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, @@ -61,7 +58,7 @@ impl CycleBuilder { .map(Into::into) .circular_tuple_windows() .map(|(start, end)| { - HalfEdge::line_segment([start, end], None, objects) + HalfEdge::line_segment([start, end], None, services) }) .collect(); @@ -69,11 +66,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(services)); Cycle::new(half_edges) } } diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 3dc980233..7dd955e9c 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,12 @@ impl FaceBuilder { } /// Build the face - pub fn build(self, objects: &mut Service) -> Face { - let exterior = self.exterior.build(objects).insert(objects); + pub fn build(self, services: &mut Services) -> Face { + let exterior = self.exterior.build(services).insert(services); let interiors = self .interiors .into_iter() - .map(|cycle| cycle.build(objects).insert(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 cacd54cda..c2fd80032 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, }; /// 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(services); + let global_form = GlobalEdge::new().insert(services); HalfEdge::new(curve, boundary, start_vertex, global_form) } @@ -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,26 +45,23 @@ 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, services) } /// 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, services) } /// Create a line segment 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)); @@ -72,7 +69,7 @@ pub trait BuildHalfEdge { boundary.zip_ext(points_surface), ); - HalfEdge::unjoined(curve, boundary, objects) + HalfEdge::unjoined(curve, boundary, services) } /// Create a line segment from global points @@ -80,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, services) } } diff --git a/crates/fj-kernel/src/operations/build/face.rs b/crates/fj-kernel/src/operations/build/face.rs index d83536c88..047b1232a 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,24 @@ 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(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, objects, + points, &surface, None, services, ); - half_edge.insert(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(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 0f2628921..24cea846b 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,40 @@ 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 abc = Face::triangle([a, b, c], services).face; let bad = - Face::triangle([b, a, d], objects) + Face::triangle([b, a, d], services) .face .update_exterior(|cycle| { cycle - .join_to(abc.exterior(), 0..=0, 0..=0, objects) - .insert(objects) + .join_to(abc.exterior(), 0..=0, 0..=0, services) + .insert(services) }); let dac = - Face::triangle([d, a, c], objects) + Face::triangle([d, a, c], services) .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) + .join_to(abc.exterior(), 1..=1, 2..=2, services) + .join_to(bad.exterior(), 0..=0, 1..=1, services) + .insert(services) }); let cbd = - Face::triangle([c, b, d], objects) + Face::triangle([c, b, d], services) .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) + .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(services) }); - let faces = [abc, bad, dac, cbd].map(|face| face.insert(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..fc98e5273 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::Services, storage::Handle, }; @@ -13,18 +13,17 @@ 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 - { - let handle = objects.$store.reserve(); + fn insert(self, services: &mut Services) -> Handle { + let handle = services.objects.$store.reserve(); let object = (handle.clone(), self).into(); - objects.execute(Operation::InsertObject { object }); + services.insert_object(object); handle } } diff --git a/crates/fj-kernel/src/operations/join/cycle.rs b/crates/fj-kernel/src/operations/join/cycle.rs index 6e579d57f..52b6ddb4f 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,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(objects); + .insert(services); let next_joined = - next_edge.replace_start_vertex(vertex_b).insert(objects); + 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/services/mod.rs b/crates/fj-kernel/src/services/mod.rs index d40d4a825..561a5acfc 100644 --- a/crates/fj-kernel/src/services/mod.rs +++ b/crates/fj-kernel/src/services/mod.rs @@ -6,11 +6,7 @@ mod objects; mod service; mod validation; -use std::sync::Arc; - -use parking_lot::Mutex; - -use crate::objects::Objects; +use crate::objects::{Object, Objects, WithHandle}; pub use self::{ objects::{InsertObject, Operation}, @@ -28,22 +24,31 @@ 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 mut objects = Service::::default(); - let validation = Arc::new(Mutex::new(Service::default())); - - objects.subscribe(validation.clone()); + let objects = Service::::default(); + let validation = Service::default(); Self { objects, validation, } } + + /// Insert an object into the stores + pub fn insert_object(&mut self, object: Object) { + let mut object_events = Vec::new(); + self.objects + .execute(Operation::InsertObject { object }, &mut object_events); + + for object_event in object_events { + self.validation.execute(object_event, &mut Vec::new()); + } + } } impl Default for Services { diff --git a/crates/fj-kernel/src/services/service.rs b/crates/fj-kernel/src/services/service.rs index b03e6f09f..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,51 +21,24 @@ use parking_lot::Mutex; /// pub struct Service { state: S, - events: Vec, - subscribers: Vec>>>, } impl Service { /// Create an instance of `Service` pub fn new(state: S) -> Self { - Self { - state, - events: Vec::new(), - subscribers: Vec::new(), - } - } - - /// Add a subscriber - pub fn subscribe( - &mut self, - subscriber: Arc>>, - ) { - self.subscribers.push(subscriber); + Self { state } } /// Execute a command /// /// 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 { - let mut subscriber = subscriber.lock(); - 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 @@ -100,15 +71,6 @@ where } } -impl Subscriber for Service -where - S::Command: Clone, -{ - fn handle_event(&mut self, event: &S::Command) { - self.execute(event.clone()); - } -} - /// Implemented for state that can be wrapped by a [`Service`] /// /// See [`Service`] for a detailed explanation. @@ -140,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); -} diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index b1ae299d7..599df865a 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -109,9 +109,9 @@ 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); + .build(&mut services); valid.validate_and_return_first_error()?; @@ -120,16 +120,16 @@ 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 - .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/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-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 1dc0c8be1..7b45fd64a 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -86,18 +86,18 @@ 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); + .build(&mut services); let invalid = { 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-kernel/src/validate/shell.rs b/crates/fj-kernel/src/validate/shell.rs index d9c557ad5..ed5d214b6 100644 --- a/crates/fj-kernel/src/validate/shell.rs +++ b/crates/fj-kernel/src/validate/shell.rs @@ -208,21 +208,21 @@ 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| { 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()?; @@ -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); diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 7fd07ff5f..ad501f0d9 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,7 @@ 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(services)); } } @@ -57,7 +57,7 @@ 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(services)); } // Faces only support one exterior, while the code here comes from @@ -83,10 +83,10 @@ impl Shape for fj::Difference2d { interiors, Some(Color(self.color())), ); - faces.push(face.insert(objects)); + faces.push(face.insert(services)); } - let difference = Sketch::new(faces).insert(objects); + let difference = Sketch::new(faces).insert(services); 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..35b097ae3 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,16 @@ 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); + let half_edge = HalfEdge::circle(circle.radius(), services) + .insert(services); + let exterior = Cycle::new([half_edge]).insert(services); Face::new( surface, @@ -59,19 +59,19 @@ impl Shape for fj::Sketch { HalfEdge::line_segment( [start, end], None, - objects, + services, ) } fj::SketchSegmentRoute::Arc { angle } => { - HalfEdge::arc(start, end, angle.rad(), objects) + HalfEdge::arc(start, end, angle.rad(), services) } }; - let half_edge = half_edge.insert(objects); + let half_edge = half_edge.insert(services); cycle = cycle.add_half_edges([half_edge]); } - cycle.insert(objects) + cycle.insert(services) }; Face::new( @@ -83,7 +83,7 @@ impl Shape for fj::Sketch { } }; - let sketch = Sketch::new(vec![face.insert(objects)]).insert(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 21ccf566e..ea32ea7d8 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,17 @@ 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) + .insert(services); let path = Vector::from(self.path()); - let solid = sketch.sweep(path, objects); + let solid = sketch.sweep(path, services); solid.deref().clone() } diff --git a/crates/fj-operations/src/transform.rs b/crates/fj-operations/src/transform.rs index 48890ee77..e97306818 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), services) } fn bounding_volume(&self) -> Aabb<3> {