[librsvg: 3/7] rect: conversion trait



commit 0de009d8953ad577cffbf577e7d14f2653ef26d0
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 5b3ae45d..9d29127d 100644
--- a/rsvg_internals/src/rect.rs
+++ b/rsvg_internals/src/rect.rs
@@ -158,6 +158,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 {
@@ -184,6 +196,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]