[librsvg] shapes.rs: Use RsvgLength::check_nonnegative()



commit b8da0ba2201646205f58dfcf09e1ae93f608ef3a
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Sep 4 13:09:51 2017 -0500

    shapes.rs: Use RsvgLength::check_nonnegative()

 rust/src/shapes.rs |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/rust/src/shapes.rs b/rust/src/shapes.rs
index 989f91f..d2808f0 100644
--- a/rust/src/shapes.rs
+++ b/rust/src/shapes.rs
@@ -448,7 +448,10 @@ impl NodeTrait for NodeCircle {
     fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
         self.cx.set (property_bag::length_or_default (pbag, "cx", LengthDir::Horizontal)?);
         self.cy.set (property_bag::length_or_default (pbag, "cy", LengthDir::Vertical)?);
-        self.r.set  (property_bag::length_or_default (pbag, "r", LengthDir::Both)?);
+
+        self.r.set  (property_bag::length_or_default (pbag, "r", LengthDir::Both)
+                     .and_then (|l| l.check_nonnegative ()
+                                .map_err (|e| NodeError::attribute_error ("r", e)))?);
 
         Ok (())
     }
@@ -490,8 +493,14 @@ impl NodeTrait for NodeEllipse {
     fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
         self.cx.set (property_bag::length_or_default (pbag, "cx", LengthDir::Horizontal)?);
         self.cy.set (property_bag::length_or_default (pbag, "cy", LengthDir::Vertical)?);
-        self.rx.set (property_bag::length_or_default (pbag, "rx", LengthDir::Horizontal)?);
-        self.ry.set (property_bag::length_or_default (pbag, "ry", LengthDir::Vertical)?);
+
+        self.rx.set (property_bag::length_or_default (pbag, "rx", LengthDir::Horizontal)
+                     .and_then (|l| l.check_nonnegative ()
+                                .map_err (|e| NodeError::attribute_error ("rx", e)))?);
+
+        self.ry.set (property_bag::length_or_default (pbag, "ry", LengthDir::Vertical)
+                     .and_then (|l| l.check_nonnegative ()
+                                .map_err (|e| NodeError::attribute_error ("ry", e)))?);
 
         Ok (())
     }


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