[librsvg] ViewBox::new() - new constructor



commit 0c0c26c8eeabd215fc11bff5a32595d241be1f59
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Sep 28 13:19:16 2017 -0500

    ViewBox::new() - new constructor

 rust/src/viewbox.rs |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/rust/src/viewbox.rs b/rust/src/viewbox.rs
index 1e882f7..af1bb87 100644
--- a/rust/src/viewbox.rs
+++ b/rust/src/viewbox.rs
@@ -20,6 +20,14 @@ pub struct RsvgViewBox {
 #[derive(Debug, Copy, Clone, PartialEq)]
 pub struct ViewBox(pub cairo::Rectangle);
 
+impl ViewBox {
+    pub fn new(x: f64, y: f64, w: f64, h: f64) -> ViewBox {
+        assert!(w >= 0.0 && h >= 0.0, "width and height must not be negative");
+
+        ViewBox(cairo::Rectangle { x: x, y: y, width: w, height: h })
+    }
+}
+
 impl From<Option<ViewBox>> for RsvgViewBox {
     fn from(v: Option<ViewBox>) -> RsvgViewBox {
         if let Some(vb) = v {
@@ -75,16 +83,10 @@ mod tests {
     #[test]
     fn parses_valid_viewboxes () {
         assert_eq! (ViewBox::parse ("  1 2 3 4", ()),
-                    Ok (ViewBox (cairo::Rectangle { x: 1.0,
-                                                    y: 2.0,
-                                                    width: 3.0,
-                                                    height: 4.0 })));
+                    Ok (ViewBox::new(1.0, 2.0, 3.0, 4.0)));
 
         assert_eq! (ViewBox::parse (" -1.5 -2.5e1,34,56e2  ", ()),
-                    Ok (ViewBox (cairo::Rectangle { x: -1.5,
-                                                    y: -25.0,
-                                                    width: 34.0,
-                                                    height: 5600.0 })));
+                    Ok (ViewBox::new(-1.5, -25.0, 34.0, 5600.0)));
     }
 
     #[test]


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