diff --git a/examples/moving_line/src/main.rs b/examples/moving_line/src/main.rs index a570959..719b437 100644 --- a/examples/moving_line/src/main.rs +++ b/examples/moving_line/src/main.rs @@ -5,7 +5,7 @@ fn main() { let connection = Connection::open("localhost:2342").unwrap(); for x_offset in 0..usize::MAX { - let mut pixels = PixelGrid::new(PIXEL_WIDTH as usize, PIXEL_HEIGHT as usize); + let mut pixels = PixelGrid::max_sized(); for y in 0..PIXEL_HEIGHT as usize { pixels.set((y + x_offset) % PIXEL_WIDTH as usize, y, true); diff --git a/src/bit_vec.rs b/src/bit_vec.rs index 881c5c4..cef716d 100644 --- a/src/bit_vec.rs +++ b/src/bit_vec.rs @@ -1,5 +1,5 @@ /// A vector of bits -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct BitVec { data: Vec, } diff --git a/src/pixel_grid.rs b/src/pixel_grid.rs index 2c7a958..aeb0df3 100644 --- a/src/pixel_grid.rs +++ b/src/pixel_grid.rs @@ -1,6 +1,6 @@ -use crate::{BitVec}; +use crate::{BitVec, PIXEL_HEIGHT, PIXEL_WIDTH}; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct PixelGrid { pub width: usize, pub height: usize, @@ -8,7 +8,7 @@ pub struct PixelGrid { } impl PixelGrid { - pub fn new(width: usize, height: usize) -> PixelGrid { + pub fn new(width: usize, height: usize) -> Self { assert_eq!(width % 8, 0); assert_eq!(height % 8, 0); Self { @@ -18,6 +18,10 @@ impl PixelGrid { } } + pub fn max_sized() -> Self { + Self::new(PIXEL_WIDTH as usize, PIXEL_HEIGHT as usize) + } + pub fn set(&mut self, x: usize, y: usize, value: bool) -> bool { self.bit_vec.set(x + y * self.width, value) }