From 87175b66199789c4e05043aa6f0bdce89c82a6e2 Mon Sep 17 00:00:00 2001 From: Rico Riedel Date: Sat, 6 Aug 2022 15:40:46 +0200 Subject: [PATCH] Refactoring --- src/convert/char.rs | 13 ++++++------- src/pattern/circle.rs | 2 +- src/pattern/line.rs | 2 +- src/pattern/rhombus.rs | 2 +- src/pattern/wheel.rs | 2 +- src/transform/shift.rs | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/convert/char.rs b/src/convert/char.rs index 004072d..3747dce 100644 --- a/src/convert/char.rs +++ b/src/convert/char.rs @@ -11,15 +11,14 @@ pub trait CharConverter { } pub struct CharConverterImpl { - chars: String, - count: f32, + chars: Vec, } impl CharConverterImpl { pub fn new(chars: String) -> Self { - let count = chars.chars().count() as f32; + let chars = chars.chars().collect(); - Self { chars, count } + Self { chars } } } @@ -28,10 +27,10 @@ impl CharConverter for CharConverterImpl { if level < 0.0 { CharSample::Clear } else if level < 1.0 { - let index = (level * self.count) as usize; - let char = self.chars.chars().nth(index).unwrap(); + let len = self.chars.len() as f32; + let index = (level * len) as usize; - CharSample::Draw(char) + CharSample::Draw(self.chars[index]) } else { CharSample::Keep } diff --git a/src/pattern/circle.rs b/src/pattern/circle.rs index 1bd745e..8726598 100644 --- a/src/pattern/circle.rs +++ b/src/pattern/circle.rs @@ -38,7 +38,7 @@ mod test { fn sample() { let config = Config { size: Vector::new(10.0, 20.0), - step: 0.0, + ..Config::default() }; let pattern = CircleFactory::new().create(&config); diff --git a/src/pattern/line.rs b/src/pattern/line.rs index eb8aa5c..f20cf3d 100644 --- a/src/pattern/line.rs +++ b/src/pattern/line.rs @@ -36,7 +36,7 @@ mod test { fn sample() { let config = Config { size: Vector::new(20.0, 0.0), - step: 0.0, + ..Config::default() }; let pattern = LineFactory::new().create(&config); diff --git a/src/pattern/rhombus.rs b/src/pattern/rhombus.rs index 480041c..aa7c071 100644 --- a/src/pattern/rhombus.rs +++ b/src/pattern/rhombus.rs @@ -38,7 +38,7 @@ mod test { fn sample() { let config = Config { size: Vector::new(10.0, 5.0), - step: 0.0, + ..Config::default() }; let pattern = RhombusFactory::new().create(&config); diff --git a/src/pattern/wheel.rs b/src/pattern/wheel.rs index 5569fe8..b833a79 100644 --- a/src/pattern/wheel.rs +++ b/src/pattern/wheel.rs @@ -37,7 +37,7 @@ mod test { fn sample() { let config = Config { size: Vector::new(10.0, 20.0), - step: 0.0, + ..Config::default() }; let pattern = WheelFactory::new().create(&config); diff --git a/src/transform/shift.rs b/src/transform/shift.rs index 39f090d..12b0d64 100644 --- a/src/transform/shift.rs +++ b/src/transform/shift.rs @@ -50,8 +50,8 @@ mod test { #[test] fn sample_shifted() { let config = Config { - size: Vector::default(), step: 0.4, + ..Config::default() }; let mut child = MockPatternFactory::new(); child.expect_create().returning(|_| {