[librsvg: 6/10] rect: rename method to intersection
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 6/10] rect: rename method to intersection
- Date: Mon, 25 Nov 2019 01:59:38 +0000 (UTC)
commit 52141b09b6db0f1cc62b09c7fc86a51349816d87
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Nov 24 19:39:23 2019 +0100
rect: rename method to intersection
rename and return Option, as done by euclid.
rsvg_internals/src/bbox.rs | 5 ++++-
rsvg_internals/src/rect.rs | 21 ++++++++-------------
2 files changed, 12 insertions(+), 14 deletions(-)
---
diff --git a/rsvg_internals/src/bbox.rs b/rsvg_internals/src/bbox.rs
index 68ccae69..d8bde22a 100644
--- a/rsvg_internals/src/bbox.rs
+++ b/rsvg_internals/src/bbox.rs
@@ -76,7 +76,10 @@ fn combine_rects(
match (r1, r2, clip) {
(r1, None, _) => r1,
(None, Some(r2), _) => Some(r2.transform(&affine)),
- (Some(r1), Some(r2), true) => Some(r2.transform(&affine).intersect(&r1)),
+ (Some(r1), Some(r2), true) => r2
+ .transform(&affine)
+ .intersection(&r1)
+ .or_else(|| Some(cairo::Rectangle::new(0.0, 0.0, 0.0, 0.0))),
(Some(r1), Some(r2), false) => Some(r2.transform(&affine).union(&r1)),
}
}
diff --git a/rsvg_internals/src/rect.rs b/rsvg_internals/src/rect.rs
index f8c892a9..694b11ec 100644
--- a/rsvg_internals/src/rect.rs
+++ b/rsvg_internals/src/rect.rs
@@ -7,7 +7,7 @@ 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 intersect(&self, rect: &cairo::Rectangle) -> cairo::Rectangle;
+ 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 outer(&self) -> cairo::Rectangle;
@@ -36,7 +36,7 @@ impl RectangleExt for cairo::Rectangle {
self.width.approx_eq_cairo(0.0) || self.height.approx_eq_cairo(0.0)
}
- fn intersect(&self, rect: &cairo::Rectangle) -> cairo::Rectangle {
+ fn intersection(&self, rect: &cairo::Rectangle) -> Option<cairo::Rectangle> {
let (x1, y1, x2, y2) = (
self.x.max(rect.x),
self.y.max(rect.y),
@@ -45,19 +45,14 @@ impl RectangleExt for cairo::Rectangle {
);
if x2 > x1 && y2 > y1 {
- cairo::Rectangle {
+ Some(cairo::Rectangle {
x: x1,
y: y1,
width: x2 - x1,
height: y2 - y1,
- }
+ })
} else {
- cairo::Rectangle {
- x: 0.0,
- y: 0.0,
- width: 0.0,
- height: 0.0,
- }
+ None
}
}
@@ -258,14 +253,14 @@ mod tests {
height: 3.14,
};
- let r = r1.intersect(&r2);
+ 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.intersect(&r3);
- assert!(r.is_empty());
+ let r = r1.intersection(&r3);
+ assert!(r.is_none());
}
#[test]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]