diff --git a/crates/cross/src/dim/dim_slice.rs b/crates/cross/src/dim/dim_slice.rs index 0bb21d6..d573615 100644 --- a/crates/cross/src/dim/dim_slice.rs +++ b/crates/cross/src/dim/dim_slice.rs @@ -5,12 +5,12 @@ use crate::vec::Vec3u; /// use this to wrap a flat region of memory into something which can be indexed by coordinates in /// 3d space. -pub struct DimensionedSlice { +pub struct DimSlice { dim: Vec3u, items: T, } -impl DimensionedSlice { +impl DimSlice { pub fn new(dim: Vec3u, items: T) -> Self { Self { dim, items } } @@ -19,7 +19,7 @@ impl DimensionedSlice { } } -impl DimensionedSlice { +impl DimSlice { pub fn enumerated(self) -> Zip { self.indices().zip(self.into_iter()) } @@ -29,7 +29,7 @@ fn index(loc: Vec3u, dim: Vec3u) -> usize { ((loc.z()*dim.y() + loc.y())*dim.x() + loc.x()) as usize } -impl<'a, T: Index + ?Sized> Index for DimensionedSlice<&'a T> { +impl<'a, T: Index + ?Sized> Index for DimSlice<&'a T> { type Output=T::Output; fn index(&self, idx: Vec3u) -> &Self::Output { @@ -38,7 +38,7 @@ impl<'a, T: Index + ?Sized> Index for DimensionedSlice<&'a T> { } } -impl<'a, T: Index + ?Sized> Index for DimensionedSlice<&'a mut T> { +impl<'a, T: Index + ?Sized> Index for DimSlice<&'a mut T> { type Output=T::Output; fn index(&self, idx: Vec3u) -> &Self::Output { @@ -47,14 +47,14 @@ impl<'a, T: Index + ?Sized> Index for DimensionedSlice<&'a mut T> } } -impl<'a, T: IndexMut + ?Sized> IndexMut for DimensionedSlice<&'a mut T> { +impl<'a, T: IndexMut + ?Sized> IndexMut for DimSlice<&'a mut T> { fn index_mut(&mut self, idx: Vec3u) -> &mut Self::Output { let idx = index(idx, self.dim); &mut self.items[idx] } } -impl IntoIterator for DimensionedSlice { +impl IntoIterator for DimSlice { type Item = T::Item; type IntoIter = T::IntoIter; fn into_iter(self) -> Self::IntoIter { @@ -118,7 +118,7 @@ mod test { } #[test] - fn dimensioned_slice_index() { + fn dim_slice_index() { let data = [ 0, 1, 2, 3, 4, 5, @@ -126,7 +126,7 @@ mod test { 0, 10,20, 30,40,50, ]; - let s = DimensionedSlice::new(Vec3u::new(3, 2, 2), &data); + let s = DimSlice::new(Vec3u::new(3, 2, 2), &data); assert_eq!(s[Vec3u::new(0, 0, 0)], 0); assert_eq!(s[Vec3u::new(1, 0, 0)], 1); assert_eq!(s[Vec3u::new(1, 1, 0)], 4); @@ -135,7 +135,7 @@ mod test { } #[test] - fn dimensioned_slice_index_mut() { + fn dim_slice_index_mut() { let mut data = [ 0, 1, 2, 3, 4, 5, @@ -143,7 +143,7 @@ mod test { 0, 10,20, 30,40,50, ]; - let mut s = DimensionedSlice::new(Vec3u::new(3, 2, 2), &mut data); + let mut s = DimSlice::new(Vec3u::new(3, 2, 2), &mut data); s[Vec3u::new(0, 0, 0)] = 100; s[Vec3u::new(0, 1, 1)] = 300; @@ -157,9 +157,9 @@ mod test { } #[test] - fn dimensioned_slice_into_iter() { + fn dim_slice_into_iter() { let data = [1, 2, 3, 4, 5, 6]; - let s = DimensionedSlice::new(Vec3u::new(3, 1, 2), &data); + let s = DimSlice::new(Vec3u::new(3, 1, 2), &data); let mut i = s.into_iter(); assert_eq!(*i.next().unwrap(), 1); assert_eq!(*i.next().unwrap(), 2); @@ -171,9 +171,9 @@ mod test { } #[test] - fn dimensioned_slice_into_iter_mut() { + fn dim_slice_into_iter_mut() { let mut data = [1, 2, 3, 4, 5, 6]; - let s = DimensionedSlice::new(Vec3u::new(3, 1, 2), &mut data); + let s = DimSlice::new(Vec3u::new(3, 1, 2), &mut data); let mut i = s.into_iter(); *i.next().unwrap() = 10; assert_eq!(*i.next().unwrap(), 2); @@ -187,8 +187,8 @@ mod test { } #[test] - fn dimensioned_slice_indices() { - let s = DimensionedSlice::new(Vec3u::new(4, 3, 2), &[()]); + fn dim_slice_indices() { + let s = DimSlice::new(Vec3u::new(4, 3, 2), &[()]); let mut i = s.indices(); assert!(i.next().unwrap() == Vec3u::new(0, 0, 0)); assert!(i.next().unwrap() == Vec3u::new(1, 0, 0)); @@ -224,40 +224,40 @@ mod test { assert!(i.next() == None); } #[test] - fn dimensioned_slice_indices_zero_dim() { - let s = DimensionedSlice::new(Vec3u::new(4, 3, 0), &[()]); + fn dim_slice_indices_zero_dim() { + let s = DimSlice::new(Vec3u::new(4, 3, 0), &[()]); assert!(s.indices().next() == None); assert!(s.indices().next() == None); - let s = DimensionedSlice::new(Vec3u::new(4, 0, 2), &[()]); + let s = DimSlice::new(Vec3u::new(4, 0, 2), &[()]); assert!(s.indices().next() == None); assert!(s.indices().next() == None); - let s = DimensionedSlice::new(Vec3u::new(0, 3, 2), &[()]); + let s = DimSlice::new(Vec3u::new(0, 3, 2), &[()]); assert!(s.indices().next() == None); assert!(s.indices().next() == None); - let s = DimensionedSlice::new(Vec3u::new(3, 0, 0), &[()]); + let s = DimSlice::new(Vec3u::new(3, 0, 0), &[()]); assert!(s.indices().next() == None); assert!(s.indices().next() == None); - let s = DimensionedSlice::new(Vec3u::new(0, 1, 0), &[()]); + let s = DimSlice::new(Vec3u::new(0, 1, 0), &[()]); assert!(s.indices().next() == None); assert!(s.indices().next() == None); - let s = DimensionedSlice::new(Vec3u::new(0, 0, 2), &[()]); + let s = DimSlice::new(Vec3u::new(0, 0, 2), &[()]); assert!(s.indices().next() == None); assert!(s.indices().next() == None); } #[test] - fn dimensioned_slice_enumerated() { + fn dim_slice_enumerated() { let data = [ 10, 11, 20, 21, 30, 31, ]; - let s = DimensionedSlice::new(Vec3u::new(1, 2, 3), &data); + let s = DimSlice::new(Vec3u::new(1, 2, 3), &data); let mut i = s.enumerated(); assert!(i.next().unwrap() == (Vec3u::new(0, 0, 0), &10)); assert!(i.next().unwrap() == (Vec3u::new(0, 1, 0), &11)); @@ -269,13 +269,13 @@ mod test { } #[test] - fn dimensioned_slice_enumerated_mut() { + fn dim_slice_enumerated_mut() { let mut data = [ 10, 11, 20, 21, 30, 31, ]; - let s = DimensionedSlice::new(Vec3u::new(2, 1, 3), &mut data); + let s = DimSlice::new(Vec3u::new(2, 1, 3), &mut data); let mut i = s.enumerated(); let (idx, v) = i.next().unwrap(); diff --git a/crates/cross/src/dim/mod.rs b/crates/cross/src/dim/mod.rs index d835112..1b7d131 100644 --- a/crates/cross/src/dim/mod.rs +++ b/crates/cross/src/dim/mod.rs @@ -1,7 +1,7 @@ mod dim_slice; mod offset_dim_slice; pub use dim_slice::{ - DimensionedSlice, + DimSlice, DimIter, }; -pub use offset_dim_slice::OffsetDimensionedSlice; +pub use offset_dim_slice::OffsetDimSlice; diff --git a/crates/cross/src/dim/offset_dim_slice.rs b/crates/cross/src/dim/offset_dim_slice.rs index daa2300..b49d293 100644 --- a/crates/cross/src/dim/offset_dim_slice.rs +++ b/crates/cross/src/dim/offset_dim_slice.rs @@ -1,34 +1,34 @@ use core::ops::{Index, IndexMut}; -use crate::dim::DimensionedSlice; +use crate::dim::DimSlice; use crate::vec::Vec3u; -pub struct OffsetDimensionedSlice { +pub struct OffsetDimSlice { offset: Vec3u, - inner: DimensionedSlice, + inner: DimSlice, } -impl OffsetDimensionedSlice { +impl OffsetDimSlice { pub fn new(offset: Vec3u, dim: Vec3u, items: T) -> Self { - Self { offset, inner: DimensionedSlice::new(dim, items) } + Self { offset, inner: DimSlice::new(dim, items) } } } -impl Index for OffsetDimensionedSlice +impl Index for OffsetDimSlice where - DimensionedSlice: Index + DimSlice: Index { - type Output= as Index>::Output; + type Output= as Index>::Output; fn index(&self, idx: Vec3u) -> &Self::Output { &self.inner[idx - self.offset] } } -impl IndexMut for OffsetDimensionedSlice +impl IndexMut for OffsetDimSlice where - DimensionedSlice: IndexMut + DimSlice: IndexMut { fn index_mut(&mut self, idx: Vec3u) -> &mut Self::Output { &mut self.inner[idx - self.offset] @@ -48,7 +48,7 @@ mod test { 0, 10,20, 30,40,50, ]; - let s = OffsetDimensionedSlice::new(Vec3u::new(1, 2, 3), Vec3u::new(3, 2, 2), &data); + let s = OffsetDimSlice::new(Vec3u::new(1, 2, 3), Vec3u::new(3, 2, 2), &data); assert_eq!(s[Vec3u::new(1, 2, 3)], 0); assert_eq!(s[Vec3u::new(2, 2, 3)], 1); assert_eq!(s[Vec3u::new(2, 3, 3)], 4); @@ -65,7 +65,7 @@ mod test { 0, 10,20, 30,40,50, ]; - let mut s = OffsetDimensionedSlice::new(Vec3u::new(1, 2, 3), Vec3u::new(3, 2, 2), &mut data); + let mut s = OffsetDimSlice::new(Vec3u::new(1, 2, 3), Vec3u::new(3, 2, 2), &mut data); s[Vec3u::new(1, 2, 3)] = 100; s[Vec3u::new(1, 3, 4)] = 300; diff --git a/crates/cross/src/step.rs b/crates/cross/src/step.rs index 66d086d..11728ac 100644 --- a/crates/cross/src/step.rs +++ b/crates/cross/src/step.rs @@ -1,7 +1,7 @@ use core::ops::{Index, IndexMut}; use crate::compound::Optional; -use crate::dim::DimensionedSlice; +use crate::dim::DimSlice; use crate::mat::Material; use crate::real::Real; use crate::vec::{Vec3, Vec3u}; @@ -274,10 +274,10 @@ impl<'a, R: Real, M: Material> StepEContext<'a, R, M> { WF: Index> + IndexMut + ?Sized, { let dim = meta.dim; - let stim_e_matrix = DimensionedSlice::new(dim, stim_e); - let mat_matrix = DimensionedSlice::new(dim, mat); - let mut e_matrix = DimensionedSlice::new(dim, e); - let h_matrix = DimensionedSlice::new(dim, h); + let stim_e_matrix = DimSlice::new(dim, stim_e); + let mat_matrix = DimSlice::new(dim, mat); + let mut e_matrix = DimSlice::new(dim, e); + let h_matrix = DimSlice::new(dim, h); let stim_e = stim_e_matrix[idx]; let mat = &mat_matrix[idx]; @@ -342,11 +342,11 @@ impl<'a, R: Real, M: Material> StepHContext<'a, R, M> { WF: Index> + IndexMut + ?Sized, { let dim = meta.dim; - let stim_h_matrix = DimensionedSlice::new(dim, stim_h); - let mat_matrix = DimensionedSlice::new(dim, mat); - let e_matrix = DimensionedSlice::new(dim, e); - let mut h_matrix = DimensionedSlice::new(dim, h); - let mut m_matrix = DimensionedSlice::new(dim, m); + let stim_h_matrix = DimSlice::new(dim, stim_h); + let mat_matrix = DimSlice::new(dim, mat); + let e_matrix = DimSlice::new(dim, e); + let mut h_matrix = DimSlice::new(dim, h); + let mut m_matrix = DimSlice::new(dim, m); let stim_h = stim_h_matrix[idx]; let mat = &mat_matrix[idx];