diff options
author | metamuffin <metamuffin@disroot.org> | 2023-05-15 08:48:35 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-05-15 08:48:35 +0200 |
commit | 3a3313704ab7589c3fd0f939c4744e74cd4a78fe (patch) | |
tree | 70155dd0710c6c4a8d99ba733d7c75b1ece14612 | |
parent | 9bcea20a8e6a5ae4661436632570c502c822293a (diff) | |
download | blubcat-3a3313704ab7589c3fd0f939c4744e74cd4a78fe.tar blubcat-3a3313704ab7589c3fd0f939c4744e74cd4a78fe.tar.bz2 blubcat-3a3313704ab7589c3fd0f939c4744e74cd4a78fe.tar.zst |
remove box_syntax
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 66 | ||||
-rw-r--r-- | src/pattern.rs | 8 | ||||
-rw-r--r-- | src/transform.rs | 20 |
4 files changed, 46 insertions, 50 deletions
@@ -1,5 +1,3 @@ -#![feature(box_syntax)] - use color::Color; pub mod color; diff --git a/src/main.rs b/src/main.rs index 304e1ed..cf6fbb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -#![feature(box_syntax)] - use anyhow::Result; use blubcat::{ color::Color, @@ -95,85 +93,85 @@ fn main() -> Result<()> { "--ukraine" => stack.push(flag_helper(&["0057B8", "FFD700"])), /* PATTERNS */ - "-R" | "--rainbow" => stack.push(box Rainbow), - "-S" | "--sequence" => stack.push(box Sequence( + "-R" | "--rainbow" => stack.push(Box::new(Rainbow)), + "-S" | "--sequence" => stack.push(Box::new(Sequence( arg_next() .unwrap() .split(",") .map(|e| Color::parse(e).expect("color invalid")) .collect::<Vec<_>>(), - )), - "-G" | "--gradient" => stack.push(box Gradient( + ))), + "-G" | "--gradient" => stack.push(Box::new(Gradient( arg_next() .unwrap() .split(",") .map(|e| Color::parse(e).expect("color invalid")) .collect::<Vec<_>>(), - )), - "-K" | "--const" => stack.push(box Solid( + ))), + "-K" | "--const" => stack.push(Box::new(Solid( Color::parse(arg_next().expect("color expected").as_str()) .expect("invalid color"), - )), + ))), /* TRANSFORMS */ "-s" | "--scale" => { let fac = arg_num(); - push_queue.push(box Matrix { + push_queue.push(Box::new(Matrix { inner: stack.pop().unwrap(), matrix: ((fac, 0.0), (0.0, fac)), - }) + })) } "-r" | "--rotate" => { let angle = arg_num() * PI * 2.0; - push_queue.push(box Matrix { + push_queue.push(Box::new(Matrix { inner: stack.pop().unwrap(), matrix: ((angle.cos(), -angle.sin()), (angle.sin(), angle.cos())), - }) + })) } - "-m" | "--matrix" => push_queue.push(box Matrix { + "-m" | "--matrix" => push_queue.push(Box::new(Matrix { inner: stack.pop().unwrap(), matrix: ((arg_num(), arg_num()), (arg_num(), arg_num())), - }), - "-p" | "--polar" => push_queue.push(box Polar(stack.pop().unwrap())), + })), + "-p" | "--polar" => push_queue.push(Box::new(Polar(stack.pop().unwrap()))), "-t" | "--translate" => { let (x, y) = (arg_num(), arg_num()); - push_queue.push(box Translate { + push_queue.push(Box::new(Translate { offset: (x, y), inner: stack.pop().unwrap(), - }) + })) } - "-T" | "--transpose" => push_queue.push(box Transpose(stack.pop().unwrap())), + "-T" | "--transpose" => push_queue.push(Box::new(Transpose(stack.pop().unwrap()))), "-d" | "--duplicate" => { let p = stack.pop().unwrap(); push_queue.push(p.clone()); push_queue.push(p.clone()) } - "--add" => push_queue.push(box Composite { + "--add" => push_queue.push(Box::new(Composite { a: stack.pop().unwrap(), b: stack.pop().unwrap(), mode: CompositeOperation::Add, - }), - "--subtract" => push_queue.push(box Composite { + })), + "--subtract" => push_queue.push(Box::new(Composite { a: stack.pop().unwrap(), b: stack.pop().unwrap(), mode: CompositeOperation::Subtract, - }), - "--multiply" => push_queue.push(box Composite { + })), + "--multiply" => push_queue.push(Box::new(Composite { a: stack.pop().unwrap(), b: stack.pop().unwrap(), mode: CompositeOperation::Multiply, - }), - "--mix" => push_queue.push(box Composite { + })), + "--mix" => push_queue.push(Box::new(Composite { a: stack.pop().unwrap(), b: stack.pop().unwrap(), mode: CompositeOperation::Mix(arg_num()), - }), + })), - "--abs" => push_queue.push(box Filter { + "--abs" => push_queue.push(Box::new(Filter { inner: stack.pop().unwrap(), mode: FilterOperation::Abs, - }), + })), _ => panic!("unknown option {}", &a), } @@ -184,7 +182,7 @@ fn main() -> Result<()> { } let mut inputs = args.collect::<Vec<String>>(); - let mut pat = stack.pop().unwrap_or_else(|| box Solid(Color::WHITE)); + let mut pat = stack.pop().unwrap_or_else(|| Box::new(Solid(Color::WHITE))); if let Some(a) = arg_extra { inputs.insert(0, a) @@ -202,15 +200,15 @@ fn main() -> Result<()> { } fn flag_helper(colors: &[&str]) -> Box<dyn Sample> { - box Matrix { + Box::new(Matrix { matrix: ((1.0 / 6.0, 1.0 / 6.0), (0.0, 0.0)), - inner: box Sequence( + inner: Box::new(Sequence( colors .into_iter() .map(|e| Color::parse(e).unwrap()) .collect(), - ), - } + )), + }) } fn colorize(file: impl Read, sampler: &mut Box<dyn Sample>) -> Result<()> { diff --git a/src/pattern.rs b/src/pattern.rs index 8049c23..8bc2344 100644 --- a/src/pattern.rs +++ b/src/pattern.rs @@ -13,7 +13,7 @@ impl Sample for Rainbow { }; } fn clone(&self) -> Box<dyn Sample> { - box Clone::clone(self) + Box::new(Clone::clone(self)) } } @@ -24,7 +24,7 @@ impl Sample for Sequence { self.0[x.rem_euclid(self.0.len() as f64) as usize] } fn clone(&self) -> Box<dyn Sample> { - box Clone::clone(self) + Box::new(Clone::clone(self)) } } @@ -39,7 +39,7 @@ impl Sample for Gradient { Color::mix(a, b, index_error) } fn clone(&self) -> Box<dyn Sample> { - box Clone::clone(self) + Box::new(Clone::clone(self)) } } @@ -50,6 +50,6 @@ impl Sample for Solid { self.0 } fn clone(&self) -> Box<dyn Sample> { - box Clone::clone(self) + Box::new(Clone::clone(self)) } } diff --git a/src/transform.rs b/src/transform.rs index 10af82e..499913b 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -13,10 +13,10 @@ impl Sample for Matrix { self.inner.sample(x, y) } fn clone(&self) -> Box<dyn Sample> { - box Self { + Box::new(Self { inner: self.inner.clone(), matrix: self.matrix.clone(), - } + }) } } @@ -28,7 +28,7 @@ impl Sample for Polar { self.0.sample(ang, dist) } fn clone(&self) -> Box<dyn Sample> { - box Self(self.0.clone()) + Box::new(Self(self.0.clone())) } } @@ -38,7 +38,7 @@ impl Sample for Transpose { self.0.sample(y, x) } fn clone(&self) -> Box<dyn Sample> { - box Self(self.0.clone()) + Box::new(Self(self.0.clone())) } } @@ -51,10 +51,10 @@ impl Sample for Translate { self.inner.sample(x - self.offset.0, y - self.offset.1) } fn clone(&self) -> Box<dyn Sample> { - box Self { + Box::new(Self { inner: self.inner.clone(), offset: self.offset.clone(), - } + }) } } @@ -78,10 +78,10 @@ impl Sample for Filter { } } fn clone(&self) -> Box<dyn Sample> { - box Self { + Box::new(Self { inner: self.inner.clone(), mode: self.mode, - } + }) } } @@ -125,10 +125,10 @@ impl Sample for Composite { } } fn clone(&self) -> Box<dyn Sample> { - box Self { + Box::new(Self { a: self.a.clone(), b: self.b.clone(), mode: self.mode, - } + }) } } |