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::coordandPoint::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
impl Point
pub fn coords_iter(&self) -> CoordIter<'_> ⓘ
Sourcepub fn coord(&self, i: usize) -> usize
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); // ySourcepub fn coords(&self) -> Vec<usize>
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]);Sourcepub fn len(&self) -> usize
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, zSourcepub fn format_as_dict(&self) -> String
pub fn format_as_dict(&self) -> String
Formats the coordinates of this Point as a string suitable for display names. Returns a string in the format: “{‘label’: coord/size, ‘label’: coord/size, …}”
§Examples
use ndslice::extent;
let ext = extent!(x = 2, y = 3);
let point = ext.point(vec![1, 2]).unwrap();
assert_eq!(point.format_as_dict(), "{'x': 1/2, 'y': 2/3}");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Point
impl<'de> Deserialize<'de> for Point
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Point
Formats a Point as a comma-separated list of per-axis
coordinates against the point’s extent:
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
SafeIdentare rendered using Rust string-literal syntax (vialabels::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/5Implementation note: label rendering is delegated to
labels::fmt_label to keep quoting behavior consistent with
Extent and Region.
Source§impl<'a> IntoIterator for &'a Point
impl<'a> IntoIterator for &'a Point
Source§fn into_iter(self) -> Self::IntoIter
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);
}impl Eq for Point
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> 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