Skip to content

Commit

Permalink
Implement get_vertex(handle)
Browse files Browse the repository at this point in the history
This is a shorthand to check if a `FixedVertexHandle` points to a valid vertex.
  • Loading branch information
mattlennon3 authored Jul 18, 2024
1 parent 6ae8eb9 commit dd6cf1a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/delaunay_core/dcel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ impl<V, DE, UE, F> Dcel<V, DE, UE, F> {
self.faces.truncate(1); // Keep outer face
}

pub fn get_vertex(&self, handle: FixedVertexHandle) -> Option<VertexHandle<V, DE, UE, F>> {
(handle.index() < self.vertices.len()).then(|| self.vertex(handle))
}

pub fn map_vertices<M, V2>(self, f: M) -> Dcel<V2, DE, UE, F>
where
M: Fn(V) -> V2,
Expand Down
13 changes: 13 additions & 0 deletions src/triangulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,19 @@ pub trait Triangulation: Default {
self.s().fixed_vertices()
}

/// Get a vertex by its index
///
/// To get the handle, wrap your local index in a FixedVertexHandle:
/// `let handle = FixedVertexHandle::from_index(my_index);`
#[allow(clippy::type_complexity)]
fn get_vertex(
&self,
handle: FixedVertexHandle,
) -> Option<VertexHandle<Self::Vertex, Self::DirectedEdge, Self::UndirectedEdge, Self::Face>>
{
self.s().get_vertex(handle)
}

/// An iterator visiting all faces.
///
/// The first returned face is the outer face, all other faces will be inner faces.
Expand Down

0 comments on commit dd6cf1a

Please sign in to comment.