[librsvg: 9/20] feComposite: 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: 9/20] feComposite: shorten code by implementing Default and Clone for its parameters
- Date: Wed, 17 Mar 2021 19:08:05 +0000 (UTC)
commit 5776d02e3ea8f5b98f097ce55856cc89406072d9
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Mar 16 13:08:35 2021 -0600
feComposite: shorten code by implementing Default and Clone for its parameters
src/filters/composite.rs | 60 +++++++++++++-----------------------------------
1 file changed, 16 insertions(+), 44 deletions(-)
---
diff --git a/src/filters/composite.rs b/src/filters/composite.rs
index 2ae4983a..5d6cbad3 100644
--- a/src/filters/composite.rs
+++ b/src/filters/composite.rs
@@ -24,19 +24,17 @@ enum Operator {
Arithmetic,
}
+enum_default!(Operator, Operator::Over);
+
/// The `feComposite` filter primitive.
+#[derive(Default)]
pub struct FeComposite {
base: Primitive,
- in1: Input,
- in2: Input,
- operator: Operator,
- k1: f64,
- k2: f64,
- k3: f64,
- k4: f64,
+ params: Composite,
}
/// Resolved `feComposite` primitive for rendering.
+#[derive(Clone, Default)]
pub struct Composite {
in1: Input,
in2: Input,
@@ -48,36 +46,19 @@ pub struct Composite {
color_interpolation_filters: ColorInterpolationFilters,
}
-impl Default for FeComposite {
- /// Constructs a new `Composite` with empty properties.
- #[inline]
- fn default() -> FeComposite {
- FeComposite {
- base: Default::default(),
- in1: Default::default(),
- in2: Default::default(),
- operator: Operator::Over,
- k1: 0.0,
- k2: 0.0,
- k3: 0.0,
- k4: 0.0,
- }
- }
-}
-
impl SetAttributes for FeComposite {
fn set_attributes(&mut self, attrs: &Attributes) -> ElementResult {
let (in1, in2) = self.base.parse_two_inputs(attrs)?;
- self.in1 = in1;
- self.in2 = in2;
+ self.params.in1 = in1;
+ self.params.in2 = in2;
for (attr, value) in attrs.iter() {
match attr.expanded() {
- expanded_name!("", "operator") => self.operator = attr.parse(value)?,
- expanded_name!("", "k1") => self.k1 = attr.parse(value)?,
- expanded_name!("", "k2") => self.k2 = attr.parse(value)?,
- expanded_name!("", "k3") => self.k3 = attr.parse(value)?,
- expanded_name!("", "k4") => self.k4 = attr.parse(value)?,
+ expanded_name!("", "operator") => self.params.operator = attr.parse(value)?,
+ expanded_name!("", "k1") => self.params.k1 = attr.parse(value)?,
+ expanded_name!("", "k2") => self.params.k2 = attr.parse(value)?,
+ expanded_name!("", "k3") => self.params.k3 = attr.parse(value)?,
+ expanded_name!("", "k4") => self.params.k4 = attr.parse(value)?,
_ => (),
}
}
@@ -141,19 +122,10 @@ impl FilterEffect for FeComposite {
let cascaded = CascadedValues::new_from_node(node);
let values = cascaded.get();
- Ok((
- self.base.clone(),
- PrimitiveParams::Composite(Composite {
- in1: self.in1.clone(),
- in2: self.in2.clone(),
- operator: self.operator,
- k1: self.k1,
- k2: self.k2,
- k3: self.k3,
- k4: self.k4,
- 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::Composite(params)))
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]