mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-22 07:56:38 +00:00
Replace default with new
This commit is contained in:
parent
402077e109
commit
9e8e9253bd
10
src/main.rs
10
src/main.rs
@ -186,10 +186,10 @@ impl Args {
|
|||||||
impl PatternConfig {
|
impl PatternConfig {
|
||||||
fn create_base(&self, rand: &mut impl Rng) -> Box<dyn PatternFactory> {
|
fn create_base(&self, rand: &mut impl Rng) -> Box<dyn PatternFactory> {
|
||||||
match choose(self.patterns, rand) {
|
match choose(self.patterns, rand) {
|
||||||
PatternEnum::Circle => Box::new(CircleFactory::default()),
|
PatternEnum::Circle => Box::new(CircleFactory::new()),
|
||||||
PatternEnum::Line => Box::new(LineFactory::default()),
|
PatternEnum::Line => Box::new(LineFactory::new()),
|
||||||
PatternEnum::Rhombus => Box::new(RhombusFactory::default()),
|
PatternEnum::Rhombus => Box::new(RhombusFactory::new()),
|
||||||
PatternEnum::Wheel => Box::new(WheelFactory::default()),
|
PatternEnum::Wheel => Box::new(WheelFactory::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ fn main() -> Result<(), Error> {
|
|||||||
let printer = PrinterImpl::new(term)?;
|
let printer = PrinterImpl::new(term)?;
|
||||||
let renderer = RendererImpl::new(sampler, converter, printer);
|
let renderer = RendererImpl::new(sampler, converter, printer);
|
||||||
|
|
||||||
let clock = ClockImpl::default();
|
let clock = ClockImpl::new();
|
||||||
let duration = Duration::from_millis(args.duration);
|
let duration = Duration::from_millis(args.duration);
|
||||||
let delay = Duration::from_nanos(1_000_000_000 / args.fps);
|
let delay = Duration::from_nanos(1_000_000_000 / args.fps);
|
||||||
let timer = Timer::new(clock, duration, delay);
|
let timer = Timer::new(clock, duration, delay);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::pattern::*;
|
use crate::pattern::*;
|
||||||
use crate::Vector;
|
use crate::Vector;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(derive_more::Constructor)]
|
||||||
pub struct CircleFactory;
|
pub struct CircleFactory;
|
||||||
pub struct Circle {
|
pub struct Circle {
|
||||||
center: Vector,
|
center: Vector,
|
||||||
@ -40,7 +40,7 @@ mod test {
|
|||||||
size: Vector::new(10.0, 20.0),
|
size: Vector::new(10.0, 20.0),
|
||||||
step: 0.0,
|
step: 0.0,
|
||||||
};
|
};
|
||||||
let pattern = CircleFactory::default().create(&config);
|
let pattern = CircleFactory::new().create(&config);
|
||||||
|
|
||||||
assert_abs_diff_eq!(1.0, pattern.sample(Vector::new(0.0, 0.0)), epsilon = 0.1);
|
assert_abs_diff_eq!(1.0, pattern.sample(Vector::new(0.0, 0.0)), epsilon = 0.1);
|
||||||
assert_abs_diff_eq!(0.0, pattern.sample(Vector::new(5.0, 10.0)), epsilon = 0.1);
|
assert_abs_diff_eq!(0.0, pattern.sample(Vector::new(5.0, 10.0)), epsilon = 0.1);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::pattern::*;
|
use crate::pattern::*;
|
||||||
use crate::Vector;
|
use crate::Vector;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(derive_more::Constructor)]
|
||||||
pub struct LineFactory;
|
pub struct LineFactory;
|
||||||
pub struct Line {
|
pub struct Line {
|
||||||
width: f32,
|
width: f32,
|
||||||
@ -38,7 +38,7 @@ mod test {
|
|||||||
size: Vector::new(20.0, 0.0),
|
size: Vector::new(20.0, 0.0),
|
||||||
step: 0.0,
|
step: 0.0,
|
||||||
};
|
};
|
||||||
let pattern = LineFactory::default().create(&config);
|
let pattern = LineFactory::new().create(&config);
|
||||||
|
|
||||||
assert_abs_diff_eq!(0.0, pattern.sample(Vector::new(0.0, 4.0)), epsilon = 0.1);
|
assert_abs_diff_eq!(0.0, pattern.sample(Vector::new(0.0, 4.0)), epsilon = 0.1);
|
||||||
assert_abs_diff_eq!(0.4, pattern.sample(Vector::new(8.0, 8.0)), epsilon = 0.1);
|
assert_abs_diff_eq!(0.4, pattern.sample(Vector::new(8.0, 8.0)), epsilon = 0.1);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::pattern::*;
|
use crate::pattern::*;
|
||||||
use crate::Vector;
|
use crate::Vector;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(derive_more::Constructor)]
|
||||||
pub struct RhombusFactory;
|
pub struct RhombusFactory;
|
||||||
pub struct Rhombus {
|
pub struct Rhombus {
|
||||||
center: Vector,
|
center: Vector,
|
||||||
@ -40,7 +40,7 @@ mod test {
|
|||||||
size: Vector::new(10.0, 5.0),
|
size: Vector::new(10.0, 5.0),
|
||||||
step: 0.0,
|
step: 0.0,
|
||||||
};
|
};
|
||||||
let pattern = RhombusFactory::default().create(&config);
|
let pattern = RhombusFactory::new().create(&config);
|
||||||
|
|
||||||
assert_abs_diff_eq!(1.0, pattern.sample(Vector::new(0.0, 0.0)), epsilon = 0.1);
|
assert_abs_diff_eq!(1.0, pattern.sample(Vector::new(0.0, 0.0)), epsilon = 0.1);
|
||||||
assert_abs_diff_eq!(1.0, pattern.sample(Vector::new(10.0, 5.0)), epsilon = 0.1);
|
assert_abs_diff_eq!(1.0, pattern.sample(Vector::new(10.0, 5.0)), epsilon = 0.1);
|
||||||
|
@ -2,7 +2,7 @@ use crate::pattern::*;
|
|||||||
use crate::Vector;
|
use crate::Vector;
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(derive_more::Constructor)]
|
||||||
pub struct WheelFactory;
|
pub struct WheelFactory;
|
||||||
pub struct Wheel {
|
pub struct Wheel {
|
||||||
center: Vector,
|
center: Vector,
|
||||||
@ -39,7 +39,7 @@ mod test {
|
|||||||
size: Vector::new(10.0, 20.0),
|
size: Vector::new(10.0, 20.0),
|
||||||
step: 0.0,
|
step: 0.0,
|
||||||
};
|
};
|
||||||
let pattern = WheelFactory::default().create(&config);
|
let pattern = WheelFactory::new().create(&config);
|
||||||
|
|
||||||
assert_abs_diff_eq!(0.0, pattern.sample(Vector::new(0.0, 9.0)), epsilon = 0.1);
|
assert_abs_diff_eq!(0.0, pattern.sample(Vector::new(0.0, 9.0)), epsilon = 0.1);
|
||||||
assert_abs_diff_eq!(1.0, pattern.sample(Vector::new(0.0, 10.0)), epsilon = 0.1);
|
assert_abs_diff_eq!(1.0, pattern.sample(Vector::new(0.0, 10.0)), epsilon = 0.1);
|
||||||
|
@ -9,7 +9,7 @@ pub trait Clock {
|
|||||||
fn sleep(&self, duration: Duration);
|
fn sleep(&self, duration: Duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(derive_more::Constructor)]
|
||||||
pub struct ClockImpl;
|
pub struct ClockImpl;
|
||||||
|
|
||||||
impl Clock for ClockImpl {
|
impl Clock for ClockImpl {
|
||||||
|
Loading…
Reference in New Issue
Block a user