mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-16 04:56:43 +00:00
Rename units to segments
This commit is contained in:
parent
5bf391e5ff
commit
66a5ec78f3
14
src/main.rs
14
src/main.rs
@ -51,9 +51,9 @@ struct Args {
|
|||||||
/// Swap the x-axis and y-axis of the pattern
|
/// Swap the x-axis and y-axis of the pattern
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
char_swap: Option<bool>,
|
char_swap: Option<bool>,
|
||||||
/// Set the count of units of the pattern [default: 1-4]
|
/// Set the count of segments of the pattern [default: 1-4]
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
char_units: Option<u8>,
|
char_segments: Option<u8>,
|
||||||
/// Set the count of slices of the pattern [default: 1-4]
|
/// Set the count of slices of the pattern [default: 1-4]
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
char_slices: Option<u8>,
|
char_slices: Option<u8>,
|
||||||
@ -119,7 +119,7 @@ struct PatternConfig {
|
|||||||
shift: Option<bool>,
|
shift: Option<bool>,
|
||||||
invert: Option<bool>,
|
invert: Option<bool>,
|
||||||
swap: Option<bool>,
|
swap: Option<bool>,
|
||||||
units: Option<u8>,
|
segments: Option<u8>,
|
||||||
slices: Option<u8>,
|
slices: Option<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ impl Args {
|
|||||||
Some(true),
|
Some(true),
|
||||||
self.char_invert,
|
self.char_invert,
|
||||||
self.char_swap,
|
self.char_swap,
|
||||||
self.char_units,
|
self.char_segments,
|
||||||
self.char_slices,
|
self.char_slices,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ impl PatternConfig {
|
|||||||
|
|
||||||
fn create(&self, rand: &mut impl Rng) -> Box<dyn PatternFactory> {
|
fn create(&self, rand: &mut impl Rng) -> Box<dyn PatternFactory> {
|
||||||
let mut pattern = self.create_base(rand);
|
let mut pattern = self.create_base(rand);
|
||||||
let units = self.units.unwrap_or(rand.gen_range(1..=4));
|
let segments = self.segments.unwrap_or(rand.gen_range(1..=4));
|
||||||
let slices = self.slices.unwrap_or(rand.gen_range(1..=4));
|
let slices = self.slices.unwrap_or(rand.gen_range(1..=4));
|
||||||
|
|
||||||
if self.shift.unwrap_or(rand.gen()) {
|
if self.shift.unwrap_or(rand.gen()) {
|
||||||
@ -207,8 +207,8 @@ impl PatternConfig {
|
|||||||
if self.swap.unwrap_or(rand.gen()) {
|
if self.swap.unwrap_or(rand.gen()) {
|
||||||
pattern = Box::new(SwapFactory::new(pattern))
|
pattern = Box::new(SwapFactory::new(pattern))
|
||||||
}
|
}
|
||||||
if units != 1 {
|
if segments != 1 {
|
||||||
pattern = Box::new(UnitsFactory::new(pattern, units));
|
pattern = Box::new(SegmentsFactory::new(pattern, segments));
|
||||||
}
|
}
|
||||||
if slices != 1 {
|
if slices != 1 {
|
||||||
pattern = Box::new(SliceFactory::new(pattern, slices));
|
pattern = Box::new(SliceFactory::new(pattern, slices));
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
mod invert;
|
mod invert;
|
||||||
|
mod segment;
|
||||||
mod shift;
|
mod shift;
|
||||||
mod slice;
|
mod slice;
|
||||||
mod swap;
|
mod swap;
|
||||||
mod units;
|
|
||||||
|
|
||||||
pub use invert::*;
|
pub use invert::*;
|
||||||
|
pub use segment::*;
|
||||||
pub use shift::*;
|
pub use shift::*;
|
||||||
pub use slice::*;
|
pub use slice::*;
|
||||||
pub use swap::*;
|
pub use swap::*;
|
||||||
pub use units::*;
|
|
||||||
|
@ -2,29 +2,29 @@ use crate::pattern::*;
|
|||||||
use crate::Vector;
|
use crate::Vector;
|
||||||
|
|
||||||
#[derive(derive_more::Constructor)]
|
#[derive(derive_more::Constructor)]
|
||||||
pub struct UnitsFactory {
|
pub struct SegmentsFactory {
|
||||||
child: Box<dyn PatternFactory>,
|
child: Box<dyn PatternFactory>,
|
||||||
units: u8,
|
segments: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(derive_more::Constructor)]
|
#[derive(derive_more::Constructor)]
|
||||||
pub struct Units {
|
pub struct Segments {
|
||||||
child: Box<dyn Pattern>,
|
child: Box<dyn Pattern>,
|
||||||
units: u8,
|
segments: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PatternFactory for UnitsFactory {
|
impl PatternFactory for SegmentsFactory {
|
||||||
fn create(&self, config: &Config) -> Box<dyn Pattern> {
|
fn create(&self, config: &Config) -> Box<dyn Pattern> {
|
||||||
Box::new(Units::new(self.child.create(config), self.units))
|
Box::new(Segments::new(self.child.create(config), self.segments))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pattern for Units {
|
impl Pattern for Segments {
|
||||||
fn sample(&self, pos: Vector) -> f32 {
|
fn sample(&self, pos: Vector) -> f32 {
|
||||||
let sample = self.child.sample(pos);
|
let sample = self.child.sample(pos);
|
||||||
|
|
||||||
if 0.0 <= sample && sample < 1.0 {
|
if 0.0 <= sample && sample < 1.0 {
|
||||||
(sample * self.units as f32) % 1.0
|
(sample * self.segments as f32) % 1.0
|
||||||
} else {
|
} else {
|
||||||
sample
|
sample
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ mod test {
|
|||||||
.once()
|
.once()
|
||||||
.returning(|_| Box::new(MockPattern::new()));
|
.returning(|_| Box::new(MockPattern::new()));
|
||||||
|
|
||||||
UnitsFactory::new(Box::new(child), 2).create(&config);
|
SegmentsFactory::new(Box::new(child), 2).create(&config);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -63,7 +63,7 @@ mod test {
|
|||||||
Box::new(sampler)
|
Box::new(sampler)
|
||||||
});
|
});
|
||||||
|
|
||||||
let sampler = UnitsFactory::new(Box::new(child), 4).create(&Config::default());
|
let sampler = SegmentsFactory::new(Box::new(child), 4).create(&Config::default());
|
||||||
|
|
||||||
assert_abs_diff_eq!(0.96, sampler.sample(Vector::default()), epsilon = 0.01);
|
assert_abs_diff_eq!(0.96, sampler.sample(Vector::default()), epsilon = 0.01);
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ mod test {
|
|||||||
Box::new(sampler)
|
Box::new(sampler)
|
||||||
});
|
});
|
||||||
|
|
||||||
let sampler = UnitsFactory::new(Box::new(child), 4).create(&Config::default());
|
let sampler = SegmentsFactory::new(Box::new(child), 4).create(&Config::default());
|
||||||
|
|
||||||
assert_abs_diff_eq!(0.0, sampler.sample(Vector::default()));
|
assert_abs_diff_eq!(0.0, sampler.sample(Vector::default()));
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ mod test {
|
|||||||
Box::new(sampler)
|
Box::new(sampler)
|
||||||
});
|
});
|
||||||
|
|
||||||
let sampler = UnitsFactory::new(Box::new(child), 4).create(&Config::default());
|
let sampler = SegmentsFactory::new(Box::new(child), 4).create(&Config::default());
|
||||||
|
|
||||||
assert_eq!(0.96, sampler.sample(Vector::default()));
|
assert_eq!(0.96, sampler.sample(Vector::default()));
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ mod test {
|
|||||||
Box::new(sampler)
|
Box::new(sampler)
|
||||||
});
|
});
|
||||||
|
|
||||||
let sampler = UnitsFactory::new(Box::new(child), 4).create(&Config::default());
|
let sampler = SegmentsFactory::new(Box::new(child), 4).create(&Config::default());
|
||||||
|
|
||||||
assert_abs_diff_eq!(0.0, sampler.sample(Vector::default()));
|
assert_abs_diff_eq!(0.0, sampler.sample(Vector::default()));
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ mod test {
|
|||||||
Box::new(sampler)
|
Box::new(sampler)
|
||||||
});
|
});
|
||||||
|
|
||||||
let sampler = UnitsFactory::new(Box::new(child), 3).create(&Config::default());
|
let sampler = SegmentsFactory::new(Box::new(child), 3).create(&Config::default());
|
||||||
|
|
||||||
sampler.sample(Vector::new(5.0, 1.0));
|
sampler.sample(Vector::new(5.0, 1.0));
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user