Skip to main content

Line1D

Struct Line1D 

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

A one-dimensional line lattice.

Each cell has coordinate [i] where 0 <= i < len. Boundary handling is controlled by EdgeBehavior:

  • Absorb: edge cells have fewer neighbors
  • Clamp: edge cells self-loop
  • Wrap: periodic boundary (equivalent to Ring1D)

§Examples

use murk_space::{Line1D, EdgeBehavior, Space};

let line = Line1D::new(5, EdgeBehavior::Absorb).unwrap();
assert_eq!(line.len(), 5);
assert_eq!(line.cell_count(), 5);
assert_eq!(line.ndim(), 1);

// Interior cell has two neighbours.
let coord: murk_core::Coord = vec![2i32].into();
assert_eq!(line.neighbours(&coord).len(), 2);

// Edge cell (absorb) has only one neighbour.
let edge: murk_core::Coord = vec![0i32].into();
assert_eq!(line.neighbours(&edge).len(), 1);

Implementations§

Source§

impl Line1D

Source

pub const MAX_LEN: u32

Maximum length: coordinates use i32, so len must fit.

Source

pub fn new(len: u32, edge: EdgeBehavior) -> Result<Self, SpaceError>

Create a new 1D line with len cells and the given edge behavior.

Returns Err(SpaceError::EmptySpace) if len == 0, or Err(SpaceError::DimensionTooLarge) if len > i32::MAX.

Source

pub fn len(&self) -> u32

Number of cells.

Source

pub fn is_empty(&self) -> bool

Always returns false — construction rejects len == 0.

Source

pub fn edge_behavior(&self) -> EdgeBehavior

Edge behavior.

Trait Implementations§

Source§

impl Clone for Line1D

Source§

fn clone(&self) -> Line1D

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 Line1D

Source§

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

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

impl Space for Line1D

Source§

fn ndim(&self) -> usize

Number of spatial dimensions.
Source§

fn cell_count(&self) -> usize

Total number of cells in the space.
Source§

fn neighbours(&self, coord: &Coord) -> SmallVec<[Coord; 8]>

Enumerate the neighbors of a cell. Read more
Source§

fn max_neighbour_degree(&self) -> usize

Maximum neighbor-list length over all cells in this space. Read more
Source§

fn distance(&self, a: &Coord, b: &Coord) -> f64

Graph-geodesic distance between two cells.
Source§

fn compile_region(&self, spec: &RegionSpec) -> Result<RegionPlan, SpaceError>

Compile a region specification into a plan for O(1) lookups.
Source§

fn canonical_ordering(&self) -> Vec<Coord>

All cells in deterministic canonical order. Read more
Source§

fn canonical_rank(&self, coord: &Coord) -> Option<usize>

Position of a coordinate in the canonical ordering. Read more
Source§

fn canonical_rank_slice(&self, coord: &[i32]) -> Option<usize>

Position of a coordinate slice in the canonical ordering. Read more
Source§

fn instance_id(&self) -> SpaceInstanceId

Unique instance identifier for this space object. Read more
Source§

fn topology_eq(&self, other: &dyn Space) -> bool

Returns true if self and other are topologically equivalent: same concrete type and identical behavioral parameters. Read more
Source§

fn iter_region<'a>( &'a self, plan: &'a RegionPlan, ) -> Box<dyn Iterator<Item = Coord> + 'a>

Iterate over the cells in a compiled region. Read more
Source§

fn map_coord_to_tensor_index( &self, coord: &Coord, plan: &RegionPlan, ) -> Option<usize>

Map a coordinate to its flat tensor index within a compiled region. Read more

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