mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-04 23:26:41 +00:00
Refactoring
This commit is contained in:
parent
703fe1a62b
commit
87175b6619
@ -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
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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(|_| {
|
||||
|
Loading…
Reference in New Issue
Block a user