From 67d351cea077fd4845f2a8e57d1cab28f85fcc3b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 12 Oct 2022 15:47:18 +0200 Subject: [PATCH] Make method return type more flexible This prepares for an upcoming change. --- crates/fj-kernel/src/partial/maybe_partial.rs | 12 +++++++++--- crates/fj-kernel/src/partial/objects/cycle.rs | 10 ++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index b931e11dd..9b968b747 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -106,10 +106,16 @@ impl MaybePartial { impl MaybePartial { /// Access the vertices - pub fn vertices(&self) -> Option<[MaybePartial; 2]> { + pub fn vertices(&self) -> [Option>; 2] { match self { - Self::Full(full) => Some(full.vertices().clone().map(Into::into)), - Self::Partial(partial) => partial.vertices.clone(), + Self::Full(full) => { + full.vertices().clone().map(|vertex| Some(vertex.into())) + } + Self::Partial(partial) => partial + .vertices + .clone() + .map(|vertices| vertices.map(Some)) + .unwrap_or([None, None]), } } } diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index be37c6a04..39b7dfbd8 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -48,9 +48,9 @@ impl PartialCycle { .half_edges .last() .map(|half_edge| { - let [_, last] = half_edge - .vertices() - .expect("Need half-edge vertices to extend cycle"); + let [_, last] = half_edge.vertices().map(|vertex| { + vertex.expect("Need half-edge vertices to extend cycle") + }); let last = last .surface_form() .expect("Need surface vertex to extend cycle"); @@ -129,7 +129,9 @@ impl PartialCycle { let vertices = [first, last].map(|option| { option.map(|half_edge| { - half_edge.vertices().expect("Need vertices to close cycle") + half_edge + .vertices() + .map(|vertex| vertex.expect("Need vertices to close cycle")) }) });