mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-15 20:46:40 +00:00
Rename slice to shrink
This commit is contained in:
parent
1e4403b5cb
commit
4ad08ea42d
@ -6,10 +6,10 @@ wipe \
|
|||||||
--char-pattern circle \
|
--char-pattern circle \
|
||||||
--char-invert false \
|
--char-invert false \
|
||||||
--char-segments 3 \
|
--char-segments 3 \
|
||||||
--char-slices 2 \
|
--char-shrink 2 \
|
||||||
--char-swap false \
|
--char-swap false \
|
||||||
--color-pattern wheel \
|
--color-pattern wheel \
|
||||||
--color-slices 2 \
|
--color-segments 2 \
|
||||||
--color-invert false \
|
--color-invert false \
|
||||||
--color-shift true \
|
--color-shift true \
|
||||||
--color-swap false \
|
--color-swap false \
|
||||||
|
@ -6,10 +6,10 @@ wipe \
|
|||||||
--char-pattern wheel \
|
--char-pattern wheel \
|
||||||
--char-invert false \
|
--char-invert false \
|
||||||
--char-segments 2 \
|
--char-segments 2 \
|
||||||
--char-slices 2 \
|
--char-shrink 2 \
|
||||||
--char-swap false \
|
--char-swap false \
|
||||||
--color-pattern circle \
|
--color-pattern circle \
|
||||||
--color-slices 4 \
|
--color-segments 4 \
|
||||||
--color-invert false \
|
--color-invert false \
|
||||||
--color-shift false \
|
--color-shift false \
|
||||||
--color-swap false \
|
--color-swap false \
|
||||||
|
@ -6,10 +6,10 @@ wipe \
|
|||||||
--char-pattern rhombus \
|
--char-pattern rhombus \
|
||||||
--char-invert true \
|
--char-invert true \
|
||||||
--char-segments 2 \
|
--char-segments 2 \
|
||||||
--char-slices 2 \
|
--char-shrink 2 \
|
||||||
--char-swap false \
|
--char-swap false \
|
||||||
--color-pattern wheel \
|
--color-pattern wheel \
|
||||||
--color-slices 2 \
|
--color-segments 2 \
|
||||||
--color-invert true \
|
--color-invert true \
|
||||||
--color-shift true \
|
--color-shift true \
|
||||||
--color-swap false \
|
--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]
|
/// Choose the segment count of the pattern [default: 1-4]
|
||||||
#[clap(long, value_parser = value_parser!(u8).range(1..255))]
|
#[clap(long, value_parser = value_parser!(u8).range(1..255))]
|
||||||
char_segments: Option<u8>,
|
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))]
|
#[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
|
/// Choose the colors used for the pattern
|
||||||
#[clap(long, value_enum)]
|
#[clap(long, value_enum)]
|
||||||
colors: Option<PalletEnum>,
|
colors: Option<PalletEnum>,
|
||||||
@ -80,9 +80,9 @@ struct Args {
|
|||||||
/// Choose whether to swap the x-axis and y-axis of the fill pattern
|
/// Choose whether to swap the x-axis and y-axis of the fill pattern
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
color_swap: Option<bool>,
|
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))]
|
#[clap(long, value_parser = value_parser!(u8).range(1..255))]
|
||||||
color_slices: Option<u8>,
|
color_segments: Option<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// All color pallets.
|
/// All color pallets.
|
||||||
@ -131,7 +131,7 @@ struct PatternConfig {
|
|||||||
invert: bool,
|
invert: bool,
|
||||||
swap: bool,
|
swap: bool,
|
||||||
segments: f32,
|
segments: f32,
|
||||||
slices: f32,
|
shrink: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args {
|
impl Args {
|
||||||
@ -143,7 +143,7 @@ impl Args {
|
|||||||
self.char_invert.unwrap_or(rng.gen()),
|
self.char_invert.unwrap_or(rng.gen()),
|
||||||
self.char_swap.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_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_shift.unwrap_or(rng.gen()),
|
||||||
self.color_invert.unwrap_or(rng.gen()),
|
self.color_invert.unwrap_or(rng.gen()),
|
||||||
self.color_swap.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,
|
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 {
|
if self.segments != 1.0 {
|
||||||
pattern = Box::new(SegmentsFactory::new(pattern, self.segments));
|
pattern = Box::new(SegmentsFactory::new(pattern, self.segments));
|
||||||
}
|
}
|
||||||
if self.slices != 1.0 {
|
if self.shrink != 1.0 {
|
||||||
pattern = Box::new(SliceFactory::new(pattern, self.slices));
|
pattern = Box::new(ShrinkFactory::new(pattern, self.shrink));
|
||||||
}
|
}
|
||||||
pattern
|
pattern
|
||||||
}
|
}
|
||||||
@ -365,13 +365,13 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn char_config_slices() {
|
fn char_config_shrink() {
|
||||||
let rng = &mut StepRng::new(1, 1);
|
let rng = &mut StepRng::new(1, 1);
|
||||||
let args = Args {
|
let args = Args {
|
||||||
char_slices: Some(42),
|
char_shrink: Some(42),
|
||||||
..Args::default()
|
..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]
|
#[test]
|
||||||
@ -417,19 +417,20 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn color_config_segments() {
|
fn color_config_segments() {
|
||||||
let rng = &mut StepRng::new(1, 1);
|
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]
|
#[test]
|
||||||
fn color_config_slices() {
|
fn color_config_shrink() {
|
||||||
let rng = &mut StepRng::new(1, 1);
|
let rng = &mut StepRng::new(1, 1);
|
||||||
let args = Args {
|
let args = Args::default();
|
||||||
color_slices: Some(23),
|
|
||||||
..Args::default()
|
assert_abs_diff_eq!(1.0, args.color_config(rng).shrink);
|
||||||
};
|
|
||||||
assert_abs_diff_eq!(23.0, args.color_config(rng).slices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -441,7 +442,7 @@ mod test {
|
|||||||
invert: true,
|
invert: true,
|
||||||
swap: true,
|
swap: true,
|
||||||
segments: 3.0,
|
segments: 3.0,
|
||||||
slices: 2.0,
|
shrink: 2.0,
|
||||||
};
|
};
|
||||||
config
|
config
|
||||||
.create()
|
.create()
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
mod invert;
|
mod invert;
|
||||||
mod segment;
|
mod segment;
|
||||||
mod shift;
|
mod shift;
|
||||||
mod slice;
|
mod shrink;
|
||||||
mod swap;
|
mod swap;
|
||||||
|
|
||||||
pub use invert::*;
|
pub use invert::*;
|
||||||
pub use segment::*;
|
pub use segment::*;
|
||||||
pub use shift::*;
|
pub use shift::*;
|
||||||
pub use slice::*;
|
pub use shrink::*;
|
||||||
pub use swap::*;
|
pub use swap::*;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::pattern::*;
|
use crate::pattern::*;
|
||||||
use crate::Vector;
|
use crate::Vector;
|
||||||
|
|
||||||
/// A factory for [Slice].
|
/// A factory for [Shrink].
|
||||||
pub struct SliceFactory {
|
pub struct ShrinkFactory {
|
||||||
child: Box<dyn PatternFactory>,
|
child: Box<dyn PatternFactory>,
|
||||||
width: f32,
|
width: f32,
|
||||||
rest: f32,
|
rest: f32,
|
||||||
@ -10,28 +10,32 @@ pub struct SliceFactory {
|
|||||||
|
|
||||||
/// Reduces the width of the child [Pattern] to one over `n`.
|
/// Reduces the width of the child [Pattern] to one over `n`.
|
||||||
#[derive(derive_more::Constructor)]
|
#[derive(derive_more::Constructor)]
|
||||||
pub struct Slice {
|
pub struct Shrink {
|
||||||
child: Box<dyn Pattern>,
|
child: Box<dyn Pattern>,
|
||||||
width: f32,
|
width: f32,
|
||||||
rest: f32,
|
rest: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SliceFactory {
|
impl ShrinkFactory {
|
||||||
pub fn new(child: Box<dyn PatternFactory>, slices: f32) -> Self {
|
pub fn new(child: Box<dyn PatternFactory>, factor: f32) -> Self {
|
||||||
let width = 1.0 / slices;
|
let width = 1.0 / factor;
|
||||||
let rest = 1.0 - width;
|
let rest = 1.0 - width;
|
||||||
|
|
||||||
Self { child, width, rest }
|
Self { child, width, rest }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PatternFactory for SliceFactory {
|
impl PatternFactory for ShrinkFactory {
|
||||||
fn create(&self, config: &Config) -> Box<dyn Pattern> {
|
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 {
|
fn sample(&self, pos: Vector) -> f32 {
|
||||||
(self.child.sample(pos) - self.rest) / self.width
|
(self.child.sample(pos) - self.rest) / self.width
|
||||||
}
|
}
|
||||||
@ -57,7 +61,7 @@ mod test {
|
|||||||
.once()
|
.once()
|
||||||
.returning(|_| Box::new(MockPattern::new()));
|
.returning(|_| Box::new(MockPattern::new()));
|
||||||
|
|
||||||
SliceFactory::new(Box::new(child), 4.0).create(&config);
|
ShrinkFactory::new(Box::new(child), 4.0).create(&config);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -69,7 +73,7 @@ mod test {
|
|||||||
Box::new(sampler)
|
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()));
|
assert_abs_diff_eq!(1.0, sampler.sample(Vector::default()));
|
||||||
}
|
}
|
||||||
@ -83,7 +87,7 @@ mod test {
|
|||||||
Box::new(sampler)
|
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()));
|
assert_abs_diff_eq!(0.0, sampler.sample(Vector::default()));
|
||||||
}
|
}
|
||||||
@ -97,7 +101,7 @@ mod test {
|
|||||||
Box::new(sampler)
|
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);
|
assert!(sampler.sample(Vector::default()) < 0.0);
|
||||||
}
|
}
|
||||||
@ -115,7 +119,7 @@ mod test {
|
|||||||
Box::new(sampler)
|
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));
|
sampler.sample(Vector::new(3.0, 5.0));
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user