pub struct Canvas<T> {
pub data: Vec<T>,
pub width: usize,
pub height: usize,
}Expand description
A struct containing a single vector abstracted to a 2 dimensional array.
§Arguments
data The actual data, stored as a Vec<T>
width The width of the canvas
height The height of the canvas
§Note
The canvas is repesented by a single vector of type <T>. The canvas can be interpreted in any
direction, but it was intended to start at the top left corner, and goes from left to right, up
to down.
The functions provided allow access to each elemeny by row and column, as well as access to
iterators over the whole canvas. If you prefer the raw data, then you can access the data
field directly.
Fields§
§data: Vec<T>§width: usize§height: usizeImplementations§
Source§impl<T: Clone> Canvas<T>
impl<T: Clone> Canvas<T>
Sourcepub fn new(width: usize, height: usize, background_data: T) -> Canvas<T>
pub fn new(width: usize, height: usize, background_data: T) -> Canvas<T>
Creates a new canvas of the specified size. The background data is the default data that will fill the canvas at initialization.
Background data type must implement the Clone trait.
Sourcepub fn get(&self, row: usize, col: usize) -> Option<&T>
pub fn get(&self, row: usize, col: usize) -> Option<&T>
Return the pixel value at the specified row and column.
Sourcepub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut T>
pub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut T>
Return a mutable reference to the pixel at the specified row and column.