[librsvg: 2/7] Add a Rect type alias for rect::Rect<f64>
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/7] Add a Rect type alias for rect::Rect<f64>
- Date: Tue, 10 Dec 2019 13:55:50 +0000 (UTC)
commit 0f0492cc521fcd58ec036d379220ff008fef141f
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Dec 8 12:03:53 2019 +0100
Add a Rect type alias for rect::Rect<f64>
rsvg_internals/src/rect.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
---
diff --git a/rsvg_internals/src/rect.rs b/rsvg_internals/src/rect.rs
index 03ad6a4e..5b3ae45d 100644
--- a/rsvg_internals/src/rect.rs
+++ b/rsvg_internals/src/rect.rs
@@ -3,6 +3,7 @@ use cairo;
use crate::float_eq_cairo::ApproxEqCairo;
mod rect {
+ use crate::float_eq_cairo::ApproxEqCairo;
use core::ops::{Add, Range, Sub};
use num_traits::Zero;
@@ -136,6 +137,49 @@ mod rect {
}
}
}
+
+ impl Rect<f64> {
+ #[inline]
+ pub fn is_empty(&self) -> bool {
+ self.width().approx_eq_cairo(0.0) || self.height().approx_eq_cairo(0.0)
+ }
+
+ #[inline]
+ pub fn scale(self, x: f64, y: f64) -> Self {
+ Self {
+ x0: self.x0 * x,
+ y0: self.y0 * y,
+ x1: self.x1 * x,
+ y1: self.y1 * y,
+ }
+ }
+ }
+}
+
+pub type Rect = rect::Rect<f64>;
+
+impl From<cairo::Rectangle> for Rect {
+ #[inline]
+ fn from(r: cairo::Rectangle) -> Self {
+ Self {
+ x0: r.x,
+ y0: r.y,
+ x1: r.x + r.width,
+ y1: r.y + r.height,
+ }
+ }
+}
+
+impl From<Rect> for cairo::Rectangle {
+ #[inline]
+ fn from(r: Rect) -> Self {
+ Self {
+ x: r.x0,
+ y: r.y0,
+ width: r.x1 - r.x0,
+ height: r.y1 - r.y0,
+ }
+ }
}
pub type IRect = rect::Rect<i32>;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]