[librsvg: 3/7] bbox: rename function to with_transform



commit b4126c612e160b19996ce277e293cd23c1f6d4c8
Author: Paolo Borelli <pborelli gnome org>
Date:   Fri Jan 17 23:59:21 2020 +0100

    bbox: rename function to with_transform

 rsvg_internals/src/bbox.rs           | 46 ++++++++++++++++++------------------
 rsvg_internals/src/drawing_ctx.rs    | 14 +++++------
 rsvg_internals/src/filter.rs         |  2 +-
 rsvg_internals/src/filters/bounds.rs |  8 +++----
 rsvg_internals/src/text.rs           |  6 +++--
 rsvg_internals/src/transform.rs      |  8 ++-----
 6 files changed, 41 insertions(+), 43 deletions(-)
---
diff --git a/rsvg_internals/src/bbox.rs b/rsvg_internals/src/bbox.rs
index bb89186c..d7a918d7 100644
--- a/rsvg_internals/src/bbox.rs
+++ b/rsvg_internals/src/bbox.rs
@@ -4,7 +4,7 @@ use crate::rect::{Rect, TransformRect};
 
 #[derive(Debug, Copy, Clone)]
 pub struct BoundingBox {
-    pub affine: cairo::Matrix,
+    pub transform: cairo::Matrix,
     pub rect: Option<Rect>,     // without stroke
     pub ink_rect: Option<Rect>, // with stroke
 }
