mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 18:10:14 +01:00
PixelGrid::max_sized, cloneable
This commit is contained in:
parent
2ff0ffa0d6
commit
a7b6cf2ad0
|
@ -5,7 +5,7 @@ fn main() {
|
||||||
let connection = Connection::open("localhost:2342").unwrap();
|
let connection = Connection::open("localhost:2342").unwrap();
|
||||||
|
|
||||||
for x_offset in 0..usize::MAX {
|
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 {
|
for y in 0..PIXEL_HEIGHT as usize {
|
||||||
pixels.set((y + x_offset) % PIXEL_WIDTH as usize, y, true);
|
pixels.set((y + x_offset) % PIXEL_WIDTH as usize, y, true);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/// A vector of bits
|
/// A vector of bits
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct BitVec {
|
pub struct BitVec {
|
||||||
data: Vec<u8>,
|
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 struct PixelGrid {
|
||||||
pub width: usize,
|
pub width: usize,
|
||||||
pub height: usize,
|
pub height: usize,
|
||||||
|
@ -8,7 +8,7 @@ pub struct PixelGrid {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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!(width % 8, 0);
|
||||||
assert_eq!(height % 8, 0);
|
assert_eq!(height % 8, 0);
|
||||||
Self {
|
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 {
|
pub fn set(&mut self, x: usize, y: usize, value: bool) -> bool {
|
||||||
self.bit_vec.set(x + y * self.width, value)
|
self.bit_vec.set(x + y * self.width, value)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue