Refactoring

This commit is contained in:
Rico Riedel 2022-08-06 15:40:46 +02:00
parent 703fe1a62b
commit 87175b6619
No known key found for this signature in database
GPG Key ID: 75AC868575DE7B18
6 changed files with 11 additions and 12 deletions

View File

@ -11,15 +11,14 @@ pub trait CharConverter {
} }
pub struct CharConverterImpl { pub struct CharConverterImpl {
chars: String, chars: Vec<char>,
count: f32,
} }
impl CharConverterImpl { impl CharConverterImpl {
pub fn new(chars: String) -> Self { 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 { if level < 0.0 {
CharSample::Clear CharSample::Clear
} else if level < 1.0 { } else if level < 1.0 {
let index = (level * self.count) as usize; let len = self.chars.len() as f32;
let char = self.chars.chars().nth(index).unwrap(); let index = (level * len) as usize;
CharSample::Draw(char) CharSample::Draw(self.chars[index])
} else { } else {
CharSample::Keep CharSample::Keep
} }

View File

@ -38,7 +38,7 @@ mod test {
fn sample() { fn sample() {
let config = Config { let config = Config {
size: Vector::new(10.0, 20.0), size: Vector::new(10.0, 20.0),
step: 0.0, ..Config::default()
}; };
let pattern = CircleFactory::new().create(&config); let pattern = CircleFactory::new().create(&config);

View File

@ -36,7 +36,7 @@ mod test {
fn sample() { fn sample() {
let config = Config { let config = Config {
size: Vector::new(20.0, 0.0), size: Vector::new(20.0, 0.0),
step: 0.0, ..Config::default()
}; };
let pattern = LineFactory::new().create(&config); let pattern = LineFactory::new().create(&config);

View File

@ -38,7 +38,7 @@ mod test {
fn sample() { fn sample() {
let config = Config { let config = Config {
size: Vector::new(10.0, 5.0), size: Vector::new(10.0, 5.0),
step: 0.0, ..Config::default()
}; };
let pattern = RhombusFactory::new().create(&config); let pattern = RhombusFactory::new().create(&config);

View File

@ -37,7 +37,7 @@ mod test {
fn sample() { fn sample() {
let config = Config { let config = Config {
size: Vector::new(10.0, 20.0), size: Vector::new(10.0, 20.0),
step: 0.0, ..Config::default()
}; };
let pattern = WheelFactory::new().create(&config); let pattern = WheelFactory::new().create(&config);

View File

@ -50,8 +50,8 @@ mod test {
#[test] #[test]
fn sample_shifted() { fn sample_shifted() {
let config = Config { let config = Config {
size: Vector::default(),
step: 0.4, step: 0.4,
..Config::default()
}; };
let mut child = MockPatternFactory::new(); let mut child = MockPatternFactory::new();
child.expect_create().returning(|_| { child.expect_create().returning(|_| {