PixelGrid::max_sized, cloneable
This commit is contained in:
		
							parent
							
								
									2ff0ffa0d6
								
							
						
					
					
						commit
						a7b6cf2ad0
					
				
					 3 changed files with 9 additions and 5 deletions
				
			
		|  | @ -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); | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| /// A vector of bits
 | ||||
| #[derive(Debug)] | ||||
| #[derive(Debug, Clone)] | ||||
| pub struct BitVec { | ||||
|     data: Vec<u8>, | ||||
| } | ||||
|  |  | |||
|  | @ -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) | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter