[librsvg/rustification] path_parser.rs: Split part of number() into a helper nonnegative_number() method



commit b8a5bffd37c1b6b863e68f48817691a9d2516e83
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Nov 8 14:35:15 2016 -0600

    path_parser.rs: Split part of number() into a helper nonnegative_number() method
    
    We will need nonnegative numbers to match for the radiuses of elliptical arcs.

 rust/src/path_parser.rs |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)
---
diff --git a/rust/src/path_parser.rs b/rust/src/path_parser.rs
index cb96d83..53d69d7 100644
--- a/rust/src/path_parser.rs
+++ b/rust/src/path_parser.rs
@@ -184,16 +184,10 @@ impl<'external> PathParser<'external> {
 
     fn number (&mut self) -> Option <f64> {
         let mut has_sign: bool;
-        let mut value: f64;
         let mut sign: f64;
-        let mut exponent_sign: f64;
-        let mut exponent: f64;
 
         has_sign = false;
         sign = 1.0;
-        value = 0.0;
-        exponent_sign = 1.0;
-        exponent = 0.0;
 
         if self.match_char ('+') {
             sign = 1.0;
@@ -203,6 +197,26 @@ impl<'external> PathParser<'external> {
             has_sign = true;
         }
 
+        if let Some (num) = self.nonnegative_number () {
+            return Some (num * sign);
+        } else {
+            if has_sign {
+                self.error ("Expected number after sign");
+            }
+
+            None
+        }
+    }
+
+    fn nonnegative_number (&mut self) -> Option<f64> {
+        let mut value: f64;
+        let mut exponent_sign: f64;
+        let mut exponent: f64;
+
+        value = 0.0;
+        exponent_sign = 1.0;
+        exponent = 0.0;
+
         let mut c: char = ' ';
 
         if self.lookahead_is_digit (&mut c) || self.lookahead_is ('.') {
@@ -254,12 +268,8 @@ impl<'external> PathParser<'external> {
                 }
             }
 
-            Some (value * sign * 10.0f64.powf (exponent * exponent_sign))
+            Some (value * 10.0f64.powf (exponent * exponent_sign))
         } else {
-            if has_sign {
-                self.error ("Expected number after sign");
-            }
-
             None
         }
     }


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