[librsvg: 24/36] filters/morphology: remove interior mutability
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 24/36] filters/morphology: remove interior mutability
- Date: Mon, 1 Jul 2019 01:55:39 +0000 (UTC)
commit 81151fc70082b6ac5da07f3baa78c2a496ede52d
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Jun 30 16:34:03 2019 +0200
filters/morphology: remove interior mutability
rsvg_internals/src/filters/morphology.rs | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
---
diff --git a/rsvg_internals/src/filters/morphology.rs b/rsvg_internals/src/filters/morphology.rs
index 4c9f6488..02beebc1 100644
--- a/rsvg_internals/src/filters/morphology.rs
+++ b/rsvg_internals/src/filters/morphology.rs
@@ -1,4 +1,3 @@
-use std::cell::Cell;
use std::cmp::{max, min};
use cairo::{self, ImageSurface, MatrixTrait};
@@ -31,8 +30,8 @@ enum Operator {
/// The `feMorphology` filter primitive.
pub struct Morphology {
base: PrimitiveWithInput,
- operator: Cell<Operator>,
- radius: Cell<(f64, f64)>,
+ operator: Operator,
+ radius: (f64, f64),
}
impl Default for Morphology {
@@ -41,8 +40,8 @@ impl Default for Morphology {
fn default() -> Morphology {
Morphology {
base: PrimitiveWithInput::new::<Self>(),
- operator: Cell::new(Operator::Erode),
- radius: Cell::new((0.0, 0.0)),
+ operator: Operator::Erode,
+ radius: (0.0, 0.0),
}
}
}
@@ -55,9 +54,9 @@ impl NodeTrait for Morphology {
for (attr, value) in pbag.iter() {
match attr {
- local_name!("operator") => self.operator.set(Operator::parse(attr, value)?),
- local_name!("radius") => self.radius.set(
- parsers::number_optional_number(value)
+ local_name!("operator") => self.operator = Operator::parse(attr, value)?,
+ local_name!("radius") => {
+ self.radius = parsers::number_optional_number(value)
.attribute(attr.clone())
.and_then(|(x, y)| {
if x >= 0.0 && y >= 0.0 {
@@ -65,8 +64,8 @@ impl NodeTrait for Morphology {
} else {
Err(NodeError::value_error(attr, "radius cannot be negative"))
}
- })?,
- ),
+ })?
+ }
_ => (),
}
}
@@ -89,15 +88,13 @@ impl Filter for Morphology {
.add_input(&input)
.into_irect(draw_ctx);
- let (rx, ry) = self.radius.get();
+ let (rx, ry) = self.radius;
let (rx, ry) = ctx.paffine().transform_distance(rx, ry);
// The radii can become negative here due to the transform.
let rx = rx.abs();
let ry = ry.abs();
- let operator = self.operator.get();
-
let mut output_surface = ImageSurface::create(
cairo::Format::ARgb32,
ctx.source_graphic().width(),
@@ -118,7 +115,7 @@ impl Filter for Morphology {
};
// Compute the new pixel values.
- let initial = match operator {
+ let initial = match self.operator {
Operator::Erode => u8::max_value(),
Operator::Dilate => u8::min_value(),
};
@@ -133,7 +130,7 @@ impl Filter for Morphology {
for (_x, _y, pixel) in
PixelRectangle::new(&input.surface(), bounds, kernel_bounds, EdgeMode::None)
{
- let op = match operator {
+ let op = match self.operator {
Operator::Erode => min,
Operator::Dilate => max,
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]