SpatialPoint

Trait SpatialPoint 

Source
pub trait SpatialPoint<T: SpatialScalar> {
    // Required methods
    fn dimension(&self) -> usize;
    fn coordinate(&self, index: usize) -> Option<T>;
    fn from_coords(coords: &[T]) -> Self;

    // Provided methods
    fn as_slice(&self) -> Option<&[T]> { ... }
    fn squared_distance_to(&self, other: &Self) -> T { ... }
    fn distance_to(&self, other: &Self) -> T { ... }
    fn manhattan_distance_to(&self, other: &Self) -> T { ... }
}
Expand description

Trait for types that can represent a point in space

This trait abstracts over different point representations, allowing algorithms to work with vectors, arrays, and custom types.

Required Methods§

Source

fn dimension(&self) -> usize

Get the dimension of the point

Source

fn coordinate(&self, index: usize) -> Option<T>

Get the coordinate at the given index

Source

fn from_coords(coords: &[T]) -> Self

Create a point from coordinates

Provided Methods§

Source

fn as_slice(&self) -> Option<&[T]>

Get all coordinates as a slice if possible (for efficiency)

Source

fn squared_distance_to(&self, other: &Self) -> T

Calculate squared Euclidean distance to another point

Source

fn distance_to(&self, other: &Self) -> T

Calculate Euclidean distance to another point

Source

fn manhattan_distance_to(&self, other: &Self) -> T

Calculate Manhattan distance to another point

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: SpatialScalar> SpatialPoint<T> for &[T]

Implementation of SpatialPoint for slices

Source§

fn dimension(&self) -> usize

Source§

fn coordinate(&self, index: usize) -> Option<T>

Source§

fn as_slice(&self) -> Option<&[T]>

Source§

fn from_coords(coords: &[T]) -> Self

Source§

impl<T: SpatialScalar> SpatialPoint<T> for Vec<T>

Implementation of SpatialPoint for Vec<T>

Source§

fn dimension(&self) -> usize

Source§

fn coordinate(&self, index: usize) -> Option<T>

Source§

fn as_slice(&self) -> Option<&[T]>

Source§

fn from_coords(coords: &[T]) -> Self

Source§

impl<T: SpatialScalar> SpatialPoint<T> for Array1<T>

Implementation of SpatialPoint for ndarray Array1

Source§

fn dimension(&self) -> usize

Source§

fn coordinate(&self, index: usize) -> Option<T>

Source§

fn as_slice(&self) -> Option<&[T]>

Source§

fn from_coords(coords: &[T]) -> Self

Source§

impl<T: SpatialScalar> SpatialPoint<T> for ArrayView1<'_, T>

Implementation of SpatialPoint for ndarray ArrayView1

Source§

fn dimension(&self) -> usize

Source§

fn coordinate(&self, index: usize) -> Option<T>

Source§

fn as_slice(&self) -> Option<&[T]>

Source§

fn from_coords(coords: &[T]) -> Self

Source§

impl<T: SpatialScalar, const N: usize> SpatialPoint<T> for [T; N]

Implementation of SpatialPoint for arrays

Source§

fn dimension(&self) -> usize

Source§

fn coordinate(&self, index: usize) -> Option<T>

Source§

fn as_slice(&self) -> Option<&[T]>

Source§

fn from_coords(coords: &[T]) -> Self

Implementors§