mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-22 16:06:38 +00:00
Rename slice to shrink
This commit is contained in:
parent
1e4403b5cb
commit
4ad08ea42d
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
43
src/main.rs
43
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<u8>,
|
||||
/// 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<u8>,
|
||||
char_shrink: Option<u8>,
|
||||
/// Choose the colors used for the pattern
|
||||
#[clap(long, value_enum)]
|
||||
colors: Option<PalletEnum>,
|
||||
@ -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<bool>,
|
||||
/// 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<u8>,
|
||||
color_segments: Option<u8>,
|
||||
}
|
||||
|
||||
/// 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()
|
||||
|
@ -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::*;
|
||||
|
@ -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<dyn PatternFactory>,
|
||||
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<dyn Pattern>,
|
||||
width: f32,
|
||||
rest: f32,
|
||||
}
|
||||
|
||||
impl SliceFactory {
|
||||
pub fn new(child: Box<dyn PatternFactory>, slices: f32) -> Self {
|
||||
let width = 1.0 / slices;
|
||||
impl ShrinkFactory {
|
||||
pub fn new(child: Box<dyn PatternFactory>, 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<dyn Pattern> {
|
||||
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));
|
||||
}
|
Loading…
Reference in New Issue
Block a user