[librsvg/rect: 10/10] rect: remove cairo extension trait



commit e9e8949ea0c45d8af0395a58bce6f2e687d4e5b8
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Dec 8 20:14:52 2019 +0100

    rect: remove cairo extension trait

 rsvg_internals/src/handle.rs |  12 +--
 rsvg_internals/src/rect.rs   | 247 -------------------------------------------
 2 files changed, 6 insertions(+), 253 deletions(-)
---
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index eb8f9d21..8213f8b7 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -15,7 +15,7 @@ use crate::dpi::Dpi;
 use crate::drawing_ctx::DrawingCtx;
 use crate::error::{DefsLookupErrorKind, LoadingError, RenderingError};
 use crate::node::{CascadedValues, RsvgNode};
-use crate::rect::{Rect, RectangleExt};
+use crate::rect::{IRect, Rect};
 use crate::structure::{IntrinsicDimensions, Svg};
 use url::Url;
 
@@ -324,12 +324,12 @@ impl Handle {
             if let Some((root_width, root_height)) =
                 node.borrow().get_impl::<Svg>().get_size(&values, dpi)
             {
-                let ink_r =
-                    cairo::Rectangle::from_size(f64::from(root_width), f64::from(root_height));
+                let rect = IRect::from_size(root_width, root_height);
 
-                let logical_r = ink_r;
-
-                return Ok((ink_r, logical_r));
+                return Ok((
+                    cairo::Rectangle::from(rect),
+                    cairo::Rectangle::from(rect),
+                ))
             }
         }
 
diff --git a/rsvg_internals/src/rect.rs b/rsvg_internals/src/rect.rs
index a97f3606..03e73487 100644
--- a/rsvg_internals/src/rect.rs
+++ b/rsvg_internals/src/rect.rs
@@ -1,7 +1,5 @@
 use cairo;
 
-use crate::float_eq_cairo::ApproxEqCairo;
-
 mod rect {
     use crate::float_eq_cairo::ApproxEqCairo;
     use core::ops::{Add, Range, Sub};
@@ -272,248 +270,3 @@ impl TransformRect for cairo::Matrix {
         }
     }
 }
