Make method return type more flexible

This prepares for an upcoming change.
This commit is contained in:
Hanno Braun 2022-10-12 15:47:18 +02:00
parent c2a28e0644
commit 67d351cea0
2 changed files with 15 additions and 7 deletions

View File

@ -106,10 +106,16 @@ impl MaybePartial<GlobalEdge> {
impl MaybePartial<HalfEdge> { impl MaybePartial<HalfEdge> {
/// Access the vertices /// Access the vertices
pub fn vertices(&self) -> Option<[MaybePartial<Vertex>; 2]> { pub fn vertices(&self) -> [Option<MaybePartial<Vertex>>; 2] {
match self { match self {
Self::Full(full) => Some(full.vertices().clone().map(Into::into)), Self::Full(full) => {
Self::Partial(partial) => partial.vertices.clone(), full.vertices().clone().map(|vertex| Some(vertex.into()))
}
Self::Partial(partial) => partial
.vertices
.clone()
.map(|vertices| vertices.map(Some))
.unwrap_or([None, None]),
} }
} }
} }

View File

@ -48,9 +48,9 @@ impl PartialCycle {
.half_edges .half_edges
.last() .last()
.map(|half_edge| { .map(|half_edge| {
let [_, last] = half_edge let [_, last] = half_edge.vertices().map(|vertex| {
.vertices() vertex.expect("Need half-edge vertices to extend cycle")
.expect("Need half-edge vertices to extend cycle"); });
let last = last let last = last
.surface_form() .surface_form()
.expect("Need surface vertex to extend cycle"); .expect("Need surface vertex to extend cycle");
@ -129,7 +129,9 @@ impl PartialCycle {
let vertices = [first, last].map(|option| { let vertices = [first, last].map(|option| {
option.map(|half_edge| { 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"))
}) })
}); });