diff options
Diffstat (limited to 'src/transform.rs')
-rw-r--r-- | src/transform.rs | 53 |
1 files changed, 53 insertions, 0 deletions
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<dyn Sample> { + box Self { + inner: self.inner.clone(), + matrix: self.matrix.clone(), + } + } } pub struct Polar(pub Box<dyn Sample>); @@ -21,6 +27,9 @@ impl Sample for Polar { let dist = (x * x + y * y).sqrt(); self.0.sample(ang, dist) } + fn clone(&self) -> Box<dyn Sample> { + box Self(self.0.clone()) + } } pub struct Transpose(pub Box<dyn Sample>); @@ -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<dyn Sample> { + 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<dyn Sample> { + box Self { + inner: self.inner.clone(), + offset: self.offset.clone(), + } + } +} + +#[derive(Clone, Copy)] +pub enum FilterOperation { + Abs, +} +pub struct Filter { + pub inner: Box<dyn Sample>, + 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<dyn Sample> { + 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<dyn Sample> { + box Self { + a: self.a.clone(), + b: self.b.clone(), + mode: self.mode, + } + } } |