-
-pub trait RectangleExt {
-    fn new(x: f64, y: f64, width: f64, height: f64) -> cairo::Rectangle;
-    fn from_size(width: f64, height: f64) -> cairo::Rectangle;
-    fn is_empty(&self) -> bool;
-    fn intersection(&self, rect: &cairo::Rectangle) -> Option<cairo::Rectangle>;
-    fn union(&self, rect: &cairo::Rectangle) -> cairo::Rectangle;
-    fn transform(&self, affine: &cairo::Matrix) -> cairo::Rectangle;
-    fn translate(&self, by: (f64, f64)) -> cairo::Rectangle;
-    fn outer(&self) -> cairo::Rectangle;
-}
-
-impl RectangleExt for cairo::Rectangle {
-    fn new(x: f64, y: f64, width: f64, height: f64) -> cairo::Rectangle {
-        cairo::Rectangle {
-            x,
-            y,
-            width,
-            height,
-        }
-    }
-
-    fn from_size(width: f64, height: f64) -> cairo::Rectangle {
-        cairo::Rectangle {
-            x: 0.0,
-            y: 0.0,
-            width,
-            height,
-        }
-    }
-
-    fn is_empty(&self) -> bool {
-        self.width.approx_eq_cairo(0.0) || self.height.approx_eq_cairo(0.0)
-    }
-
-    fn intersection(&self, rect: &cairo::Rectangle) -> Option<cairo::Rectangle> {
-        let (x1, y1, x2, y2) = (
-            self.x.max(rect.x),
-            self.y.max(rect.y),
-            (self.x + self.width).min(rect.x + rect.width),
-            (self.y + self.height).min(rect.y + rect.height),
-        );
-
-        if x2 > x1 && y2 > y1 {
-            Some(cairo::Rectangle {
-                x: x1,
-                y: y1,
-                width: x2 - x1,
-                height: y2 - y1,
-            })
-        } else {
-            None
-        }
-    }
-
-    fn union(&self, rect: &cairo::Rectangle) -> cairo::Rectangle {
-        let (x1, y1, x2, y2) = (
-            self.x.min(rect.x),
-            self.y.min(rect.y),
-            (self.x + self.width).max(rect.x + rect.width),
-            (self.y + self.height).max(rect.y + rect.height),
-        );
-
-        cairo::Rectangle {
-            x: x1,
-            y: y1,
-            width: x2 - x1,
-            height: y2 - y1,
-        }
-    }
-
-    fn transform(&self, affine: &cairo::Matrix) -> cairo::Rectangle {
-        let points = vec![
-            affine.transform_point(self.x, self.y),
-            affine.transform_point(self.x + self.width, self.y),
-            affine.transform_point(self.x, self.y + self.height),
-            affine.transform_point(self.x + self.width, self.y + self.height),
-        ];
-
-        let (mut xmin, mut ymin, mut xmax, mut ymax) = {
-            let (x, y) = points[0];
-
-            (x, y, x, y)
-        };
-
-        for &(x, y) in points.iter().take(4).skip(1) {
-            if x < xmin {
-                xmin = x;
-            }
-
-            if x > xmax {
-                xmax = x;
-            }
-
-            if y < ymin {
-                ymin = y;
-            }
-
-            if y > ymax {
-                ymax = y;
-            }
-        }
-
-        cairo::Rectangle {
-            x: xmin,
-            y: ymin,
-            width: xmax - xmin,
-            height: ymax - ymin,
-        }
-    }
-
-    fn translate(&self, by: (f64, f64)) -> cairo::Rectangle {
-        cairo::Rectangle {
-            x: self.x + by.0,
-            y: self.y + by.1,
-            width: self.width,
-            height: self.height,
-        }
-    }
-
-    fn outer(&self) -> cairo::Rectangle {
-        let (x, y) = (self.x.floor(), self.y.floor());
-
-        cairo::Rectangle {
-            x,
-            y,
-            width: (self.x + self.width).ceil() - x,
-            height: (self.y + self.height).ceil() - y,
-        }
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-
-    #[test]
-    fn empty_rect() {
-        let empty = cairo::Rectangle {
-            x: 0.42,
-            y: 0.42,
-            width: 0.0,
-            height: 0.0,
-        };
-        let not_empty = cairo::Rectangle {
-            x: 0.22,
-            y: 0.22,
-            width: 3.14,
-            height: 3.14,
-        };
-
-        assert!(empty.is_empty());
-        assert!(!not_empty.is_empty());
-    }
-
-    #[test]
-    fn intersect_rects() {
-        let r1 = cairo::Rectangle {
-            x: 0.42,
-            y: 0.42,
-            width: 4.14,
-            height: 4.14,
-        };
-        let r2 = cairo::Rectangle {
-            x: 0.22,
-            y: 0.22,
-            width: 3.14,
-            height: 3.14,
-        };
-        let r3 = cairo::Rectangle {
-            x: 10.0,
-            y: 10.0,
-            width: 3.14,
-            height: 3.14,
-        };
-
-        let r = r1.intersection(&r2).unwrap();
-        assert_approx_eq_cairo!(0.42_f64, r.x);
-        assert_approx_eq_cairo!(0.42_f64, r.y);
-        assert_approx_eq_cairo!(2.94_f64, r.width);
-        assert_approx_eq_cairo!(2.94_f64, r.height);
-
-        let r = r1.intersection(&r3);
-        assert!(r.is_none());
-    }
-
-    #[test]
-    fn union_rects() {
-        let r1 = cairo::Rectangle {
-            x: 0.42,
-            y: 0.42,
-            width: 4.14,
-            height: 4.14,
-        };
-        let r2 = cairo::Rectangle {
-            x: 0.22,
-            y: 0.22,
-            width: 3.14,
-            height: 3.14,
-        };
-
-        let r = r1.union(&r2);
-        assert_approx_eq_cairo!(0.22_f64, r.x);
-        assert_approx_eq_cairo!(0.22_f64, r.y);
-        assert_approx_eq_cairo!(4.34_f64, r.width);
-        assert_approx_eq_cairo!(4.34_f64, r.height);
-    }
-
-    #[test]
-    fn transform_rect() {
-        let r = cairo::Rectangle {
-            x: 0.42,
-            y: 0.42,
-            width: 3.14,
-            height: 3.14,
-        };
-
-        let m = cairo::Matrix::identity();
-        let tr = r.transform(&m);
-        assert_eq!(tr, r);
-
-        let m = cairo::Matrix::new(2.0, 0.0, 0.0, 2.0, 1.5, 1.5);
-        let tr = r.transform(&m);
-        assert_approx_eq_cairo!(2.34_f64, tr.x);
-        assert_approx_eq_cairo!(2.34_f64, tr.y);
-        assert_approx_eq_cairo!(6.28_f64, tr.width);
-        assert_approx_eq_cairo!(6.28_f64, tr.height);
-    }
-
-    #[test]
-    fn outer_rect() {
-        let r = cairo::Rectangle {
-            x: 1.42,
-            y: 1.42,
-            width: 3.14,
-            height: 3.14,
-        };
-
-        let or = r.outer();
-        assert_eq!(1.0, or.x);
-        assert_eq!(1.0, or.y);
-        assert_eq!(4.0, or.width);
-        assert_eq!(4.0, or.height);
-    }
-}


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