Trait toodee::TranslateOps
source · pub trait TranslateOps<T>: TooDeeOpsMut<T> {
// Provided methods
fn translate_with_wrap(&mut self, mid: Coordinate) { ... }
fn flip_rows(&mut self) { ... }
fn flip_cols(&mut self) { ... }
}
Expand description
Provides implementations for translate (also known as scroll) operations, and other internal data movement operations such as flipping.
Provided Methods§
sourcefn translate_with_wrap(&mut self, mid: Coordinate)
fn translate_with_wrap(&mut self, mid: Coordinate)
Translate (or scroll) the entire area. The mid
coordinate will be moved to (0, 0), and
all other elements will be moved in the same fashion. All the original data is preserved by
wrapping at the array edges.
If you don’t want the wrapped data, simply overwrite it after translation.
Examples
use toodee::{TooDee,TooDeeOps,TranslateOps};
let v = vec![42u32; 15];
let mut toodee : TooDee<u32> = TooDee::from_vec(5, 3, v);
toodee[1][1] = 1;
// move (1, 1) to (0, 0)
toodee.translate_with_wrap((1, 1));
assert_eq!(toodee[0][0], 1);
assert_eq!(toodee[1][1], 42);
use toodee::{TooDee,TooDeeOps,TranslateOps};
let v = vec![42u32; 15];
let mut toodee : TooDee<u32> = TooDee::from_vec(5, 3, v);
// set (4, 2) to 1
toodee[(4, 2)] = 1;
// move (4, 2) to (0, 0)
toodee.translate_with_wrap((4, 2));
assert_eq!(toodee[0][0], 1);
assert_eq!(toodee[2][4], 42);