From 80784a1c3b0ef2eb39e912a85c9330fced4490ed Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 7 Oct 2022 13:28:55 +0200 Subject: [PATCH 1/6] Fix `GlobalVertex` duplication in `build` method --- crates/fj-kernel/src/partial/objects/edge.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 640caa6e3..768cfbec1 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -201,10 +201,9 @@ impl PartialHalfEdge { let global_form = self .global_form - .unwrap_or_else(|| { - GlobalEdge::partial() - .from_curve_and_vertices(&curve, &vertices) - .into() + .unwrap_or_else(|| GlobalEdge::partial().into()) + .update_partial(|partial| { + partial.from_curve_and_vertices(&curve, &vertices) }) .into_full(objects); From 8e8ff9484924a1bfabd78b8aa48248f3b3695b60 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 7 Oct 2022 14:03:50 +0200 Subject: [PATCH 2/6] Clean up `as_line_segment_from_points` --- crates/fj-kernel/src/partial/objects/edge.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 768cfbec1..b21c94ebd 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -104,14 +104,14 @@ impl PartialHalfEdge { points: [impl Into>; 2], ) -> Self { let surface = self.surface.clone(); - self.with_vertices(Some(points.map(|point| { - Vertex::partial().with_surface_form(Some( - SurfaceVertex::partial() - .with_surface(surface.clone()) - .with_position(Some(point)), - )) - }))) - .as_line_segment() + let vertices = points.map(|point| { + let surface_form = SurfaceVertex::partial() + .with_surface(surface.clone()) + .with_position(Some(point)); + Vertex::partial().with_surface_form(Some(surface_form)) + }); + + self.with_vertices(Some(vertices)).as_line_segment() } /// Update partial half-edge as a line segment, reusing existing vertices From d2c3c0fdb6a8d1aa886e340c6d3ff947ea6fbfd8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 7 Oct 2022 14:36:29 +0200 Subject: [PATCH 3/6] Clean up `PartialCurve` use in `as_line_segment` --- crates/fj-kernel/src/partial/objects/edge.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index b21c94ebd..581c06ea8 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -5,7 +5,7 @@ use crate::{ Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects, Surface, SurfaceVertex, Vertex, }, - partial::{HasPartial, MaybePartial, PartialCurve}, + partial::{HasPartial, MaybePartial}, storage::{Handle, HandleWrapper}, }; @@ -159,12 +159,10 @@ impl PartialHalfEdge { .expect("Can't infer line segment without surface position") }); - let curve = PartialCurve { - global_form: extract_global_curve(&self), - ..PartialCurve::default() - } - .with_surface(Some(surface)) - .as_line_from_points(points); + let curve = Handle::::partial() + .with_global_form(extract_global_curve(&self)) + .with_surface(Some(surface)) + .as_line_from_points(points); let vertices = [(from, 0.), (to, 1.)].map(|(vertex, position)| { vertex.update_partial(|vertex| { From 062cbbbf3be03e204c727621878c193ce2044dee Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 7 Oct 2022 14:41:25 +0200 Subject: [PATCH 4/6] Clean global curve extraction in `as_line_segment` --- crates/fj-kernel/src/partial/objects/edge.rs | 30 ++++++-------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 581c06ea8..1ee0bd1d7 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -116,26 +116,6 @@ impl PartialHalfEdge { /// Update partial half-edge as a line segment, reusing existing vertices pub fn as_line_segment(mut self) -> Self { - fn extract_global_curve( - partial: &PartialHalfEdge, - ) -> Option> { - fn extract_global_curve_from_curve( - partial: &PartialHalfEdge, - ) -> Option> { - partial.curve.as_ref()?.global_form() - } - - fn extract_global_curve_from_global_form( - partial: &PartialHalfEdge, - ) -> Option> { - Some(partial.global_form.as_ref()?.curve()?.clone()) - } - - extract_global_curve_from_curve(partial) - .or_else(|| extract_global_curve_from_global_form(partial)) - .map(Into::into) - } - let [from, to] = self .vertices .clone() @@ -159,8 +139,16 @@ impl PartialHalfEdge { .expect("Can't infer line segment without surface position") }); + let global_curve = { + let global_curve_from_curve = || self.curve.as_ref()?.global_form(); + let global_curve_from_global_form = + || Some(self.global_form.as_ref()?.curve()?.clone()); + + global_curve_from_curve().or_else(global_curve_from_global_form) + }; + let curve = Handle::::partial() - .with_global_form(extract_global_curve(&self)) + .with_global_form(global_curve) .with_surface(Some(surface)) .as_line_from_points(points); From b7d878b9e1d0bce8679080bec43763bce0da31f9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 7 Oct 2022 14:56:41 +0200 Subject: [PATCH 5/6] Add `PartialHalfEdge::extract_global_curve` --- crates/fj-kernel/src/partial/objects/edge.rs | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 1ee0bd1d7..9ce9b3dc6 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -30,6 +30,17 @@ pub struct PartialHalfEdge { } impl PartialHalfEdge { + /// Extract the global curve from either the curve or global form + /// + /// If a global curve is available through both, the curve is preferred. + pub fn extract_global_curve(&self) -> Option> { + let global_curve_from_curve = || self.curve.as_ref()?.global_form(); + let global_curve_from_global_form = + || Some(self.global_form.as_ref()?.curve()?.clone()); + + global_curve_from_curve().or_else(global_curve_from_global_form) + } + /// Update the partial half-edge with the given surface pub fn with_surface(mut self, surface: Option>) -> Self { if let Some(surface) = surface { @@ -139,16 +150,8 @@ impl PartialHalfEdge { .expect("Can't infer line segment without surface position") }); - let global_curve = { - let global_curve_from_curve = || self.curve.as_ref()?.global_form(); - let global_curve_from_global_form = - || Some(self.global_form.as_ref()?.curve()?.clone()); - - global_curve_from_curve().or_else(global_curve_from_global_form) - }; - let curve = Handle::::partial() - .with_global_form(global_curve) + .with_global_form(self.extract_global_curve()) .with_surface(Some(surface)) .as_line_from_points(points); From acdaaabe1d9b409c4254a92ae955df1212bf5325 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 7 Oct 2022 14:58:04 +0200 Subject: [PATCH 6/6] Fix object duplication in `as_circle_from_radius` --- crates/fj-kernel/src/partial/objects/edge.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 9ce9b3dc6..0789c889c 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -85,6 +85,7 @@ impl PartialHalfEdge { /// Update partial half-edge as a circle, from the given radius pub fn as_circle_from_radius(mut self, radius: impl Into) -> Self { let curve = Handle::::partial() + .with_global_form(self.extract_global_curve()) .with_surface(self.surface.clone()) .as_circle_from_radius(radius);