[librsvg/rect: 1/2] bbox: simplify api



commit 5e8b6a9b0b5e05828db50a3176c3e921aee84bfe
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Dec 8 20:07:10 2019 +0100

    bbox: simplify api

 rsvg_internals/src/bbox.rs           | 19 +++++++++++++++----
 rsvg_internals/src/drawing_ctx.rs    |  6 +++---
 rsvg_internals/src/filter.rs         |  4 ++--
 rsvg_internals/src/filters/bounds.rs |  7 ++++---
 rsvg_internals/src/image.rs          |  4 +---
 rsvg_internals/src/text.rs           |  7 +++----
 6 files changed, 28 insertions(+), 19 deletions(-)
---
diff --git a/rsvg_internals/src/bbox.rs b/rsvg_internals/src/bbox.rs
index 9f7b4a75..7976f216 100644
--- a/rsvg_internals/src/bbox.rs
+++ b/rsvg_internals/src/bbox.rs
@@ -18,12 +18,23 @@ impl BoundingBox {
         }
     }
 
-    pub fn with_rect(self, rect: Option<Rect>) -> BoundingBox {
-        BoundingBox { rect, ..self }
+    pub fn with_rect(self, rect: Rect) -> BoundingBox {
+        BoundingBox {
+            rect: Some(rect),
+            ..self
+        }
+    }
+
+    pub fn with_ink_rect(self, ink_rect: Rect) -> BoundingBox {
+        BoundingBox {
+            ink_rect: Some(ink_rect),
+            ..self
+        }
     }
 
-    pub fn with_ink_rect(self, ink_rect: Option<Rect>) -> BoundingBox {
-        BoundingBox { ink_rect, ..self }
+    pub fn clear(mut self) {
+        self.rect = None;
+        self.ink_rect = None;
     }
 
     fn combine(&mut self, src: &BoundingBox, clip: bool) {
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 9fd6c89f..0808d6fc 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -953,21 +953,21 @@ fn compute_stroke_and_fill_box(cr: &cairo::Context, values: &ComputedValues) ->
     // rectangle's extents, even when it has no fill nor stroke.
 
     let (x0, y0, x1, y1) = cr.fill_extents();
-    let fb = BoundingBox::new(&affine).with_ink_rect(Some(Rect::new(x0, y0, x1, y1)));
+    let fb = BoundingBox::new(&affine).with_ink_rect(Rect::new(x0, y0, x1, y1));
     bbox.insert(&fb);
 
     // Bounding box for stroke
 
     if values.stroke.0 != PaintServer::None {
         let (x0, y0, x1, y1) = cr.stroke_extents();
-        let sb = BoundingBox::new(&affine).with_ink_rect(Some(Rect::new(x0, y0, x1, y1)));
+        let sb = BoundingBox::new(&affine).with_ink_rect(Rect::new(x0, y0, x1, y1));
         bbox.insert(&sb);
     }
 
     // objectBoundingBox
 
     let (x0, y0, x1, y1) = cr.path_extents();
-    let ob = BoundingBox::new(&affine).with_rect(Some(Rect::new(x0, y0, x1, y1)));
+    let ob = BoundingBox::new(&affine).with_rect(Rect::new(x0, y0, x1, y1));
     bbox.insert(&ob);
 
     // restore tolerance
diff --git a/rsvg_internals/src/filter.rs b/rsvg_internals/src/filter.rs
index d6d37acc..f9a1541d 100644
--- a/rsvg_internals/src/filter.rs
+++ b/rsvg_internals/src/filter.rs
@@ -93,7 +93,7 @@ impl Filter {
         };
 
         let rect = Rect::new(x, y, x + w, y + h);
-        let other_bbox = BoundingBox::new(&affine).with_rect(Some(rect));
+        let other_bbox = BoundingBox::new(&affine).with_rect(rect);
 
         // At this point all of the previous viewbox and matrix business gets converted to pixel
         // coordinates in the final surface, because bbox is created with an identity affine.
@@ -101,7 +101,7 @@ impl Filter {
 
         // Finally, clip to the width and height of our surface.
         let rect = Rect::from_size(width, height);
-        let other_bbox = BoundingBox::new(&cairo::Matrix::identity()).with_rect(Some(rect));
+        let other_bbox = BoundingBox::new(&cairo::Matrix::identity()).with_rect(rect);
         bbox.clip(&other_bbox);
 
         bbox
diff --git a/rsvg_internals/src/filters/bounds.rs b/rsvg_internals/src/filters/bounds.rs
index 8983ea02..6fd5fff2 100644
--- a/rsvg_internals/src/filters/bounds.rs
+++ b/rsvg_internals/src/filters/bounds.rs
@@ -64,8 +64,8 @@ impl<'a> BoundsBuilder<'a> {
                 self.standard_input_was_referenced = true;
             }
             FilterInput::PrimitiveOutput(ref output) => {
-                let input_bbox = BoundingBox::new(&cairo::Matrix::identity())
-                    .with_rect(Some(output.bounds.into()));
+                let input_bbox =
+                    BoundingBox::new(&cairo::Matrix::identity()).with_rect(output.bounds.into());
                 self.bbox.insert(&input_bbox);
             }
         }
@@ -99,7 +99,8 @@ impl<'a> BoundsBuilder<'a> {
             let effects_region = self.ctx.effects_region();
 
             // Clear out the rect.
-            self.bbox = self.bbox.with_rect(None);
+            self.bbox.clear();
+
             // Convert into the paffine coordinate system.
             self.bbox.insert(&effects_region);
         }
diff --git a/rsvg_internals/src/image.rs b/rsvg_internals/src/image.rs
index 9d45bd23..65cba362 100644
--- a/rsvg_internals/src/image.rs
+++ b/rsvg_internals/src/image.rs
@@ -98,9 +98,7 @@ impl NodeTrait for Image {
 
             // The bounding box for <image> is decided by the values of x, y, w, h and not by
             // the final computed image bounds.
-            let bbox = dc
-                .empty_bbox()
-                .with_rect(Some(Rect::new(x, y, x + w, y + h)));
+            let bbox = dc.empty_bbox().with_rect(Rect::new(x, y, x + w, y + h));
 
             dc.with_saved_cr(&mut |dc| {
                 let cr = dc.get_cairo_context();
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index a16fe04a..35f19d67 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -345,7 +345,7 @@ impl PositionedSpan {
                     if !clipping {
                         let (x0, y0, x1, y1) = cr.stroke_extents();
                         let ib = BoundingBox::new(&affine)
-                            .with_ink_rect(Some(Rect::new(x0, y0, x1, y1)));
+                            .with_ink_rect(Rect::new(x0, y0, x1, y1));
                         cr.stroke();
                         bbox.insert(&ib);
                     }
@@ -389,9 +389,8 @@ impl PositionedSpan {
             )
         };
 
-        let bbox = BoundingBox::new(affine)
-            .with_rect(Some(Rect::new(x, y, x + w, y + h)))
-            .with_ink_rect(Some(Rect::new(x, y, x + w, y + h)));
+        let r = Rect::new(x, y, x + w, y + h);
+        let bbox = BoundingBox::new(affine).with_rect(r).with_ink_rect(r);
 
         Some(bbox)
     }


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