Simplex

Struct Simplex 

Source
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 sorted Vec<usize> of vertex indices that define the simplex.
  • dimension: The dimension of the simplex, equal to vertices.len() - 1.
  • id: An optional unique identifier assigned when the simplex is added to a complex.

Implementations§

Source§

impl Simplex

Source

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 of usize vertex indices. The length of this vector must be `dimension
    • 1`.
§Panics
  • If vertices.len() does not equal dimension + 1.
  • If any vertex indices in vertices are repeated (i.e., vertices are not distinct).
Source

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 of usize vertex 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
Source

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 sorted
Source

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

Source

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

Source

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 Clone for Simplex

Source§

fn clone(&self) -> Simplex

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ComplexElement for Simplex

Source§

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)>

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 dimension(&self) -> usize

Returns the intrinsic dimension of this element. Read more
Source§

fn id(&self) -> Option<usize>

Returns the ID if this element has been assigned to a complex, None otherwise. Read more
Source§

fn same_content(&self, other: &Self) -> bool

Checks if this element has the same mathematical content as another. Read more
Source§

fn with_id(&self, new_id: usize) -> Self

Creates a new element with the same content but a specific ID. Read more
Source§

impl Debug for Simplex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Simplex

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Simplex

Source§

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) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Simplex

Source§

fn eq(&self, other: &Simplex) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Simplex

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

Provides a partial ordering for simplices.

This implementation delegates to cmp, thus providing a total ordering.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Simplex

Source§

impl StructuralPartialEq for Simplex

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.