pub struct Simplex { /* private fields */ }Expand description
A simplex represents a $k$-dimensional geometric object, defined as the convex hull of $k+1$ affinely independent vertices.
Simplices are the basic building blocks of SimplicialComplexes.
- A 0-simplex (dimension 0) is a point.
- A 1-simplex (dimension 1) is a line segment.
- A 2-simplex (dimension 2) is a triangle.
- A 3-simplex (dimension 3) is a tetrahedron.
- … and so on for higher dimensions.
In this implementation, vertices are represented by usize indices and are always stored in a
sorted vector to ensure a canonical representation for each simplex.
§Fields
vertices: A sortedVec<usize>of vertex indices that define the simplex.dimension: The dimension of the simplex, equal tovertices.len() - 1.id: An optional unique identifier assigned when the simplex is added to a complex.
Implementations§
Source§impl Simplex
impl Simplex
Sourcepub fn new(dimension: usize, vertices: Vec<usize>) -> Self
pub fn new(dimension: usize, vertices: Vec<usize>) -> Self
Creates a new simplex of a given dimension from a set of vertices.
The provided vertices will be sorted internally to ensure a canonical representation.
The simplex is created without an ID (id = None).
§Arguments
dimension: The dimension of the simplex (e.g., 0 for a point, 1 for an edge, 2 for a triangle).vertices: A vector ofusizevertex indices. The length of this vector must be `dimension- 1`.
§Panics
- If
vertices.len()does not equaldimension + 1. - If any vertex indices in
verticesare repeated (i.e., vertices are not distinct).
Sourcepub fn from_vertices(vertices: Vec<usize>) -> Self
pub fn from_vertices(vertices: Vec<usize>) -> Self
Creates a new simplex from vertices, automatically determining the dimension.
This is a convenience constructor that calculates the dimension based on the number
of vertices provided. The dimension will be vertices.len() - 1.
§Arguments
vertices: A vector ofusizevertex indices. Must contain distinct values.
§Examples
// Create a point (0-simplex)
let point = Simplex::from_vertices(vec![0]);
assert_eq!(point.dimension(), 0);
// Create an edge (1-simplex)
let edge = Simplex::from_vertices(vec![0, 1]);
assert_eq!(edge.dimension(), 1);
// Create a triangle (2-simplex)
let triangle = Simplex::from_vertices(vec![0, 1, 2]);
assert_eq!(triangle.dimension(), 2);§Panics
- If any vertex indices are repeated
- If the vertices vector is empty
Sourcepub fn vertices(&self) -> &[usize]
pub fn vertices(&self) -> &[usize]
Returns a slice reference to the sorted vertex indices of the simplex.
The vertices are always maintained in sorted order to ensure canonical representation. This means that two simplices with the same vertex set (regardless of input order) will have identical vertex arrays.
§Returns
A slice &[usize] containing the vertex indices in ascending order
§Examples
let simplex = Simplex::new(2, vec![2, 0, 1]); // Input order doesn't matter
assert_eq!(simplex.vertices(), &[0, 1, 2]); // Always sortedSourcepub const fn dimension(&self) -> usize
pub const fn dimension(&self) -> usize
Returns the dimension of the simplex.
The dimension $k$ is equal to the number of vertices minus one. This follows the standard topological convention where:
- Points have dimension 0
- Line segments have dimension 1
- Triangles have dimension 2
- Tetrahedra have dimension 3
- etc.
§Returns
The dimension as a usize
Sourcepub const fn id(&self) -> Option<usize>
pub const fn id(&self) -> Option<usize>
Returns the ID of the simplex if it has been assigned to a complex.
Simplices start with no ID (None) when created. IDs are assigned automatically
when the simplex is added to a Complex via Complex::join_element. The ID
serves as a unique identifier for efficient storage and lookup operations within
the complex.
§Returns
Some(usize) if the simplex has been assigned to a complex, None otherwise
Sourcepub fn same_content(&self, other: &Self) -> bool
pub fn same_content(&self, other: &Self) -> bool
Checks if this simplex has the same mathematical content as another.
Two simplices are considered to have the same content if they have the same dimension and the same set of vertices. This comparison ignores ID assignment and is used for deduplication when adding elements to complexes.
§Arguments
other: The other simplex to compare against
§Returns
true if the simplices represent the same geometric object, false otherwise
Trait Implementations§
Source§impl ComplexElement for Simplex
impl ComplexElement for Simplex
Source§fn faces(&self) -> Vec<Self>
fn faces(&self) -> Vec<Self>
Computes all $(k-1)$-dimensional faces of this $k$-simplex.
A face is obtained by removing one vertex from the simplex’s vertex set. For example:
- The faces of a 2-simplex (triangle)
[v_0, v_1, v_2]are its three 1-simplices (edges):[v_1, v_2],[v_0, v_2], and[v_0, v_1]. - The faces of a 1-simplex (edge)
[v_0, v_1]are its two 0-simplices (vertices):[v_1]and[v_0]. - A 0-simplex has no faces (its dimension is -1, typically considered an empty set of faces).
§Returns
A Vec<Simplex> containing all $(k-1)$-dimensional faces. If the simplex is
0-dimensional, an empty vector is returned as it has no $( -1)$-dimensional faces in the
typical sense.
Source§fn boundary_with_orientations(&self) -> Vec<(Self, i32)>
fn boundary_with_orientations(&self) -> Vec<(Self, i32)>
Computes the faces with their correct orientation coefficients for the simplicial boundary operator.
For a k-simplex σ = [v_0, v_1, …, v_k], the boundary is: ∂σ = Σ_{i=0}^k (-1)^i [v_0, …, v̂_i, …, v_k] where v̂_i means vertex v_i is omitted.
Source§fn id(&self) -> Option<usize>
fn id(&self) -> Option<usize>
None otherwise. Read moreSource§fn same_content(&self, other: &Self) -> bool
fn same_content(&self, other: &Self) -> bool
Source§impl Ord for Simplex
impl Ord for Simplex
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Provides a total ordering for simplices, primarily for use in sorted collections (e.g.,
BTreeSet or when sorting Vec<Simplex>).
The ordering is based on the lexicographical comparison of their sorted vertex lists, then by dimension.
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Simplex
impl PartialOrd for Simplex
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Provides a partial ordering for simplices.
This implementation delegates to cmp, thus providing a total ordering.
impl Eq for Simplex
impl StructuralPartialEq for Simplex
Auto Trait Implementations§
impl Freeze for Simplex
impl RefUnwindSafe for Simplex
impl Send for Simplex
impl Sync for Simplex
impl Unpin for Simplex
impl UnwindSafe for Simplex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more