From 4ad08ea42d2cfc4b49779fa42c7c8bf50b25373e Mon Sep 17 00:00:00 2001 From: Rico Riedel Date: Wed, 23 Nov 2022 20:16:41 +0100 Subject: [PATCH] Rename slice to shrink --- misc/script-1.sh | 4 +-- misc/script-2.sh | 4 +-- misc/script-3.sh | 4 +-- src/main.rs | 43 ++++++++++++++------------- src/transform/mod.rs | 4 +-- src/transform/{slice.rs => shrink.rs} | 32 +++++++++++--------- 6 files changed, 48 insertions(+), 43 deletions(-) rename src/transform/{slice.rs => shrink.rs} (76%) diff --git a/misc/script-1.sh b/misc/script-1.sh index e159c87..04cdfa3 100755 --- a/misc/script-1.sh +++ b/misc/script-1.sh @@ -6,10 +6,10 @@ wipe \ --char-pattern circle \ --char-invert false \ --char-segments 3 \ - --char-slices 2 \ + --char-shrink 2 \ --char-swap false \ --color-pattern wheel \ - --color-slices 2 \ + --color-segments 2 \ --color-invert false \ --color-shift true \ --color-swap false \ diff --git a/misc/script-2.sh b/misc/script-2.sh index 9427297..bd3bf99 100755 --- a/misc/script-2.sh +++ b/misc/script-2.sh @@ -6,10 +6,10 @@ wipe \ --char-pattern wheel \ --char-invert false \ --char-segments 2 \ - --char-slices 2 \ + --char-shrink 2 \ --char-swap false \ --color-pattern circle \ - --color-slices 4 \ + --color-segments 4 \ --color-invert false \ --color-shift false \ --color-swap false \ diff --git a/misc/script-3.sh b/misc/script-3.sh index fc66162..707a762 100755 --- a/misc/script-3.sh +++ b/misc/script-3.sh @@ -6,10 +6,10 @@ wipe \ --char-pattern rhombus \ --char-invert true \ --char-segments 2 \ - --char-slices 2 \ + --char-shrink 2 \ --char-swap false \ --color-pattern wheel \ - --color-slices 2 \ + --color-segments 2 \ --color-invert true \ --color-shift true \ --color-swap false \ diff --git a/src/main.rs b/src/main.rs index 942e5ef..785b552 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,9 +62,9 @@ struct Args { /// Choose the segment count of the pattern [default: 1-4] #[clap(long, value_parser = value_parser!(u8).range(1..255))] char_segments: Option, - /// Choose the slice count of the pattern [default: 1-4] + /// Choose the factor by which to shrink the pattern [default: 1-4] #[clap(long, value_parser = value_parser!(u8).range(1..255))] - char_slices: Option, + char_shrink: Option, /// Choose the colors used for the pattern #[clap(long, value_enum)] colors: Option, @@ -80,9 +80,9 @@ struct Args { /// Choose whether to swap the x-axis and y-axis of the fill pattern #[clap(long)] color_swap: Option, - /// Choose the slice count of the fill pattern [default: 1-4] + /// Choose the segment count of the fill pattern [default: 1-4] #[clap(long, value_parser = value_parser!(u8).range(1..255))] - color_slices: Option, + color_segments: Option, } /// All color pallets. @@ -131,7 +131,7 @@ struct PatternConfig { invert: bool, swap: bool, segments: f32, - slices: f32, + shrink: f32, } impl Args { @@ -143,7 +143,7 @@ impl Args { self.char_invert.unwrap_or(rng.gen()), self.char_swap.unwrap_or(rng.gen()), self.char_segments.unwrap_or(rng.gen_range(1..=4)) as f32, - self.char_slices.unwrap_or(rng.gen_range(1..=4)) as f32, + self.char_shrink.unwrap_or(rng.gen_range(1..=4)) as f32, ) } @@ -154,8 +154,8 @@ impl Args { self.color_shift.unwrap_or(rng.gen()), self.color_invert.unwrap_or(rng.gen()), self.color_swap.unwrap_or(rng.gen()), + self.color_segments.unwrap_or(rng.gen_range(1..=4)) as f32, 1.0, - self.color_slices.unwrap_or(rng.gen_range(1..=4)) as f32, ) } @@ -234,8 +234,8 @@ impl PatternConfig { if self.segments != 1.0 { pattern = Box::new(SegmentsFactory::new(pattern, self.segments)); } - if self.slices != 1.0 { - pattern = Box::new(SliceFactory::new(pattern, self.slices)); + if self.shrink != 1.0 { + pattern = Box::new(ShrinkFactory::new(pattern, self.shrink)); } pattern } @@ -365,13 +365,13 @@ mod test { } #[test] - fn char_config_slices() { + fn char_config_shrink() { let rng = &mut StepRng::new(1, 1); let args = Args { - char_slices: Some(42), + char_shrink: Some(42), ..Args::default() }; - assert_abs_diff_eq!(42.0, args.char_config(rng).slices); + assert_abs_diff_eq!(42.0, args.char_config(rng).shrink); } #[test] @@ -417,19 +417,20 @@ mod test { #[test] fn color_config_segments() { let rng = &mut StepRng::new(1, 1); - let args = Args::default(); + let args = Args { + color_segments: Some(23), + ..Args::default() + }; - assert_abs_diff_eq!(1.0, args.color_config(rng).segments); + assert_abs_diff_eq!(23.0, args.color_config(rng).segments); } #[test] - fn color_config_slices() { + fn color_config_shrink() { let rng = &mut StepRng::new(1, 1); - let args = Args { - color_slices: Some(23), - ..Args::default() - }; - assert_abs_diff_eq!(23.0, args.color_config(rng).slices); + let args = Args::default(); + + assert_abs_diff_eq!(1.0, args.color_config(rng).shrink); } #[test] @@ -441,7 +442,7 @@ mod test { invert: true, swap: true, segments: 3.0, - slices: 2.0, + shrink: 2.0, }; config .create() diff --git a/src/transform/mod.rs b/src/transform/mod.rs index 1a1bad5..73206fb 100644 --- a/src/transform/mod.rs +++ b/src/transform/mod.rs @@ -3,11 +3,11 @@ mod invert; mod segment; mod shift; -mod slice; +mod shrink; mod swap; pub use invert::*; pub use segment::*; pub use shift::*; -pub use slice::*; +pub use shrink::*; pub use swap::*; diff --git a/src/transform/slice.rs b/src/transform/shrink.rs similarity index 76% rename from src/transform/slice.rs rename to src/transform/shrink.rs index 2bef835..d6aafab 100644 --- a/src/transform/slice.rs +++ b/src/transform/shrink.rs @@ -1,8 +1,8 @@ use crate::pattern::*; use crate::Vector; -/// A factory for [Slice]. -pub struct SliceFactory { +/// A factory for [Shrink]. +pub struct ShrinkFactory { child: Box, width: f32, rest: f32, @@ -10,28 +10,32 @@ pub struct SliceFactory { /// Reduces the width of the child [Pattern] to one over `n`. #[derive(derive_more::Constructor)] -pub struct Slice { +pub struct Shrink { child: Box, width: f32, rest: f32, } -impl SliceFactory { - pub fn new(child: Box, slices: f32) -> Self { - let width = 1.0 / slices; +impl ShrinkFactory { + pub fn new(child: Box, factor: f32) -> Self { + let width = 1.0 / factor; let rest = 1.0 - width; Self { child, width, rest } } } -impl PatternFactory for SliceFactory { +impl PatternFactory for ShrinkFactory { fn create(&self, config: &Config) -> Box { - Box::new(Slice::new(self.child.create(config), self.width, self.rest)) + Box::new(Shrink::new( + self.child.create(config), + self.width, + self.rest, + )) } } -impl Pattern for Slice { +impl Pattern for Shrink { fn sample(&self, pos: Vector) -> f32 { (self.child.sample(pos) - self.rest) / self.width } @@ -57,7 +61,7 @@ mod test { .once() .returning(|_| Box::new(MockPattern::new())); - SliceFactory::new(Box::new(child), 4.0).create(&config); + ShrinkFactory::new(Box::new(child), 4.0).create(&config); } #[test] @@ -69,7 +73,7 @@ mod test { Box::new(sampler) }); - let sampler = SliceFactory::new(Box::new(child), 4.0).create(&Config::default()); + let sampler = ShrinkFactory::new(Box::new(child), 4.0).create(&Config::default()); assert_abs_diff_eq!(1.0, sampler.sample(Vector::default())); } @@ -83,7 +87,7 @@ mod test { Box::new(sampler) }); - let sampler = SliceFactory::new(Box::new(child), 4.0).create(&Config::default()); + let sampler = ShrinkFactory::new(Box::new(child), 4.0).create(&Config::default()); assert_abs_diff_eq!(0.0, sampler.sample(Vector::default())); } @@ -97,7 +101,7 @@ mod test { Box::new(sampler) }); - let sampler = SliceFactory::new(Box::new(child), 4.0).create(&Config::default()); + let sampler = ShrinkFactory::new(Box::new(child), 4.0).create(&Config::default()); assert!(sampler.sample(Vector::default()) < 0.0); } @@ -115,7 +119,7 @@ mod test { Box::new(sampler) }); - let sampler = SliceFactory::new(Box::new(child), 3.0).create(&Config::default()); + let sampler = ShrinkFactory::new(Box::new(child), 3.0).create(&Config::default()); sampler.sample(Vector::new(3.0, 5.0)); }