pub struct DataArray<T: Scalar> { /* private fields */ }Expand description
A contiguous array of tuples, where each tuple has num_components values.
This is the fundamental data container, analogous to VTK’s vtkDataArray.
Uses Arc<Vec<T>> for zero-copy clone with copy-on-write semantics.
§Examples
use crate::data::DataArray;
// Create a 3-component array (e.g., for normals or positions)
let mut normals = DataArray::<f64>::new("Normals", 3);
normals.push_tuple(&[0.0, 0.0, 1.0]);
normals.push_tuple(&[0.0, 1.0, 0.0]);
assert_eq!(normals.num_tuples(), 2);
// Create from a Vec
let scalars = DataArray::<f64>::from_vec("Temperature", vec![10.0, 20.0, 30.0], 1);
assert_eq!(scalars.num_tuples(), 3);Implementations§
Source§impl<T: Scalar> DataArray<T>
impl<T: Scalar> DataArray<T>
pub fn new(name: impl Into<String>, num_components: usize) -> Self
pub fn from_vec( name: impl Into<String>, data: Vec<T>, num_components: usize, ) -> Self
Sourcepub fn from_slice(
name: impl Into<String>,
data: &[T],
num_components: usize,
) -> Self
pub fn from_slice( name: impl Into<String>, data: &[T], num_components: usize, ) -> Self
Create from a borrowed slice (copies data).
pub fn name(&self) -> &str
pub fn set_name(&mut self, name: impl Into<String>)
pub fn scalar_type(&self) -> ScalarType
pub fn num_components(&self) -> usize
pub fn num_tuples(&self) -> usize
pub fn tuple(&self, idx: usize) -> &[T]
pub fn tuple_mut(&mut self, idx: usize) -> &mut [T]
pub fn push_tuple(&mut self, values: &[T])
pub fn as_slice(&self) -> &[T]
pub fn as_mut_slice(&mut self) -> &mut [T]
pub fn into_vec(self) -> Vec<T>
pub fn is_empty(&self) -> bool
Sourcepub fn from_fn(
name: impl Into<String>,
count: usize,
f: impl Fn(usize) -> T,
) -> Self
pub fn from_fn( name: impl Into<String>, count: usize, f: impl Fn(usize) -> T, ) -> Self
Create a 1-component DataArray by evaluating a function for each index.
Sourcepub fn from_fn_components(
name: impl Into<String>,
count: usize,
num_components: usize,
f: impl Fn(usize) -> Vec<T>,
) -> Self
pub fn from_fn_components( name: impl Into<String>, count: usize, num_components: usize, f: impl Fn(usize) -> Vec<T>, ) -> Self
Create a multi-component DataArray from a function returning a slice.
Sourcepub fn filled(
name: impl Into<String>,
value: T,
count: usize,
num_components: usize,
) -> Self
pub fn filled( name: impl Into<String>, value: T, count: usize, num_components: usize, ) -> Self
Create a DataArray filled with a constant value.
Sourcepub fn map_in_place(&mut self, f: impl Fn(T) -> T)
pub fn map_in_place(&mut self, f: impl Fn(T) -> T)
Apply a function to each scalar value in-place.
Sourcepub fn map(&self, name: impl Into<String>, f: impl Fn(T) -> T) -> Self
pub fn map(&self, name: impl Into<String>, f: impl Fn(T) -> T) -> Self
Create a new DataArray by mapping each scalar value.
Sourcepub fn map_tuples(
&self,
name: impl Into<String>,
f: impl Fn(&[T]) -> T,
) -> DataArray<T>
pub fn map_tuples( &self, name: impl Into<String>, f: impl Fn(&[T]) -> T, ) -> DataArray<T>
Create a new 1-component DataArray from a per-tuple function.
pub fn clear(&mut self)
Returns true if this array shares storage with another clone.
Sourcepub fn make_unique(&mut self)
pub fn make_unique(&mut self)
Ensure exclusive ownership. Call before tight mutation loops to avoid per-call Arc::make_mut atomic checks.
Sourcepub fn iter_tuples(&self) -> DataArrayTupleIter<'_, T> ⓘ
pub fn iter_tuples(&self) -> DataArrayTupleIter<'_, T> ⓘ
Iterate over tuples as slices.
Source§impl DataArray<f64>
impl DataArray<f64>
Source§impl DataArray<f64>
impl DataArray<f64>
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for DataArray<T>
impl<T> RefUnwindSafe for DataArray<T>where
T: RefUnwindSafe,
impl<T> Send for DataArray<T>
impl<T> Sync for DataArray<T>
impl<T> Unpin for DataArray<T>
impl<T> UnsafeUnpin for DataArray<T>
impl<T> UnwindSafe for DataArray<T>where
T: RefUnwindSafe,
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