[librsvg/rect: 9/10] bbox: simplify api



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

    bbox: simplify api

 rsvg_internals/src/bbox.rs           | 13 +++++++++----
 rsvg_internals/src/drawing_ctx.rs    |  6 +++---
 rsvg_internals/src/filter.rs         |  4 ++--
 rsvg_internals/src/filters/bounds.rs |  5 +++--
 rsvg_internals/src/image.rs          |  2 +-
 rsvg_internals/src/text.rs           |  7 +++----
 6 files changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/rsvg_internals/src/bbox.rs b/rsvg_internals/src/bbox.rs
index 9f7b4a75..1539691f 100644
--- a/rsvg_internals/src/bbox.rs
+++ b/rsvg_internals/src/bbox.rs
@@ -18,12 +18,17 @@ 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: Option<Rect>) -> BoundingBox {
-        BoundingBox { ink_rect, ..self }
+    pub fn with_ink_rect(self, ink_rect: Rect) -> BoundingBox {
+        BoundingBox { ink_rect: Some(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..ff4e18d5 100644
--- a/rsvg_internals/src/filters/bounds.rs
+++ b/rsvg_internals/src/filters/bounds.rs
@@ -65,7 +65,7 @@ impl<'a> BoundsBuilder<'a> {
             }
             FilterInput::PrimitiveOutput(ref output) => {
                 let input_bbox = BoundingBox::new(&cairo::Matrix::identity())
-                    .with_rect(Some(output.bounds.into()));
+                    .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..5f08538e 100644
--- a/rsvg_internals/src/image.rs
+++ b/rsvg_internals/src/image.rs
@@ -100,7 +100,7 @@ impl NodeTrait for Image {
             // the final computed image bounds.
             let bbox = dc
                 .empty_bbox()
-                .with_rect(Some(Rect::new(x, y, x + w, y + h)));
+                .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]