Struct all_is_cubes::math::Vol
source · pub struct Vol<C, O = ZMaj> { /* private fields */ }Expand description
Type for volume data stored in a slice, or for generating linear indexing.
Cis some slice container type, e.g.&[T]orBox<[T]>. It may also be()to describe a linearization without actually storing data.Ospecifies the choice of linearization. Currently, only one choice exists,ZMaj.
In addition to the data, each Vol stores the GridAab defining its size;
the container’s length must be equal to the volume of that AAB. Whether that can be
relied upon entirely depends on whether the specific container value produces
the same length of slice every time it is Dereferenced without mutating it directly.
For example, Vec<T> and Box<[T]> satisfy this criterion; the fact that [Vec] has
length-mutating operations is irrelevant because no &mut Vec<T> is exposed.
A Vol whose volume exceeds usize::MAX cannot exist.
Implementations§
source§impl<O> Vol<(), O>
impl<O> Vol<(), O>
sourcepub fn with_elements<C, V>(
self,
elements: C,
) -> Result<Vol<C, O>, VolLengthError>
pub fn with_elements<C, V>( self, elements: C, ) -> Result<Vol<C, O>, VolLengthError>
Attach some data to this dataless Vol.
Returns a VolLengthError if the number of elements does not match
bounds.volume().
source§impl Vol<()>
impl Vol<()>
sourcepub fn subdivide(self) -> Option<(Vol<()>, Vol<()>)>
pub fn subdivide(self) -> Option<(Vol<()>, Vol<()>)>
Divide self into two approximately equal-sized parts which, if they had elements, would
each be contiguous in the linear ordering.
Returns None if self does not have at least two cubes.
Note that this is one of several subdivide() methods for different container types;
it is also implemented for immutable and mutable references.
These are intended to be useful in executing parallel algorithms on volume data.
source§impl<C, O, V> Vol<C, O>
impl<C, O, V> Vol<C, O>
Constructors from linear containers.
sourcepub fn from_elements(
bounds: GridAab,
elements: impl Into<C>,
) -> Result<Vol<C, O>, VolLengthError>
pub fn from_elements( bounds: GridAab, elements: impl Into<C>, ) -> Result<Vol<C, O>, VolLengthError>
Constructs a Vol<C> containing the provided elements, which must be in the
ordering specified by O.
Returns a VolLengthError if the number of elements does not match
bounds.volume().
source§impl<C, V> Vol<C>
impl<C, V> Vol<C>
Constructors from elements.
sourcepub fn from_fn<F>(bounds: GridAab, f: F) -> Vol<C>
pub fn from_fn<F>(bounds: GridAab, f: F) -> Vol<C>
Constructs a Vol<C> by using the provided function to compute a value
for each point.
Panics if bounds has a volume exceeding usize::MAX.
(But there will likely be a memory allocation failure well below that point.)
sourcepub fn repeat(bounds: GridAab, value: V) -> Vol<C>where
V: Clone,
pub fn repeat(bounds: GridAab, value: V) -> Vol<C>where
V: Clone,
Constructs a Vol<C> by cloning the provided value for each point.
TODO: This feels like it should be called ‘filled’ or ‘cloned’, but if so,
maybe FaceMap::repeat should also change?
sourcepub fn from_element(value: V) -> Vol<C>
pub fn from_element(value: V) -> Vol<C>
Constructs a Vol<C> with a single value, in bounds ORIGIN_CUBE.
If the single element should be at a different location, you can call
.translate(offset), or use Vol::from_elements()
instead.
source§impl<C, O> Vol<C, O>
impl<C, O> Vol<C, O>
sourcepub fn into_elements(self) -> C
pub fn into_elements(self) -> C
Extracts the linear contents, discarding the bounds and ordering.
sourcepub fn without_elements(&self) -> Vol<(), O>where
O: Clone,
pub fn without_elements(&self) -> Vol<(), O>where
O: Clone,
Returns a Vol with the same bounds and ordering but no data.
This is the inverse operation to Vol::with_elements().
source§impl<C> Vol<C>
impl<C> Vol<C>
sourcepub fn iter_cubes(&self) -> GridIter ⓘ
pub fn iter_cubes(&self) -> GridIter ⓘ
Iterate over all cubes that this contains, in the order of the linearization, without including the stored data (if there is any).
sourcepub fn index(&self, cube: Cube) -> Option<usize>
pub fn index(&self, cube: Cube) -> Option<usize>
Determines whether a unit cube lies within this volume and, if it does, returns the linearized slice index into it.
The linearized element order is defined by the O type.
use all_is_cubes::math::{Vol, GridAab};
let vol = GridAab::from_lower_size([0, 0, 0], [10, 10, 10]).to_vol().unwrap();
assert_eq!(vol.index([0, 0, 0].into()), Some(0));
assert_eq!(vol.index([1, 2, 3].into()), Some(123));
assert_eq!(vol.index([9, 9, 9].into()), Some(999));
assert_eq!(vol.index([0, 0, -1].into()), None);
assert_eq!(vol.index([0, 0, 10].into()), None);TODO: more example, less unit-test
source§impl<C, O, V> Vol<C, O>
impl<C, O, V> Vol<C, O>
Linear data access.
source§impl<'a, V> Vol<&'a [V]>
impl<'a, V> Vol<&'a [V]>
sourcepub fn subdivide(self) -> Option<(Vol<&'a [V]>, Vol<&'a [V]>)>
pub fn subdivide(self) -> Option<(Vol<&'a [V]>, Vol<&'a [V]>)>
Divide self into two approximately equal-sized parts,
each of which refers to the appropriate sub-slice of elements.
Returns None if self does not have at least two cubes.
Note that this is one of several subdivide() methods for different container types;
it is also implemented for mutable references and ().
These are intended to be useful in executing parallel algorithms on volume data.
source§impl<'a, V> Vol<&'a mut [V]>
impl<'a, V> Vol<&'a mut [V]>
sourcepub fn subdivide(self) -> Option<(Vol<&'a mut [V]>, Vol<&'a mut [V]>)>
pub fn subdivide(self) -> Option<(Vol<&'a mut [V]>, Vol<&'a mut [V]>)>
Divide self into two approximately equal-sized parts.
each of which refers to the appropriate sub-slice of elements.
Returns None if self does not have at least two cubes.
Note that this is one of several subdivide() methods for different container types;
it is also implemented for immutable references and ().
These are intended to be useful in executing parallel algorithms on volume data.
source§impl<C, V> Vol<C>
impl<C, V> Vol<C>
Element lookup operations by 3D coordinates.
sourcepub fn get(&self, position: impl Into<Cube>) -> Option<&V>
pub fn get(&self, position: impl Into<Cube>) -> Option<&V>
Returns the element at position of this volume data, or None if position is out
of bounds.
sourcepub fn get_mut(&mut self, position: impl Into<Cube>) -> Option<&mut V>where
C: DerefMut,
pub fn get_mut(&mut self, position: impl Into<Cube>) -> Option<&mut V>where
C: DerefMut,
Returns a mutable reference to the element at position of this volume data,
or None if position is out of bounds.
Trait Implementations§
source§impl<'a, V, C> Arbitrary<'a> for Vol<C>
impl<'a, V, C> Arbitrary<'a> for Vol<C>
source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Vol<C>, Error>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Vol<C>, Error>
Self from the given unstructured data. Read moresource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moresource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moresource§impl<O> PartialEq<GridAab> for Vol<(), O>
impl<O> PartialEq<GridAab> for Vol<(), O>
source§impl<O> PartialEq<Vol<(), O>> for GridAab
impl<O> PartialEq<Vol<(), O>> for GridAab
source§impl<C, O> PartialEq for Vol<C, O>
impl<C, O> PartialEq for Vol<C, O>
impl<C, O> Copy for Vol<C, O>
impl<C, O> Eq for Vol<C, O>
impl SpaceBuilderBounds for Vol<()>
impl<C, O> StructuralPartialEq for Vol<C, O>
Auto Trait Implementations§
impl<C, O> Freeze for Vol<C, O>
impl<C, O> RefUnwindSafe for Vol<C, O>where
O: RefUnwindSafe,
C: RefUnwindSafe,
impl<C, O> Send for Vol<C, O>
impl<C, O> Sync for Vol<C, O>
impl<C, O> Unpin for Vol<C, O>
impl<C, O> UnwindSafe for Vol<C, O>where
O: UnwindSafe,
C: UnwindSafe,
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> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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