Struct Point

Source
pub struct Point { /* private fields */ }
Expand description

Point represents a specific coordinate within the multi-dimensional space defined by an Extent.

A Point can be viewed in two equivalent ways:

  • Coordinates: a tuple of indices, one per dimension, retrievable with Point::coord and Point::coords.
  • Rank: a single linearized index into the extent’s row-major ordering, retrievable with Point::rank.

Internally, a Point stores:

  • A rank: the row-major linearized index of this point.
  • An extent: the extent that defines its dimensionality and sizes.

These fields are private; use the accessor methods instead.

§Examples

use ndslice::extent;

let ext = extent!(zone = 2, host = 4, gpu = 8);
let point = ext.point(vec![1, 2, 3]).unwrap();

// Coordinate-based access
assert_eq!(point.coord(0), 1);
assert_eq!(point.coord(1), 2);
assert_eq!(point.coord(2), 3);

// Rank-based access
assert_eq!(point.rank(), 1 * (4 * 8) + 2 * 8 + 3);

Implementations§

Source§

impl Point

Source

pub fn coords_iter(&self) -> CoordIter<'_>

Source

pub fn coord(&self, i: usize) -> usize

Returns the coordinate of this Point along the given axis.

The axis index i must be less than the number of dimensions in the Extent, otherwise this function will panic. Computes only the i-th coordinate from the point’s row-major rank, avoiding materialization of the full coordinate vector.

§Examples
use ndslice::extent;

let ext = extent!(x = 2, y = 3);
let point = ext.point(vec![1, 2]).unwrap();
assert_eq!(point.coord(0), 1); // x
assert_eq!(point.coord(1), 2); // y
Source

pub fn coords(&self) -> Vec<usize>

Returns the full coordinate vector for this Point (allocates).

The vector contains one coordinate per dimension of the Extent, reconstructed from the point’s row-major rank.

§Examples
use ndslice::extent;

let ext = extent!(x = 2, y = 3);
let point = ext.point(vec![1, 2]).unwrap();
assert_eq!(point.coords(), vec![1, 2]);
Source

pub fn rank(&self) -> usize

Returns the linearized row-major rank of this Point within its Extent.

Source

pub fn extent(&self) -> &Extent

Returns the Extent that defines the coordinate space of this Point.

Source

pub fn len(&self) -> usize

Returns the number of dimensions in this Point’s Extent.

This corresponds to the dimensionality of the coordinate space, i.e. how many separate axes (labels) are present.

§Examples
use ndslice::extent;

let ext = extent!(x = 2, y = 3, z = 4);
let point = ext.point(vec![1, 2, 3]).unwrap();
assert_eq!(point.len(), 3); // x, y, z
Source

pub fn is_empty(&self) -> bool

Returns true if this Point lies in a 0-dimensional Extent.

A 0-D extent has no coordinate axes and exactly one valid point (the empty tuple []).

§Examples
use ndslice::extent;

let ext = extent!();
let point = ext.point(vec![]).unwrap();
assert!(point.is_empty());
assert_eq!(point.len(), 0);

Trait Implementations§

Source§

impl Clone for Point

Source§

fn clone(&self) -> Point

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 Debug for Point

Source§

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

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

impl<'de> Deserialize<'de> for Point

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Point

Formats a Point as a comma-separated list of per-axis coordinates against the point’s extent:

label=coord/size[,label=coord/size,...]

§Grammar

Point    := Pair ( "," Pair )*
Pair     := Label "=" Coord "/" Size
Label    := SafeIdent | Quoted
SafeIdent:= [A-Za-z0-9_]+
Quoted   := "\"" ( [^"\\] | "\\" . )* "\""   // Rust string-literal style
Coord    := [0-9]+
Size     := [0-9]+

§Quoting rules

  • Labels that are not SafeIdent are rendered using Rust string-literal syntax (via labels::fmt_label), e.g. "dim/0" or "x y".
  • “Safe” means ASCII alphanumeric or underscore ([A-Za-z0-9_]+). Everything else is quoted.
  • Coordinates are shown in row-major order and each is paired with that axis’s size from the point’s extent.

§Examples

x=1/4,y=2/5,z=3/6
"dim/0"=1/3,"dim,1"=2/5

Implementation note: label rendering is delegated to labels::fmt_label to keep quoting behavior consistent with Extent and Region.

Source§

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

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

impl FromStr for Point

Source§

type Err = PointError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Point

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<'a> IntoIterator for &'a Point

Source§

fn into_iter(self) -> Self::IntoIter

Iterate over the coordinate values of a Point (without allocating).

This allows using a Point directly in a for loop:

use ndslice::extent;

let ext = extent!(x = 2, y = 3);
let point = ext.point(vec![1, 2]).unwrap();

let coords: Vec<_> = (&point).into_iter().collect();
assert_eq!(coords, vec![1, 2]);

for coord in &point {
    println!("{}", coord);
}
Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = CoordIter<'a>

Which kind of iterator are we turning this into?
Source§

impl PartialEq for Point

Source§

fn eq(&self, other: &Point) -> 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 Serialize for Point

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Point

Source§

impl StructuralPartialEq for Point

Auto Trait Implementations§

§

impl Freeze for Point

§

impl RefUnwindSafe for Point

§

impl Send for Point

§

impl Sync for Point

§

impl Unpin for Point

§

impl UnwindSafe for Point

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,