@@ -12,14 +12,14 @@ pub struct BoundingBox {
 impl BoundingBox {
     pub fn new() -> BoundingBox {
         BoundingBox {
-            affine: cairo::Matrix::identity(),
+            transform: cairo::Matrix::identity(),
             rect: None,
             ink_rect: None,
         }
     }
 
-    pub fn with_affine(self, affine: cairo::Matrix) -> BoundingBox {
-        BoundingBox { affine, ..self }
+    pub fn with_transform(self, transform: cairo::Matrix) -> BoundingBox {
+        BoundingBox { transform, ..self }
     }
 
     pub fn with_rect(self, rect: Rect) -> BoundingBox {
@@ -46,14 +46,14 @@ impl BoundingBox {
             return;
         }
 
-        let mut affine = self.affine;
+        let mut transform = self.transform;
 
         // this will panic!() if it's not invertible... should we check on our own?
-        affine.invert();
-        affine = cairo::Matrix::multiply(&src.affine, &affine);
+        transform.invert();
+        transform = cairo::Matrix::multiply(&src.transform, &transform);
 
-        self.rect = combine_rects(self.rect, src.rect, &affine, clip);
-        self.ink_rect = combine_rects(self.ink_rect, src.ink_rect, &affine, clip);
+        self.rect = combine_rects(self.rect, src.rect, &transform, clip);
+        self.ink_rect = combine_rects(self.ink_rect, src.ink_rect, &transform, clip);
     }
 
     pub fn insert(&mut self, src: &BoundingBox) {
@@ -68,17 +68,17 @@ impl BoundingBox {
 fn combine_rects(
     r1: Option<Rect>,
     r2: Option<Rect>,
-    affine: &cairo::Matrix,
+    transform: &cairo::Matrix,
     clip: bool,
 ) -> Option<Rect> {
     match (r1, r2, clip) {
         (r1, None, _) => r1,
-        (None, Some(r2), _) => Some(affine.transform_rect(&r2)),
-        (Some(r1), Some(r2), true) => affine
+        (None, Some(r2), _) => Some(transform.transform_rect(&r2)),
+        (Some(r1), Some(r2), true) => transform
             .transform_rect(&r2)
             .intersection(&r1)
             .or_else(|| Some(Rect::default())),
-        (Some(r1), Some(r2), false) => Some(affine.transform_rect(&r2).union(&r1)),
+        (Some(r1), Some(r2), false) => Some(transform.transform_rect(&r2).union(&r1)),
     }
 }
 
@@ -91,33 +91,33 @@ mod tests {
         let r1 = Rect::new(1.0, 2.0, 3.0, 4.0);
         let r2 = Rect::new(1.5, 2.5, 3.5, 4.5);
         let r3 = Rect::new(10.0, 11.0, 12.0, 13.0);
-        let affine = cairo::Matrix::new(1.0, 0.0, 0.0, 1.0, 0.5, 0.5);
+        let t = cairo::Matrix::new(1.0, 0.0, 0.0, 1.0, 0.5, 0.5);
 
-        let res = combine_rects(None, None, &affine, true);
+        let res = combine_rects(None, None, &t, true);
         assert_eq!(res, None);
 
-        let res = combine_rects(None, None, &affine, false);
+        let res = combine_rects(None, None, &t, false);
         assert_eq!(res, None);
 
-        let res = combine_rects(Some(r1), None, &affine, true);
+        let res = combine_rects(Some(r1), None, &t, true);
         assert_eq!(res, Some(r1));
 
-        let res = combine_rects(Some(r1), None, &affine, false);
+        let res = combine_rects(Some(r1), None, &t, false);
         assert_eq!(res, Some(r1));
 
-        let res = combine_rects(None, Some(r2), &affine, true);
+        let res = combine_rects(None, Some(r2), &t, true);
         assert_eq!(res, Some(Rect::new(2.0, 3.0, 4.0, 5.0)));
 
-        let res = combine_rects(None, Some(r2), &affine, false);
+        let res = combine_rects(None, Some(r2), &t, false);
         assert_eq!(res, Some(Rect::new(2.0, 3.0, 4.0, 5.0)));
 
-        let res = combine_rects(Some(r1), Some(r2), &affine, true);
+        let res = combine_rects(Some(r1), Some(r2), &t, true);
         assert_eq!(res, Some(Rect::new(2.0, 3.0, 3.0, 4.0)));
 
-        let res = combine_rects(Some(r1), Some(r3), &affine, true);
+        let res = combine_rects(Some(r1), Some(r3), &t, true);
         assert_eq!(res, Some(Rect::default()));
 
-        let res = combine_rects(Some(r1), Some(r2), &affine, false);
+        let res = combine_rects(Some(r1), Some(r2), &t, false);
         assert_eq!(res, Some(Rect::new(1.0, 2.0, 4.0, 5.0)));
     }
 }
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index cf4ae9d5..327921d0 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -190,7 +190,7 @@ impl DrawingCtx {
     }
 
     pub fn empty_bbox(&self) -> BoundingBox {
-        BoundingBox::new().with_affine(self.get_transform())
+        BoundingBox::new().with_transform(self.get_transform())
     }
 
     // FIXME: Usage of this function is more less a hack... The caller
@@ -518,7 +518,7 @@ impl DrawingCtx {
                     let bbox = if let Ok(ref bbox) = res {
                         *bbox
                     } else {
-                        BoundingBox::new().with_affine(affines.for_temporary_surface)
+                        BoundingBox::new().with_transform(affines.for_temporary_surface)
                     };
 
                     // Filter
@@ -633,7 +633,7 @@ impl DrawingCtx {
         self.cr.set_matrix(orig_transform);
 
         if let Ok(bbox) = res {
-            let mut res_bbox = BoundingBox::new().with_affine(orig_transform);
+            let mut res_bbox = BoundingBox::new().with_transform(orig_transform);
             res_bbox.insert(&bbox);
             Ok(res_bbox)
         } else {
@@ -1210,7 +1210,7 @@ fn acquire_paint_server(
 fn compute_stroke_and_fill_box(cr: &cairo::Context, values: &ComputedValues) -> BoundingBox {
     let affine = cr.get_matrix();
 
-    let mut bbox = BoundingBox::new().with_affine(affine);
+    let mut bbox = BoundingBox::new().with_transform(affine);
 
     // Dropping the precision of cairo's bezier subdivision, yielding 2x
     // _rendering_ time speedups, are these rather expensive operations
@@ -1228,7 +1228,7 @@ fn compute_stroke_and_fill_box(cr: &cairo::Context, values: &ComputedValues) ->
 
     let (x0, y0, x1, y1) = cr.fill_extents();
     let fb = BoundingBox::new()
-        .with_affine(affine)
+        .with_transform(affine)
         .with_ink_rect(Rect::new(x0, y0, x1, y1));
     bbox.insert(&fb);
 
@@ -1237,7 +1237,7 @@ fn compute_stroke_and_fill_box(cr: &cairo::Context, values: &ComputedValues) ->
     if values.stroke.0 != PaintServer::None {
         let (x0, y0, x1, y1) = cr.stroke_extents();
         let sb = BoundingBox::new()
-            .with_affine(affine)
+            .with_transform(affine)
             .with_ink_rect(Rect::new(x0, y0, x1, y1));
         bbox.insert(&sb);
     }
@@ -1246,7 +1246,7 @@ fn compute_stroke_and_fill_box(cr: &cairo::Context, values: &ComputedValues) ->
 
     let (x0, y0, x1, y1) = cr.path_extents();
     let ob = BoundingBox::new()
-        .with_affine(affine)
+        .with_transform(affine)
         .with_rect(Rect::new(x0, y0, x1, y1));
     bbox.insert(&ob);
 
diff --git a/rsvg_internals/src/filter.rs b/rsvg_internals/src/filter.rs
index acf0f3cb..d2244baf 100644
--- a/rsvg_internals/src/filter.rs
+++ b/rsvg_internals/src/filter.rs
@@ -94,7 +94,7 @@ impl Filter {
         };
 
         let rect = Rect::new(x, y, x + w, y + h);
-        let other_bbox = BoundingBox::new().with_affine(affine).with_rect(rect);
+        let other_bbox = BoundingBox::new().with_transform(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.
diff --git a/rsvg_internals/src/filters/bounds.rs b/rsvg_internals/src/filters/bounds.rs
index 9433eaea..0d4a0a64 100644
--- a/rsvg_internals/src/filters/bounds.rs
+++ b/rsvg_internals/src/filters/bounds.rs
@@ -37,8 +37,8 @@ impl<'a> BoundsBuilder<'a> {
     ) -> Self {
         Self {
             ctx,
-            // The matrix is paffine because we're using that fact in apply_properties().
-            bbox: BoundingBox::new().with_affine(ctx.paffine()),
+            // The transform is paffine because we're using that fact in apply_properties().
+            bbox: BoundingBox::new().with_transform(ctx.paffine()),
             standard_input_was_referenced: false,
             x,
             y,
@@ -110,8 +110,8 @@ impl<'a> BoundsBuilder<'a> {
             let params = self.ctx.get_view_params(draw_ctx);
             let values = self.ctx.get_computed_values_from_node_being_filtered();
 
-            // These replacements are correct only because self.bbox is used with the paffine
-            // matrix.
+            // These replacements are correct only because self.bbox is used with the
+            // paffine transform.
             let rect = self.bbox.rect.as_mut().unwrap();
 
             if let Some(x) = self.x {
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index 405d8bf9..e5fcc426 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -342,7 +342,9 @@ impl PositionedSpan {
                     if !clipping {
                         let (x0, y0, x1, y1) = cr.stroke_extents();
                         let r = Rect::new(x0, y0, x1, y1);
-                        let ib = BoundingBox::new().with_affine(transform).with_ink_rect(r);
+                        let ib = BoundingBox::new()
+                            .with_transform(transform)
+                            .with_ink_rect(r);
                         cr.stroke();
                         bbox.insert(&ib);
                     }
@@ -388,7 +390,7 @@ impl PositionedSpan {
 
         let r = Rect::new(x, y, x + w, y + h);
         let bbox = BoundingBox::new()
-            .with_affine(transform)
+            .with_transform(transform)
             .with_rect(r)
             .with_ink_rect(r);
 
diff --git a/rsvg_internals/src/transform.rs b/rsvg_internals/src/transform.rs
index a51d6d77..a8715951 100644
--- a/rsvg_internals/src/transform.rs
+++ b/rsvg_internals/src/transform.rs
@@ -25,9 +25,7 @@ impl Parse for cairo::Matrix {
 // Its operataion and grammar are described here:
 // https://www.w3.org/TR/SVG/coords.html#TransformAttribute
 
-fn parse_transform_list<'i>(
-    parser: &mut Parser<'i, '_>,
-) -> Result<cairo::Matrix, ParseError<'i>> {
+fn parse_transform_list<'i>(parser: &mut Parser<'i, '_>) -> Result<cairo::Matrix, ParseError<'i>> {
     let mut matrix = cairo::Matrix::identity();
 
     loop {
@@ -103,9 +101,7 @@ fn parse_matrix_args<'i>(parser: &mut Parser<'i, '_>) -> Result<cairo::Matrix, P
     })
 }
 
-fn parse_translate_args<'i>(
-    parser: &mut Parser<'i, '_>,
-) -> Result<cairo::Matrix, ParseError<'i>> {
+fn parse_translate_args<'i>(parser: &mut Parser<'i, '_>) -> Result<cairo::Matrix, ParseError<'i>> {
     parser.parse_nested_block(|p| {
         let tx = f64::parse(p)?;
 


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