mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-22 07:56:38 +00:00
Refactoring
This commit is contained in:
parent
1785f9eec5
commit
26f4960276
@ -23,7 +23,7 @@ mod test {
|
||||
fn sample() {
|
||||
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)));
|
||||
}
|
||||
}
|
@ -12,10 +12,9 @@ pub trait Surface {
|
||||
fn draw(&mut self, x: usize, y: usize, char: char, color: Color);
|
||||
fn clear(&mut self, x: usize, y: usize);
|
||||
fn present(&mut self) -> Result<(), Error>;
|
||||
fn purge(&mut self) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
pub struct WriteSurface<T> {
|
||||
pub struct WriteSurface<T: Write> {
|
||||
out: T,
|
||||
array: Array2D<Cell>,
|
||||
}
|
||||
@ -31,7 +30,7 @@ impl Default for Cell {
|
||||
fn default() -> Self { Cell::Keep }
|
||||
}
|
||||
|
||||
impl<T> WriteSurface<T> {
|
||||
impl<T: Write> WriteSurface<T> {
|
||||
pub fn new(out: T, width: usize, height: usize) -> Self {
|
||||
Self {
|
||||
out,
|
||||
@ -87,10 +86,11 @@ impl<T: Write> Surface for WriteSurface<T> {
|
||||
self.out.flush()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn purge(&mut self) -> Result<(), Error> {
|
||||
self.out.execute(Clear(ClearType::Purge))?;
|
||||
Ok(())
|
||||
impl<T: Write> Drop for WriteSurface<T> {
|
||||
fn drop(&mut self) {
|
||||
self.out.execute(Clear(ClearType::Purge)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,9 +162,9 @@ mod test {
|
||||
// Execute
|
||||
let data = Data::new();
|
||||
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
|
||||
let expected = Data::new();
|
||||
|
Loading…
Reference in New Issue
Block a user