mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-26 09:46:37 +00:00
Refactoring
This commit is contained in:
parent
1785f9eec5
commit
26f4960276
@ -23,7 +23,7 @@ mod test {
|
|||||||
fn sample() {
|
fn sample() {
|
||||||
let mode = LevelFillMode::new();
|
let mode = LevelFillMode::new();
|
||||||
|
|
||||||
assert_eq!(0.3, mode.sample(0.3, Vector::ZERO));
|
assert_eq!(0.3, mode.sample(0.3, Vector::new(0.0, 0.0)));
|
||||||
assert_eq!(0.7, mode.sample(0.7, Vector::new(0.1, 0.2)));
|
assert_eq!(0.7, mode.sample(0.7, Vector::new(0.1, 0.2)));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,10 +12,9 @@ pub trait Surface {
|
|||||||
fn draw(&mut self, x: usize, y: usize, char: char, color: Color);
|
fn draw(&mut self, x: usize, y: usize, char: char, color: Color);
|
||||||
fn clear(&mut self, x: usize, y: usize);
|
fn clear(&mut self, x: usize, y: usize);
|
||||||
fn present(&mut self) -> Result<(), Error>;
|
fn present(&mut self) -> Result<(), Error>;
|
||||||
fn purge(&mut self) -> Result<(), Error>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WriteSurface<T> {
|
pub struct WriteSurface<T: Write> {
|
||||||
out: T,
|
out: T,
|
||||||
array: Array2D<Cell>,
|
array: Array2D<Cell>,
|
||||||
}
|
}
|
||||||
@ -31,7 +30,7 @@ impl Default for Cell {
|
|||||||
fn default() -> Self { Cell::Keep }
|
fn default() -> Self { Cell::Keep }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> WriteSurface<T> {
|
impl<T: Write> WriteSurface<T> {
|
||||||
pub fn new(out: T, width: usize, height: usize) -> Self {
|
pub fn new(out: T, width: usize, height: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
out,
|
out,
|
||||||
@ -87,10 +86,11 @@ impl<T: Write> Surface for WriteSurface<T> {
|
|||||||
self.out.flush()?;
|
self.out.flush()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn purge(&mut self) -> Result<(), Error> {
|
impl<T: Write> Drop for WriteSurface<T> {
|
||||||
self.out.execute(Clear(ClearType::Purge))?;
|
fn drop(&mut self) {
|
||||||
Ok(())
|
self.out.execute(Clear(ClearType::Purge)).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,9 +162,9 @@ mod test {
|
|||||||
// Execute
|
// Execute
|
||||||
let data = Data::new();
|
let data = Data::new();
|
||||||
let mock = MockWrite::new(data.clone());
|
let mock = MockWrite::new(data.clone());
|
||||||
let mut renderer = WriteSurface::new(mock, 4, 4);
|
let renderer = WriteSurface::new(mock, 4, 4);
|
||||||
|
|
||||||
renderer.purge().unwrap();
|
drop(renderer);
|
||||||
|
|
||||||
// Recreate expectation
|
// Recreate expectation
|
||||||
let expected = Data::new();
|
let expected = Data::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user