From 9bcea20a8e6a5ae4661436632570c502c822293a Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 5 Jun 2022 20:12:58 +0200 Subject: sadfasdf --- src/transform.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/transform.rs') diff --git a/src/transform.rs b/src/transform.rs index ccb1850..10af82e 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -12,6 +12,12 @@ impl Sample for Matrix { ); self.inner.sample(x, y) } + fn clone(&self) -> Box { + box Self { + inner: self.inner.clone(), + matrix: self.matrix.clone(), + } + } } pub struct Polar(pub Box); @@ -21,6 +27,9 @@ impl Sample for Polar { let dist = (x * x + y * y).sqrt(); self.0.sample(ang, dist) } + fn clone(&self) -> Box { + box Self(self.0.clone()) + } } pub struct Transpose(pub Box); @@ -28,6 +37,9 @@ impl Sample for Transpose { fn sample(&mut self, x: f64, y: f64) -> Color { self.0.sample(y, x) } + fn clone(&self) -> Box { + box Self(self.0.clone()) + } } pub struct Translate { @@ -38,8 +50,42 @@ impl Sample for Translate { fn sample(&mut self, x: f64, y: f64) -> Color { self.inner.sample(x - self.offset.0, y - self.offset.1) } + fn clone(&self) -> Box { + box Self { + inner: self.inner.clone(), + offset: self.offset.clone(), + } + } +} + +#[derive(Clone, Copy)] +pub enum FilterOperation { + Abs, +} +pub struct Filter { + pub inner: Box, + pub mode: FilterOperation, +} +impl Sample for Filter { + fn sample(&mut self, x: f64, y: f64) -> Color { + let a = self.inner.sample(x, y); + match self.mode { + FilterOperation::Abs => Color { + r: a.r.abs(), + g: a.g.abs(), + b: a.b.abs(), + }, + } + } + fn clone(&self) -> Box { + box Self { + inner: self.inner.clone(), + mode: self.mode, + } + } } +#[derive(Clone, Copy)] pub enum CompositeOperation { Add, Subtract, @@ -78,4 +124,11 @@ impl Sample for Composite { }, } } + fn clone(&self) -> Box { + box Self { + a: self.a.clone(), + b: self.b.clone(), + mode: self.mode, + } + } } -- cgit v1.2.3-70-g09d2