Skip to content

Commit

Permalink
Implements FixedVertexHandle::from_index
Browse files Browse the repository at this point in the history
  • Loading branch information
Stoeoef committed Jan 14, 2024
1 parent 56ffeb0 commit 78f5bfc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/delaunay_core/handles/handle_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use core::convert::TryInto;

use super::super::Dcel;
use super::public_handles::{InnerOuterMarker, PossiblyOuterTag};
use super::FixedVertexHandle;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -43,6 +44,23 @@ pub const fn new_fixed_face_handle(index: usize) -> FixedHandleImpl<FaceTag, Pos
}
}

impl FixedVertexHandle {
/// Creates a new vertex handle from a `usize`.
///
/// Ideally, this method should only be used in advanced scenarios as it allows to create
/// invalid vertex handles. When possible, attempt to retrieve handles by other means
/// instead (see [crate::handles]).
///
/// # Panics
///
/// Panics if `index >= 2^32`
pub fn from_index(index: usize) -> Self {
// Preferably, `new` would simply be public. However, that would allow to create a handle
// to the outer face marked with `InnerTag` which is bad. Let's only allow vertices for now.
Self::new(index)
}
}

impl<Type: Default, InnerOuter: InnerOuterMarker> FixedHandleImpl<Type, InnerOuter> {
pub(crate) fn new(index: usize) -> Self {
Self::new_internal(
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ mod test_utilities;
/// | **Reference** | [vertices()](Triangulation::vertices()) | [directed_edges()](Triangulation::directed_edges) | [undirected_edges()](Triangulation::undirected_edges()) | [inner_faces()](Triangulation::inner_faces())<br>[all_faces()](Triangulation::all_faces()) |
/// | **Fixed** | [fixed_vertices()](Triangulation::fixed_vertices()) | [fixed_directed_edges()](Triangulation::fixed_directed_edges()) | [fixed_undirected_edges()](Triangulation::fixed_undirected_edges()) | [fixed_inner_faces()](Triangulation::fixed_inner_faces())<br> [fixed_faces()](Triangulation::fixed_inner_faces()) |
///
/// # Creating handles directly
///
/// In some cases it may be desireable to create vertex handles artificially by providing the index
/// manually. This can be done by calling [handles::FixedVertexHandle::from_index](from_index(usize)).
/// Make sure that the provided index is smaller than the number of vertices in the triangulation.
///
/// # Converting between reference and fixed handles
///
/// Converting a reference handle into its fixed counterpart is performed via the
Expand Down

0 comments on commit 78f5bfc

Please sign in to comment.