diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index a178fc7a02..666bf71f1d 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -125,6 +125,7 @@ impl Sweep for (HalfEdge, Color) { surface_vertices .clone() .map(|surface_vertex| surface_vertex.global_form().clone()), + objects, ); let vertices = { diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index bbb4f511a8..16f1e964c7 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -122,7 +122,7 @@ impl Sweep for (Handle, Handle) { } impl Sweep for Handle { - type Swept = (GlobalEdge, [Handle; 2]); + type Swept = (Handle, [Handle; 2]); fn sweep_with_cache( self, @@ -145,7 +145,7 @@ impl Sweep for Handle { .clone(); let vertices = [a, b]; - let global_edge = GlobalEdge::new(curve, vertices.clone()); + let global_edge = GlobalEdge::new(curve, vertices.clone(), objects); // The vertices of the returned `GlobalEdge` are in normalized order, // which means the order can't be relied upon by the caller. Return the diff --git a/crates/fj-kernel/src/algorithms/validate/mod.rs b/crates/fj-kernel/src/algorithms/validate/mod.rs index f155b01251..ddabcf9fd8 100644 --- a/crates/fj-kernel/src/algorithms/validate/mod.rs +++ b/crates/fj-kernel/src/algorithms/validate/mod.rs @@ -171,6 +171,7 @@ mod tests { }, partial::HasPartial, path::SurfacePath, + storage::Handle, }; #[test] @@ -224,7 +225,7 @@ mod tests { ); let vertices = [a, b]; - let global_edge = GlobalEdge::partial() + let global_edge = Handle::::partial() .from_curve_and_vertices(&curve, &vertices) .build(&objects); let half_edge = HalfEdge::new(vertices, global_edge); diff --git a/crates/fj-kernel/src/objects/edge.rs b/crates/fj-kernel/src/objects/edge.rs index b0e01d80b2..924d2bc6a5 100644 --- a/crates/fj-kernel/src/objects/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -4,13 +4,13 @@ use pretty_assertions::{assert_eq, assert_ne}; use crate::storage::{Handle, HandleWrapper}; -use super::{Curve, GlobalCurve, GlobalVertex, Vertex}; +use super::{Curve, GlobalCurve, GlobalVertex, Objects, Vertex}; /// A half-edge #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct HalfEdge { vertices: [Handle; 2], - global_form: GlobalEdge, + global_form: Handle, } impl HalfEdge { @@ -29,7 +29,10 @@ impl HalfEdge { /// were, the edge would have no length, and thus not be valid. (It is /// perfectly fine for global forms of the the vertices to be coincident. /// That would just mean, that ends of the edge connect to each other.) - pub fn new([a, b]: [Handle; 2], global_form: GlobalEdge) -> Self { + pub fn new( + [a, b]: [Handle; 2], + global_form: Handle, + ) -> Self { // Make sure `curve` and `vertices` match. assert_eq!( a.curve().id(), @@ -101,7 +104,7 @@ impl HalfEdge { } /// Access the global form of this half-edge - pub fn global_form(&self) -> &GlobalEdge { + pub fn global_form(&self) -> &Handle { &self.global_form } } @@ -137,10 +140,12 @@ impl GlobalEdge { pub fn new( curve: impl Into>, vertices: [Handle; 2], - ) -> Self { + objects: &Objects, + ) -> Handle { let curve = curve.into(); let (vertices, _) = VerticesInNormalizedOrder::new(vertices); - Self { curve, vertices } + + objects.global_edges.insert(Self { curve, vertices }) } /// Access the curve that defines the edge's geometry diff --git a/crates/fj-kernel/src/objects/mod.rs b/crates/fj-kernel/src/objects/mod.rs index 43655d2155..e1446a8727 100644 --- a/crates/fj-kernel/src/objects/mod.rs +++ b/crates/fj-kernel/src/objects/mod.rs @@ -118,6 +118,9 @@ pub struct Objects { /// Store for global curves pub global_curves: Store, + /// Store for global edges + pub global_edges: Store, + /// Store for global vertices pub global_vertices: Store, diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 5ffe4fe8e0..a1a9acb031 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -92,7 +92,7 @@ impl MaybePartial> { } } -impl MaybePartial { +impl MaybePartial> { /// Access the curve pub fn curve(&self) -> Option<&Handle> { match self { diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 81eee40868..59109c67b7 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -26,7 +26,7 @@ pub struct PartialHalfEdge { /// The global form of the [`HalfEdge`] /// /// Can be computed by [`PartialHalfEdge::build`], if not available. - pub global_form: Option>, + pub global_form: Option>>, } impl PartialHalfEdge { @@ -104,7 +104,7 @@ impl PartialHalfEdge { /// Update the partial half-edge with the given global form pub fn with_global_form( mut self, - global_form: Option>>, + global_form: Option>>>, ) -> Self { if let Some(global_form) = global_form { self.global_form = Some(global_form.into()); @@ -282,7 +282,7 @@ impl PartialHalfEdge { let global_form = self .global_form - .unwrap_or_else(|| GlobalEdge::partial().into()) + .unwrap_or_else(|| Handle::::partial().into()) .update_partial(|partial| { partial.from_curve_and_vertices(&curve, &vertices) }) @@ -355,7 +355,7 @@ impl PartialGlobalEdge { } /// Build a full [`GlobalEdge`] from the partial global edge - pub fn build(self, _: &Objects) -> GlobalEdge { + pub fn build(self, objects: &Objects) -> Handle { let curve = self .curve .expect("Can't build `GlobalEdge` without `GlobalCurve`"); @@ -363,12 +363,12 @@ impl PartialGlobalEdge { .vertices .expect("Can't build `GlobalEdge` without vertices"); - GlobalEdge::new(curve, vertices) + GlobalEdge::new(curve, vertices, objects) } } -impl From<&GlobalEdge> for PartialGlobalEdge { - fn from(global_edge: &GlobalEdge) -> Self { +impl From<&Handle> for PartialGlobalEdge { + fn from(global_edge: &Handle) -> Self { Self { curve: Some(global_edge.curve().clone().into()), vertices: Some( diff --git a/crates/fj-kernel/src/partial/objects/mod.rs b/crates/fj-kernel/src/partial/objects/mod.rs index db9be798b9..965b5e0a8c 100644 --- a/crates/fj-kernel/src/partial/objects/mod.rs +++ b/crates/fj-kernel/src/partial/objects/mod.rs @@ -44,7 +44,7 @@ macro_rules! impl_traits { impl_traits!( Handle, PartialCurve; Cycle, PartialCycle; - GlobalEdge, PartialGlobalEdge; + Handle, PartialGlobalEdge; Handle, PartialGlobalVertex; HalfEdge, PartialHalfEdge; Handle, PartialSurfaceVertex;