diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 7d5e467b5..80e038c42 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -267,8 +267,8 @@ mod tests { builder::{CycleBuilder, HalfEdgeBuilder}, geometry::{curve::GlobalPath, surface::SurfaceGeometry}, insert::Insert, - objects::Surface, - partial::{PartialCycle, PartialHalfEdge, PartialObject}, + objects::{HalfEdge, Surface}, + partial::{PartialCycle, PartialObject}, services::Services, }; @@ -285,10 +285,7 @@ mod tests { &mut services.objects, ); - let half_edge = half_edge.read().clone(); half_edge - .build(&mut services.objects) - .insert(&mut services.objects) }; let tolerance = 1.; @@ -314,10 +311,7 @@ mod tests { &mut services.objects, ); - let half_edge = half_edge.read().clone(); half_edge - .build(&mut services.objects) - .insert(&mut services.objects) }; let tolerance = 1.; @@ -338,14 +332,13 @@ mod tests { v: [0., 0., 1.].into(), }) .insert(&mut services.objects); - let half_edge = PartialHalfEdge::make_line_segment( + let half_edge = HalfEdge::make_line_segment( [[0., 1.], [TAU, 1.]], Some(range.boundary), None, None, &mut services.objects, - ) - .build(&mut services.objects); + ); let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); @@ -369,8 +362,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xz_plane(); - let half_edge = PartialHalfEdge::make_circle(1., &mut services.objects) - .build(&mut services.objects); + let half_edge = HalfEdge::make_circle(1., &mut services.objects); 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 34a5202e1..62c6961af 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -93,7 +93,7 @@ mod tests { &mut services.objects, ); - half_edge.build(&mut services.objects) + half_edge }; let intersection = CurveEdgeIntersection::compute(&curve, &half_edge); @@ -119,7 +119,7 @@ mod tests { &mut services.objects, ); - half_edge.build(&mut services.objects) + half_edge }; let intersection = CurveEdgeIntersection::compute(&curve, &half_edge); @@ -145,7 +145,7 @@ mod tests { &mut services.objects, ); - half_edge.build(&mut services.objects) + half_edge }; let intersection = CurveEdgeIntersection::compute(&curve, &half_edge); @@ -166,7 +166,7 @@ mod tests { &mut services.objects, ); - half_edge.build(&mut services.objects) + half_edge }; 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 5ed392b5a..bbcdc4961 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -5,7 +5,7 @@ use crate::{ builder::{CycleBuilder, HalfEdgeBuilder}, insert::Insert, objects::{Face, HalfEdge, Objects, Surface, Vertex}, - partial::{PartialFace, PartialHalfEdge, PartialObject}, + partial::{PartialFace, PartialObject}, services::Service, storage::Handle, }; @@ -88,7 +88,7 @@ impl Sweep for (Handle, &Handle, &Surface, Color) { .zip_ext(vertices) .zip_ext(global_edges) .map(|((((boundary, start), end), start_vertex), global_edge)| { - let half_edge = PartialHalfEdge::make_line_segment( + let half_edge = HalfEdge::make_line_segment( [start, end], Some(boundary), Some(start_vertex), @@ -104,7 +104,6 @@ impl Sweep for (Handle, &Handle, &Surface, Color) { // And we're done creating the face! All that's left to do is build our // return values. let face = face.build(objects).insert(objects); - let edge_top = edge_top.build(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 c3f0757ed..df81567dc 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -78,7 +78,7 @@ impl Sweep for Handle { faces.push(face); top_edges.push(( - Partial::from(top_edge), + top_edge, half_edge.curve(), half_edge.boundary(), )); diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 758065f86..77e7bff35 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -3,8 +3,9 @@ use fj_math::Point; use crate::{ geometry::curve::Curve, objects::{HalfEdge, Objects}, - partial::{Partial, PartialCycle, PartialHalfEdge}, + partial::PartialCycle, services::Service, + storage::Handle, }; use super::{HalfEdgeBuilder, ObjectArgument}; @@ -20,14 +21,14 @@ pub trait CycleBuilder { /// /// If this is the first half-edge being added, it is connected to itself, /// meaning its front and back vertices are the same. - fn add_half_edge(&mut self, half_edge: Partial); + fn add_half_edge(&mut self, half_edge: Handle); /// Update cycle as a polygon from the provided points fn update_as_polygon_from_points( &mut self, points: O, objects: &mut Service, - ) -> O::SameSize> + ) -> O::SameSize> where O: ObjectArgument

, P: Clone + Into>; @@ -42,13 +43,13 @@ pub trait CycleBuilder { &mut self, edges: O, objects: &mut Service, - ) -> O::SameSize> + ) -> O::SameSize> where - O: ObjectArgument<(Partial, Curve, [Point<1>; 2])>; + O: ObjectArgument<(Handle, Curve, [Point<1>; 2])>; } impl CycleBuilder for PartialCycle { - fn add_half_edge(&mut self, half_edge: Partial) { + fn add_half_edge(&mut self, half_edge: Handle) { self.half_edges.push(half_edge); } @@ -56,13 +57,13 @@ impl CycleBuilder for PartialCycle { &mut self, points: O, objects: &mut Service, - ) -> O::SameSize> + ) -> O::SameSize> where O: ObjectArgument

, P: Clone + Into>, { points.map_with_next(|start, end| { - let half_edge = PartialHalfEdge::make_line_segment( + let half_edge = HalfEdge::make_line_segment( [start, end], None, None, @@ -80,15 +81,15 @@ impl CycleBuilder for PartialCycle { &mut self, edges: O, objects: &mut Service, - ) -> O::SameSize> + ) -> O::SameSize> where - O: ObjectArgument<(Partial, Curve, [Point<1>; 2])>, + O: ObjectArgument<(Handle, Curve, [Point<1>; 2])>, { edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| { - let half_edge = PartialHalfEdge::make_half_edge( + let half_edge = HalfEdge::make_half_edge( curve, boundary, - Some(prev.read().start_vertex.clone()), + Some(prev.start_vertex().clone()), None, objects, ); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index be395df81..1ac9e6bdc 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -5,18 +5,17 @@ use crate::{ geometry::curve::Curve, insert::Insert, objects::{GlobalEdge, HalfEdge, Objects, Vertex}, - partial::{Partial, PartialHalfEdge}, services::Service, storage::Handle, }; -/// Builder API for [`PartialHalfEdge`] +/// Builder API for [`HalfEdge`] pub trait HalfEdgeBuilder { /// Create a circle fn make_circle( radius: impl Into, objects: &mut Service, - ) -> Partial; + ) -> Handle; /// Create an arc /// @@ -28,7 +27,7 @@ pub trait HalfEdgeBuilder { end: impl Into>, angle_rad: impl Into, objects: &mut Service, - ) -> Partial; + ) -> Handle; /// Create a line segment fn make_line_segment( @@ -37,7 +36,7 @@ pub trait HalfEdgeBuilder { start_vertex: Option>, global_form: Option>, objects: &mut Service, - ) -> Partial; + ) -> Handle; /// Create a half-edge fn make_half_edge( @@ -46,14 +45,14 @@ pub trait HalfEdgeBuilder { start_vertex: Option>, global_form: Option>, objects: &mut Service, - ) -> Partial; + ) -> Handle; } -impl HalfEdgeBuilder for PartialHalfEdge { +impl HalfEdgeBuilder for HalfEdge { fn make_circle( radius: impl Into, objects: &mut Service, - ) -> Partial { + ) -> Handle { let curve = Curve::circle_from_radius(radius); let boundary = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); @@ -66,7 +65,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { end: impl Into>, angle_rad: impl Into, objects: &mut Service, - ) -> Partial { + ) -> Handle { let angle_rad = angle_rad.into(); if angle_rad <= -Scalar::TAU || angle_rad >= Scalar::TAU { panic!("arc angle must be in the range (-2pi, 2pi) radians"); @@ -88,7 +87,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { start_vertex: Option>, global_form: Option>, objects: &mut Service, - ) -> Partial { + ) -> Handle { let boundary = boundary.unwrap_or_else(|| [[0.], [1.]].map(Point::from)); let curve = Curve::line_from_points_with_coords( @@ -110,14 +109,13 @@ impl HalfEdgeBuilder for PartialHalfEdge { start_vertex: Option>, global_form: Option>, objects: &mut Service, - ) -> Partial { - Partial::from_partial(PartialHalfEdge { + ) -> Handle { + HalfEdge::new( curve, boundary, - start_vertex: start_vertex - .unwrap_or_else(|| Vertex::new().insert(objects)), - global_form: global_form - .unwrap_or_else(|| GlobalEdge::new().insert(objects)), - }) + start_vertex.unwrap_or_else(|| Vertex::new().insert(objects)), + global_form.unwrap_or_else(|| GlobalEdge::new().insert(objects)), + ) + .insert(objects) } } diff --git a/crates/fj-kernel/src/partial/mod.rs b/crates/fj-kernel/src/partial/mod.rs index 7f688571c..ef084f360 100644 --- a/crates/fj-kernel/src/partial/mod.rs +++ b/crates/fj-kernel/src/partial/mod.rs @@ -16,9 +16,39 @@ mod wrapper; pub use self::{ objects::{ - cycle::PartialCycle, edge::PartialHalfEdge, face::PartialFace, - shell::PartialShell, sketch::PartialSketch, solid::PartialSolid, + cycle::PartialCycle, face::PartialFace, shell::PartialShell, + sketch::PartialSketch, solid::PartialSolid, }, traits::{HasPartial, PartialObject}, wrapper::{FullToPartialCache, Partial}, }; + +use crate::storage::Handle; + +/// Either a full or a partial object +/// +/// # Implementation Note +/// +/// This enum temporarily exists to aid in the transition towards a unified +/// object system. Issue: +/// +#[derive(Clone, Debug)] +pub enum FullOrPartial { + /// A full object + Full(Handle), + + /// A partial object + Partial(Partial), +} + +impl From> for FullOrPartial { + fn from(object: Handle) -> Self { + Self::Full(object) + } +} + +impl From> for FullOrPartial { + fn from(object: Partial) -> Self { + Self::Partial(object) + } +} diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index 5615a74a1..c81c0665e 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -1,14 +1,15 @@ use crate::{ objects::{Cycle, HalfEdge, Objects}, - partial::{FullToPartialCache, Partial, PartialObject}, + 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>, + pub half_edges: Vec>, } impl PartialObject for PartialCycle { @@ -20,22 +21,13 @@ impl PartialObject for PartialCycle { } } - fn from_full(cycle: &Self::Full, cache: &mut FullToPartialCache) -> Self { + fn from_full(cycle: &Self::Full, _: &mut FullToPartialCache) -> Self { Self { - half_edges: cycle - .half_edges() - .cloned() - .map(|half_edge| Partial::from_full(half_edge, cache)) - .collect(), + half_edges: cycle.half_edges().cloned().collect(), } } - fn build(self, objects: &mut Service) -> Self::Full { - let half_edges = self - .half_edges - .into_iter() - .map(|half_edge| half_edge.build(objects)); - - Cycle::new(half_edges) + fn build(self, _: &mut Service) -> Self::Full { + Cycle::new(self.half_edges) } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs deleted file mode 100644 index 7f637590e..000000000 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ /dev/null @@ -1,53 +0,0 @@ -use fj_math::Point; - -use crate::{ - geometry::curve::Curve, - objects::{GlobalEdge, HalfEdge, Objects, Vertex}, - partial::{FullToPartialCache, PartialObject}, - services::Service, - storage::Handle, -}; - -/// A partial [`HalfEdge`] -#[derive(Clone, Debug)] -pub struct PartialHalfEdge { - /// The curve that the half-edge is defined in - pub curve: Curve, - - /// The boundary of the half-edge on the curve - pub boundary: [Point<1>; 2], - - /// The surface vertex where the half-edge starts - pub start_vertex: Handle, - - /// The global form of the half-edge - pub global_form: Handle, -} - -impl PartialObject for PartialHalfEdge { - type Full = HalfEdge; - - fn new(_: &mut Service) -> Self { - // This method is no longer used, and since `PartialHalfEdge` will be - // replaced with `HalfEdge`, it will soon be removed. - unreachable!() - } - - fn from_full(half_edge: &Self::Full, _: &mut FullToPartialCache) -> Self { - Self { - curve: half_edge.curve(), - boundary: half_edge.boundary(), - start_vertex: half_edge.start_vertex().clone(), - global_form: half_edge.global_form().clone(), - } - } - - fn build(self, _: &mut Service) -> Self::Full { - HalfEdge::new( - self.curve, - self.boundary, - self.start_vertex, - self.global_form, - ) - } -} diff --git a/crates/fj-kernel/src/partial/objects/mod.rs b/crates/fj-kernel/src/partial/objects/mod.rs index 8928937cb..f693681df 100644 --- a/crates/fj-kernel/src/partial/objects/mod.rs +++ b/crates/fj-kernel/src/partial/objects/mod.rs @@ -1,5 +1,4 @@ pub mod cycle; -pub mod edge; 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 d0ff79827..9cb526b68 100644 --- a/crates/fj-kernel/src/partial/traits.rs +++ b/crates/fj-kernel/src/partial/traits.rs @@ -38,7 +38,6 @@ macro_rules! impl_trait { impl_trait!( Cycle, PartialCycle; Face, PartialFace; - HalfEdge, PartialHalfEdge; Shell, PartialShell; Sketch, PartialSketch; Solid, PartialSolid; diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 961b6f17c..5df0d80ac 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -95,7 +95,7 @@ mod tests { &mut services.objects, ); - half_edge.build(&mut services.objects) + half_edge }; 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 fea504801..c84cbc5fd 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -4,10 +4,9 @@ use fj_interop::{debug::DebugInfo, mesh::Color}; use fj_kernel::{ builder::{CycleBuilder, HalfEdgeBuilder}, insert::Insert, - objects::{Objects, Sketch}, + objects::{HalfEdge, Objects, Sketch}, partial::{ - Partial, PartialCycle, PartialFace, PartialHalfEdge, PartialObject, - PartialSketch, + Partial, PartialCycle, PartialFace, PartialObject, PartialSketch, }, services::Service, }; @@ -28,8 +27,7 @@ impl Shape for fj::Sketch { let face = match self.chain() { fj::Chain::Circle(circle) => { - let half_edge = - PartialHalfEdge::make_circle(circle.radius(), objects); + let half_edge = HalfEdge::make_circle(circle.radius(), objects); let exterior = { let mut cycle = PartialCycle::new(objects); cycle.half_edges.push(half_edge); @@ -65,7 +63,7 @@ impl Shape for fj::Sketch { for ((start, route), (end, _)) in segments { let half_edge = match route { fj::SketchSegmentRoute::Direct => { - PartialHalfEdge::make_line_segment( + HalfEdge::make_line_segment( [start, end], None, None, @@ -74,7 +72,7 @@ impl Shape for fj::Sketch { ) } fj::SketchSegmentRoute::Arc { angle } => { - PartialHalfEdge::make_arc( + HalfEdge::make_arc( start, end, angle.rad(),