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 {
chars: String,
count: f32,
chars: Vec<char>,
}
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
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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(|_| {