diff --git a/src/main.rs b/src/main.rs index f970f18..0d81503 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,9 +51,9 @@ struct Args { /// Swap the x-axis and y-axis of the pattern #[clap(long)] char_swap: Option, - /// Set the count of units of the pattern [default: 1-4] + /// Set the count of segments of the pattern [default: 1-4] #[clap(long)] - char_units: Option, + char_segments: Option, /// Set the count of slices of the pattern [default: 1-4] #[clap(long)] char_slices: Option, @@ -119,7 +119,7 @@ struct PatternConfig { shift: Option, invert: Option, swap: Option, - units: Option, + segments: Option, slices: Option, } @@ -130,7 +130,7 @@ impl Args { Some(true), self.char_invert, self.char_swap, - self.char_units, + self.char_segments, self.char_slices, ) } @@ -195,7 +195,7 @@ impl PatternConfig { fn create(&self, rand: &mut impl Rng) -> Box { 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)); if self.shift.unwrap_or(rand.gen()) { @@ -207,8 +207,8 @@ impl PatternConfig { if self.swap.unwrap_or(rand.gen()) { pattern = Box::new(SwapFactory::new(pattern)) } - if units != 1 { - pattern = Box::new(UnitsFactory::new(pattern, units)); + if segments != 1 { + pattern = Box::new(SegmentsFactory::new(pattern, segments)); } if slices != 1 { pattern = Box::new(SliceFactory::new(pattern, slices)); diff --git a/src/transform/mod.rs b/src/transform/mod.rs index 3f5ebea..204b941 100644 --- a/src/transform/mod.rs +++ b/src/transform/mod.rs @@ -1,11 +1,11 @@ mod invert; +mod segment; mod shift; mod slice; mod swap; -mod units; pub use invert::*; +pub use segment::*; pub use shift::*; pub use slice::*; pub use swap::*; -pub use units::*; diff --git a/src/transform/units.rs b/src/transform/segment.rs similarity index 78% rename from src/transform/units.rs rename to src/transform/segment.rs index 810732c..e659b6f 100644 --- a/src/transform/units.rs +++ b/src/transform/segment.rs @@ -2,29 +2,29 @@ use crate::pattern::*; use crate::Vector; #[derive(derive_more::Constructor)] -pub struct UnitsFactory { +pub struct SegmentsFactory { child: Box, - units: u8, + segments: u8, } #[derive(derive_more::Constructor)] -pub struct Units { +pub struct Segments { child: Box, - units: u8, + segments: u8, } -impl PatternFactory for UnitsFactory { +impl PatternFactory for SegmentsFactory { fn create(&self, config: &Config) -> Box { - 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 { let sample = self.child.sample(pos); if 0.0 <= sample && sample < 1.0 { - (sample * self.units as f32) % 1.0 + (sample * self.segments as f32) % 1.0 } else { sample } @@ -51,7 +51,7 @@ mod test { .once() .returning(|_| Box::new(MockPattern::new())); - UnitsFactory::new(Box::new(child), 2).create(&config); + SegmentsFactory::new(Box::new(child), 2).create(&config); } #[test] @@ -63,7 +63,7 @@ mod test { 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); } @@ -77,7 +77,7 @@ mod test { 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())); } @@ -91,7 +91,7 @@ mod test { 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())); } @@ -105,7 +105,7 @@ mod test { 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())); } @@ -123,7 +123,7 @@ mod test { 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)); }