[librsvg/rect: 3/10] rect: conversion trait



commit e5bed7867d1b95063fc214e7a4c9457d5705c379
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Dec 8 13:45:05 2019 +0100

    rect: conversion trait

 rsvg_internals/src/rect.rs | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
---
diff --git a/rsvg_internals/src/rect.rs b/rsvg_internals/src/rect.rs
index 4b1bd5aa..5b0d5bb6 100644
--- a/rsvg_internals/src/rect.rs
+++ b/rsvg_internals/src/rect.rs
@@ -153,6 +153,18 @@ mod rect {
 
 pub type Rect = rect::Rect<f64>;
 
+impl From<Rect> for IRect {
+    #[inline]
+    fn from(r: Rect) -> Self {
+        Self {
+            x0: r.x0.floor() as i32,
+            y0: r.y0.floor() as i32,
+            x1: r.x1.ceil() as i32,
+            y1: r.y1.ceil() as i32,
+        }
+    }
+}
+
 impl From<cairo::Rectangle> for Rect {
     #[inline]
     fn from(r: cairo::Rectangle) -> Self {
@@ -179,6 +191,18 @@ impl From<Rect> for cairo::Rectangle {
 
 pub type IRect = rect::Rect<i32>;
 
+impl From<IRect> for Rect {
+    #[inline]
+    fn from(r: IRect) -> Self {
+        Self {
+            x0: f64::from(r.x0),
+            y0: f64::from(r.y0),
+            x1: f64::from(r.x1),
+            y1: f64::from(r.y1),
+        }
+    }
+}
+
 impl From<cairo::Rectangle> for IRect {
     #[inline]
     fn from(r: cairo::Rectangle) -> Self {


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