[librsvg: 1/10] filters: shorten code leveraging Rect's From trait



commit 92e22c30b297a5032ff9cfc13cd3825de4e841f3
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Nov 24 10:10:56 2019 +0100

    filters: shorten code leveraging Rect's From trait

 rsvg_internals/src/filters/bounds.rs | 17 ++++-------------
 rsvg_internals/src/filters/image.rs  | 27 +++++++--------------------
 2 files changed, 11 insertions(+), 33 deletions(-)
---
diff --git a/rsvg_internals/src/filters/bounds.rs b/rsvg_internals/src/filters/bounds.rs
index 1fc8cc1f..10094f9d 100644
--- a/rsvg_internals/src/filters/bounds.rs
+++ b/rsvg_internals/src/filters/bounds.rs
@@ -6,7 +6,7 @@ use crate::drawing_ctx::DrawingCtx;
 use crate::length::*;
 use crate::rect::IRect;
 
-use super::context::{FilterContext, FilterInput, FilterOutput};
+use super::context::{FilterContext, FilterInput};
 
 /// A helper type for filter primitive subregion computation.
 #[derive(Clone, Copy)]
@@ -63,18 +63,9 @@ impl<'a> BoundsBuilder<'a> {
             FilterInput::StandardInput(_) => {
                 self.standard_input_was_referenced = true;
             }
-            FilterInput::PrimitiveOutput(FilterOutput {
-                bounds: IRect { x0, y0, x1, y1 },
-                ..
-            }) => {
-                let rect = cairo::Rectangle {
-                    x: f64::from(x0),
-                    y: f64::from(y0),
-                    width: f64::from(x1 - x0),
-                    height: f64::from(y1 - y0),
-                };
-
-                let input_bbox = BoundingBox::new(&cairo::Matrix::identity()).with_rect(Some(rect));
+            FilterInput::PrimitiveOutput(ref output) => {
+                let input_bbox = BoundingBox::new(&cairo::Matrix::identity())
+                    .with_rect(Some(output.bounds.into()));
                 self.bbox.insert(&input_bbox);
             }
         }
diff --git a/rsvg_internals/src/filters/image.rs b/rsvg_internals/src/filters/image.rs
index d1fa2238..c4b14131 100644
--- a/rsvg_internals/src/filters/image.rs
+++ b/rsvg_internals/src/filters/image.rs
@@ -1,4 +1,4 @@
-use cairo::{self, ImageSurface, Rectangle};
+use cairo::{self, ImageSurface};
 use markup5ever::{expanded_name, local_name, namespace_url, ns};
 
 use crate::allowed_url::{Fragment, Href};
@@ -9,7 +9,7 @@ use crate::float_eq_cairo::ApproxEqCairo;
 use crate::node::{CascadedValues, NodeResult, NodeTrait, RsvgNode};
 use crate::parsers::{ParseError, ParseValue};
 use crate::property_bag::PropertyBag;
-use crate::rect::{IRect, RectangleExt};
+use crate::rect::IRect;
 use crate::surface_utils::shared_surface::{SharedImageSurface, SurfaceType};
 use crate::viewbox::ViewBox;
 
@@ -86,12 +86,8 @@ impl FeImage {
         )?;
 
         let cr = cairo::Context::new(&output_surface);
-        cr.rectangle(
-            f64::from(bounds.x0),
-            f64::from(bounds.y0),
-            f64::from(bounds.x1 - bounds.x0),
-            f64::from(bounds.y1 - bounds.y0),
-        );
+        let r = cairo::Rectangle::from(bounds);
+        cr.rectangle(r.x, r.y, r.width, r.height);
         cr.clip();
         cr.set_source_surface(&surface, 0f64, 0f64);
         cr.paint();
@@ -131,12 +127,7 @@ impl FeImage {
                 f64::from(surface.width()),
                 f64::from(surface.height()),
             ),
-            &Rectangle::new(
-                f64::from(unclipped_bounds.x0),
-                f64::from(unclipped_bounds.y0),
-                f64::from(unclipped_bounds.x1 - unclipped_bounds.x0),
-                f64::from(unclipped_bounds.y1 - unclipped_bounds.y0),
-            ),
+            &cairo::Rectangle::from(*unclipped_bounds),
         );
 
         if w.approx_eq_cairo(0.0) || h.approx_eq_cairo(0.0) {
@@ -156,12 +147,8 @@ impl FeImage {
         ptn.set_matrix(matrix);
 
         let cr = cairo::Context::new(&output_surface);
-        cr.rectangle(
-            f64::from(bounds.x0),
-            f64::from(bounds.y0),
-            f64::from(bounds.x1 - bounds.x0),
-            f64::from(bounds.y1 - bounds.y0),
-        );
+        let r = cairo::Rectangle::from(*bounds);
+        cr.rectangle(r.x, r.y, r.width, r.height);
         cr.clip();
         cr.set_source(&ptn);
         cr.paint();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]