summaryrefslogtreecommitdiff
path: root/libhitomezashi
diff options
context:
space:
mode:
Diffstat (limited to 'libhitomezashi')
-rw-r--r--libhitomezashi/.gitignore2
-rw-r--r--libhitomezashi/src/lib.rs14
-rw-r--r--libhitomezashi/src/pixel_buffer.rs8
3 files changed, 11 insertions, 13 deletions
diff --git a/libhitomezashi/.gitignore b/libhitomezashi/.gitignore
index 4fffb2f..e9e2199 100644
--- a/libhitomezashi/.gitignore
+++ b/libhitomezashi/.gitignore
@@ -1,2 +1,2 @@
-/target
+/target/
/Cargo.lock
diff --git a/libhitomezashi/src/lib.rs b/libhitomezashi/src/lib.rs
index b07057a..c2f302e 100644
--- a/libhitomezashi/src/lib.rs
+++ b/libhitomezashi/src/lib.rs
@@ -1,5 +1,5 @@
mod pixel_buffer;
-pub use bitvec::vec::BitVec;
+use bitvec::prelude::*;
use pixel_buffer::PixelBuffer;
pub fn get_hitomezashi_pattern(
@@ -52,12 +52,10 @@ mod tests {
#[test]
fn test() {
- let mut x_pattern = BitVec::new();
- x_pattern.resize(40, false);
- x_pattern.set(1, true);
- let mut y_pattern = BitVec::new();
- y_pattern.resize(40, false);
- y_pattern.set(1, true);
- println!("{}", get_hitomezashi_pattern(x_pattern, y_pattern, 3, 1));
+ let x_pattern = bitvec![1, 1, 0, 1, 1, 1];
+ let y_pattern = bitvec![0, 1, 1, 0, 0, 0];
+ let result = format!("{}", get_hitomezashi_pattern(x_pattern, y_pattern, 3, 1));
+ println!("{}", result);
+ assert!(result == "███ ███ ███ \n █ \n █ \n█ ████ ████ ███\n█ █ █ █ █ \n█ █ █ █ █ \n ████ ████ ███\n █ \n █ \n████ ████ ████ \n█ █ █ █ █ \n█ █ █ █ █ \n████ ████ ████ \n █ \n █ \n████ ████ ████ \n█ █ █ █ █ \n█ █ █ █ █ \n")
}
}
diff --git a/libhitomezashi/src/pixel_buffer.rs b/libhitomezashi/src/pixel_buffer.rs
index b151906..9b27059 100644
--- a/libhitomezashi/src/pixel_buffer.rs
+++ b/libhitomezashi/src/pixel_buffer.rs
@@ -4,7 +4,7 @@ use std::ops::{Index, IndexMut};
/// 2D buffer of monochrome (white/black i.e. true/false) pixels
pub struct PixelBuffer {
- buffer: BitVec,
+ pub buffer: BitVec,
pub width: usize,
pub height: usize,
}
@@ -47,7 +47,7 @@ impl fmt::Display for PixelBuffer {
let mut result = String::new();
for y in 0..self.height {
for x in 0..self.width {
- result.push(if self[x][y] { '1' } else { '0' })
+ result.push(if self[x][y] { '█' } else { ' ' })
}
result.push('\n')
}
@@ -81,13 +81,13 @@ mod tests {
let mut pixel_buffer = PixelBuffer::new(3, 3);
pixel_buffer[1].set(1, true);
let result = format!("{}", pixel_buffer);
- assert!(result == "000\n010\n000\n");
+ assert!(result == " \n █ \n \n");
}
#[test]
fn rect() {
let mut pixel_buffer = PixelBuffer::new(5, 3);
pixel_buffer.fill_rect(1, 0, 2, 2);
let result = format!("{}", pixel_buffer);
- assert!(result == "01100\n01100\n00000\n");
+ assert!(result == " ██ \n ██ \n \n");
}
}