diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index a27eb150c..524124d4c 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -153,6 +153,7 @@ mod tests { builder::{CycleBuilder, FaceBuilder}, geometry::curve::Curve, insert::Insert, + objects::Cycle, partial::{PartialFace, PartialObject}, services::Services, }; @@ -193,13 +194,12 @@ mod tests { face.exterior = exterior.insert(&mut services.objects); } { - let mut interior = face.add_interior(&mut services.objects); - let (updated, _) = - interior.read().clone().update_as_polygon_from_points( + let (interior, _) = Cycle::new([]) + .update_as_polygon_from_points( interior_points, &mut services.objects, ); - *interior.write() = updated; + face.add_interior(interior, &mut services.objects); } face.build(&mut services.objects) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 77dd034c7..ff289f5d7 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -8,10 +8,8 @@ use crate::{ builder::{CycleBuilder, FaceBuilder}, geometry::curve::GlobalPath, insert::Insert, - objects::{Face, Objects, Shell}, - partial::{ - Partial, PartialCycle, PartialFace, PartialObject, PartialShell, - }, + objects::{Cycle, Face, Objects, Shell}, + partial::{Partial, PartialFace, PartialObject, PartialShell}, services::Service, storage::Handle, }; @@ -87,13 +85,12 @@ impl Sweep for Handle { } let (top_cycle, _) = - PartialCycle::new(objects).connect_to_edges(top_edges, objects); + Cycle::new([]).connect_to_edges(top_edges, objects); if i == 0 { - top_face.exterior = top_cycle.build(objects).insert(objects); + top_face.exterior = top_cycle.insert(objects); } else { - let mut interior = top_face.add_interior(objects); - *interior.write() = top_cycle; + top_face.add_interior(top_cycle, objects); }; } diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index fadbb4b6c..a65acf51e 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -79,7 +79,7 @@ mod tests { algorithms::approx::{Approx, Tolerance}, builder::{CycleBuilder, FaceBuilder}, insert::Insert, - objects::Face, + objects::{Cycle, Face}, partial::{PartialFace, PartialObject}, services::Services, storage::Handle, @@ -152,13 +152,11 @@ mod tests { face.exterior = exterior.insert(&mut services.objects); } { - let mut interior = face.add_interior(&mut services.objects); - let (updated, _) = - interior.read().clone().update_as_polygon_from_points( - [e, f, g, h], - &mut services.objects, - ); - *interior.write() = updated; + let (interior, _) = Cycle::new([]).update_as_polygon_from_points( + [e, f, g, h], + &mut services.objects, + ); + face.add_interior(interior, &mut services.objects); } let face = face .build(&mut services.objects) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index b3dab17f8..f4ce6ba82 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -4,14 +4,13 @@ use crate::{ geometry::curve::Curve, insert::Insert, objects::{Cycle, HalfEdge, Objects}, - partial::PartialCycle, services::Service, storage::Handle, }; use super::{HalfEdgeBuilder, ObjectArgument}; -/// Builder API for [`PartialCycle`] +/// Builder API for [`Cycle`] pub trait CycleBuilder: Sized { /// Add a new half-edge to the cycle /// @@ -112,62 +111,3 @@ impl CycleBuilder for Cycle { (self, edges) } } - -impl CycleBuilder for PartialCycle { - fn add_half_edge( - mut self, - half_edge: HalfEdge, - objects: &mut Service, - ) -> (Self, Handle) { - let half_edge = half_edge.insert(objects); - self.half_edges.push(half_edge.clone()); - (self, half_edge) - } - - fn update_as_polygon_from_points( - mut self, - points: O, - objects: &mut Service, - ) -> (Self, O::SameSize>) - where - O: ObjectArgument

, - P: Clone + Into>, - { - let half_edges = points.map_with_next(|start, end| { - let half_edge = HalfEdgeBuilder::line_segment([start, end], None) - .build(objects); - - let (cycle, half_edge) = - self.clone().add_half_edge(half_edge, objects); - self = cycle; - - half_edge - }); - - (self, half_edges) - } - - fn connect_to_edges( - mut self, - edges: O, - objects: &mut Service, - ) -> (Self, O::SameSize>) - where - O: ObjectArgument<(Handle, Curve, [Point<1>; 2])>, - { - let edges = - edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| { - let half_edge = HalfEdgeBuilder::new(curve, boundary) - .with_start_vertex(prev.start_vertex().clone()) - .build(objects); - - let (cycle, half_edge) = - self.clone().add_half_edge(half_edge, objects); - self = cycle; - - half_edge - }); - - (self, edges) - } -} diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 2ee8339d3..bcaf053a9 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -1,7 +1,9 @@ use crate::{ + insert::Insert, objects::{Cycle, Objects}, - partial::{Partial, PartialFace}, + partial::PartialFace, services::Service, + storage::Handle, }; /// Builder API for [`PartialFace`] @@ -9,16 +11,18 @@ pub trait FaceBuilder { /// Add an interior cycle fn add_interior( &mut self, + cycle: Cycle, objects: &mut Service, - ) -> Partial; + ) -> Handle; } impl FaceBuilder for PartialFace { fn add_interior( &mut self, + cycle: Cycle, objects: &mut Service, - ) -> Partial { - let cycle = Partial::new(objects); + ) -> Handle { + let cycle = cycle.insert(objects); self.interiors.push(cycle.clone()); cycle } diff --git a/crates/fj-kernel/src/partial/mod.rs b/crates/fj-kernel/src/partial/mod.rs index ef084f360..461c07594 100644 --- a/crates/fj-kernel/src/partial/mod.rs +++ b/crates/fj-kernel/src/partial/mod.rs @@ -16,8 +16,8 @@ mod wrapper; pub use self::{ objects::{ - cycle::PartialCycle, face::PartialFace, shell::PartialShell, - sketch::PartialSketch, solid::PartialSolid, + face::PartialFace, shell::PartialShell, sketch::PartialSketch, + solid::PartialSolid, }, traits::{HasPartial, PartialObject}, wrapper::{FullToPartialCache, Partial}, diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs deleted file mode 100644 index c81c0665e..000000000 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ /dev/null @@ -1,33 +0,0 @@ -use crate::{ - objects::{Cycle, HalfEdge, Objects}, - partial::{FullToPartialCache, PartialObject}, - services::Service, - storage::Handle, -}; - -/// A partial [`Cycle`] -#[derive(Clone, Debug)] -pub struct PartialCycle { - /// The half-edges that make up the cycle - pub half_edges: Vec>, -} - -impl PartialObject for PartialCycle { - type Full = Cycle; - - fn new(_: &mut Service) -> Self { - Self { - half_edges: Vec::new(), - } - } - - fn from_full(cycle: &Self::Full, _: &mut FullToPartialCache) -> Self { - Self { - half_edges: cycle.half_edges().cloned().collect(), - } - } - - fn build(self, _: &mut Service) -> Self::Full { - Cycle::new(self.half_edges) - } -} diff --git a/crates/fj-kernel/src/partial/objects/face.rs b/crates/fj-kernel/src/partial/objects/face.rs index ac009c8a7..4c072b616 100644 --- a/crates/fj-kernel/src/partial/objects/face.rs +++ b/crates/fj-kernel/src/partial/objects/face.rs @@ -3,7 +3,7 @@ use fj_interop::mesh::Color; use crate::{ insert::Insert, objects::{Cycle, Face, Objects, Surface}, - partial::{FullToPartialCache, Partial, PartialObject}, + partial::{FullToPartialCache, PartialObject}, services::Service, storage::Handle, }; @@ -20,7 +20,7 @@ pub struct PartialFace { /// The cycles that bound the face on the inside /// /// Each of these cycles defines a hole in the face. - pub interiors: Vec>, + pub interiors: Vec>, /// The color of the face pub color: Option, @@ -38,25 +38,19 @@ impl PartialObject for PartialFace { } } - fn from_full(face: &Self::Full, cache: &mut FullToPartialCache) -> Self { + fn from_full(face: &Self::Full, _: &mut FullToPartialCache) -> Self { Self { surface: Some(face.surface().clone()), exterior: face.exterior().clone(), - interiors: face - .interiors() - .map(|cycle| Partial::from_full(cycle.clone(), cache)) - .collect(), + interiors: face.interiors().cloned().collect(), color: Some(face.color()), } } - fn build(self, objects: &mut Service) -> Self::Full { + fn build(self, _: &mut Service) -> Self::Full { let surface = self.surface.expect("Need `Surface` to build `Face`"); - - let interiors = - self.interiors.into_iter().map(|cycle| cycle.build(objects)); let color = self.color.unwrap_or_default(); - Face::new(surface, self.exterior, interiors, color) + Face::new(surface, self.exterior, self.interiors, color) } } diff --git a/crates/fj-kernel/src/partial/objects/mod.rs b/crates/fj-kernel/src/partial/objects/mod.rs index f693681df..2136df99c 100644 --- a/crates/fj-kernel/src/partial/objects/mod.rs +++ b/crates/fj-kernel/src/partial/objects/mod.rs @@ -1,4 +1,3 @@ -pub mod cycle; pub mod face; pub mod shell; pub mod sketch; diff --git a/crates/fj-kernel/src/partial/traits.rs b/crates/fj-kernel/src/partial/traits.rs index 9cb526b68..0b824b48b 100644 --- a/crates/fj-kernel/src/partial/traits.rs +++ b/crates/fj-kernel/src/partial/traits.rs @@ -36,7 +36,6 @@ macro_rules! impl_trait { } impl_trait!( - Cycle, PartialCycle; Face, PartialFace; Shell, PartialShell; Sketch, PartialSketch; diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 52e15d454..903dfa0fc 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -74,7 +74,7 @@ mod tests { algorithms::reverse::Reverse, builder::{CycleBuilder, FaceBuilder}, insert::Insert, - objects::Face, + objects::{Cycle, Face}, partial::{PartialFace, PartialObject}, services::Services, validate::{FaceValidationError, Validate, ValidationError}, @@ -97,13 +97,12 @@ mod tests { face.exterior = exterior.insert(&mut services.objects); } { - let mut interior = face.add_interior(&mut services.objects); - let (updated, _) = - interior.read().clone().update_as_polygon_from_points( + let (interior, _) = Cycle::new([]) + .update_as_polygon_from_points( [[1., 1.], [1., 2.], [2., 1.]], &mut services.objects, ); - *interior.write() = updated; + face.add_interior(interior, &mut services.objects); } face.build(&mut services.objects) }; diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index c55b73ef5..8e228bd5f 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -47,8 +47,7 @@ impl Shape for fj::Difference2d { exteriors.push(face.exterior().clone()); for cycle in face.interiors() { - interiors - .push(Partial::from(cycle.clone().reverse(objects))); + interiors.push(cycle.clone().reverse(objects)); } } @@ -59,9 +58,7 @@ impl Shape for fj::Difference2d { "Trying to subtract faces with different surfaces.", ); - interiors.push(Partial::from( - face.exterior().clone().reverse(objects), - )); + interiors.push(face.exterior().clone().reverse(objects)); } // Faces only support one exterior, while the code here comes from