Replace default with new

This commit is contained in:
Rico Riedel 2022-08-05 19:38:54 +02:00
parent 402077e109
commit 9e8e9253bd
No known key found for this signature in database
GPG Key ID: 75AC868575DE7B18
6 changed files with 14 additions and 14 deletions

View File

@ -186,10 +186,10 @@ impl Args {
impl PatternConfig {
fn create_base(&self, rand: &mut impl Rng) -> Box<dyn PatternFactory> {
match choose(self.patterns, rand) {
PatternEnum::Circle => Box::new(CircleFactory::default()),
PatternEnum::Line => Box::new(LineFactory::default()),
PatternEnum::Rhombus => Box::new(RhombusFactory::default()),
PatternEnum::Wheel => Box::new(WheelFactory::default()),
PatternEnum::Circle => Box::new(CircleFactory::new()),
PatternEnum::Line => Box::new(LineFactory::new()),
PatternEnum::Rhombus => Box::new(RhombusFactory::new()),
PatternEnum::Wheel => Box::new(WheelFactory::new()),
}
}
@ -244,7 +244,7 @@ fn main() -> Result<(), Error> {
let printer = PrinterImpl::new(term)?;
let renderer = RendererImpl::new(sampler, converter, printer);
let clock = ClockImpl::default();
let clock = ClockImpl::new();
let duration = Duration::from_millis(args.duration);
let delay = Duration::from_nanos(1_000_000_000 / args.fps);
let timer = Timer::new(clock, duration, delay);

View File

@ -1,7 +1,7 @@
use crate::pattern::*;
use crate::Vector;
#[derive(Default)]
#[derive(derive_more::Constructor)]
pub struct CircleFactory;
pub struct Circle {
center: Vector,
@ -40,7 +40,7 @@ mod test {
size: Vector::new(10.0, 20.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!(0.0, pattern.sample(Vector::new(5.0, 10.0)), epsilon = 0.1);

View File

@ -1,7 +1,7 @@
use crate::pattern::*;
use crate::Vector;
#[derive(Default)]
#[derive(derive_more::Constructor)]
pub struct LineFactory;
pub struct Line {
width: f32,
@ -38,7 +38,7 @@ mod test {
size: Vector::new(20.0, 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.4, pattern.sample(Vector::new(8.0, 8.0)), epsilon = 0.1);

View File

@ -1,7 +1,7 @@
use crate::pattern::*;
use crate::Vector;
#[derive(Default)]
#[derive(derive_more::Constructor)]
pub struct RhombusFactory;
pub struct Rhombus {
center: Vector,
@ -40,7 +40,7 @@ mod test {
size: Vector::new(10.0, 5.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(10.0, 5.0)), epsilon = 0.1);

View File

@ -2,7 +2,7 @@ use crate::pattern::*;
use crate::Vector;
use std::f32::consts::PI;
#[derive(Default)]
#[derive(derive_more::Constructor)]
pub struct WheelFactory;
pub struct Wheel {
center: Vector,
@ -39,7 +39,7 @@ mod test {
size: Vector::new(10.0, 20.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!(1.0, pattern.sample(Vector::new(0.0, 10.0)), epsilon = 0.1);

View File

@ -9,7 +9,7 @@ pub trait Clock {
fn sleep(&self, duration: Duration);
}
#[derive(Default)]
#[derive(derive_more::Constructor)]
pub struct ClockImpl;
impl Clock for ClockImpl {