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