From b7d878b9e1d0bce8679080bec43763bce0da31f9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 7 Oct 2022 14:56:41 +0200 Subject: [PATCH] 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);