[librsvg: 18/20] feTurbulence: shorten code by implementing Default and Clone for its parameters
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 18/20] feTurbulence: shorten code by implementing Default and Clone for its parameters
- Date: Wed, 17 Mar 2021 19:08:06 +0000 (UTC)
commit 63a162fd38f83e31066d0fd32c6cf03312449b7c
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Mar 16 15:28:45 2021 -0600
feTurbulence: shorten code by implementing Default and Clone for its parameters
src/filters/turbulence.rs | 51 ++++++++++++++++++++++-------------------------
1 file changed, 24 insertions(+), 27 deletions(-)
---
diff --git a/src/filters/turbulence.rs b/src/filters/turbulence.rs
index c26315ff..d3c79116 100644
--- a/src/filters/turbulence.rs
+++ b/src/filters/turbulence.rs
@@ -25,6 +25,8 @@ enum StitchTiles {
NoStitch,
}
+enum_default!(StitchTiles, StitchTiles::NoStitch);
+
/// Enumeration of the noise types.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
enum NoiseType {
@@ -32,17 +34,17 @@ enum NoiseType {
Turbulence,
}
+enum_default!(NoiseType, NoiseType::Turbulence);
+
/// The `feTurbulence` filter primitive.
+#[derive(Default)]
pub struct FeTurbulence {
base: Primitive,
- base_frequency: (f64, f64),
- num_octaves: i32,
- seed: i32,
- stitch_tiles: StitchTiles,
- type_: NoiseType,
+ params: Turbulence,
}
/// Resolved `feTurbulence` primitive for rendering.
+#[derive(Clone)]
pub struct Turbulence {
base_frequency: (f64, f64),
num_octaves: i32,
@@ -52,17 +54,17 @@ pub struct Turbulence {
color_interpolation_filters: ColorInterpolationFilters,
}
-impl Default for FeTurbulence {
+impl Default for Turbulence {
/// Constructs a new `Turbulence` with empty properties.
#[inline]
- fn default() -> FeTurbulence {
- FeTurbulence {
- base: Default::default(),
+ fn default() -> Turbulence {
+ Turbulence {
base_frequency: (0.0, 0.0),
num_octaves: 1,
seed: 0,
- stitch_tiles: StitchTiles::NoStitch,
- type_: NoiseType::Turbulence,
+ stitch_tiles: Default::default(),
+ type_: Default::default(),
+ color_interpolation_filters: Default::default(),
}
}
}
@@ -75,22 +77,24 @@ impl SetAttributes for FeTurbulence {
match attr.expanded() {
expanded_name!("", "baseFrequency") => {
let NumberOptionalNumber(NonNegative(x), NonNegative(y)) = attr.parse(value)?;
- self.base_frequency = (x, y);
+ self.params.base_frequency = (x, y);
}
expanded_name!("", "numOctaves") => {
- self.num_octaves = attr.parse(value)?;
+ self.params.num_octaves = attr.parse(value)?;
}
// Yes, seed needs to be parsed as a number and then truncated.
expanded_name!("", "seed") => {
let v: f64 = attr.parse(value)?;
- self.seed = clamp(
+ self.params.seed = clamp(
v.trunc(),
f64::from(i32::min_value()),
f64::from(i32::max_value()),
) as i32;
}
- expanded_name!("", "stitchTiles") => self.stitch_tiles = attr.parse(value)?,
- expanded_name!("", "type") => self.type_ = attr.parse(value)?,
+ expanded_name!("", "stitchTiles") => {
+ self.params.stitch_tiles = attr.parse(value)?
+ }
+ expanded_name!("", "type") => self.params.type_ = attr.parse(value)?,
_ => (),
}
}
@@ -416,17 +420,10 @@ impl FilterEffect for FeTurbulence {
let cascaded = CascadedValues::new_from_node(node);
let values = cascaded.get();
- Ok((
- self.base.clone(),
- PrimitiveParams::Turbulence(Turbulence {
- base_frequency: self.base_frequency,
- num_octaves: self.num_octaves,
- seed: self.seed,
- stitch_tiles: self.stitch_tiles,
- type_: self.type_,
- color_interpolation_filters: values.color_interpolation_filters(),
- }),
- ))
+ let mut params = self.params.clone();
+ params.color_interpolation_filters = values.color_interpolation_filters();
+
+ Ok((self.base.clone(), PrimitiveParams::Turbulence(params)))
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]