[librsvg/rustification] path_parser.rs: Maintain reflection points for quadratic curves as well



commit c4ed9b2f523e5b79e6be26ce902809a2afd3133d
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Nov 8 13:28:03 2016 -0600

    path_parser.rs: Maintain reflection points for quadratic curves as well
    
    Per the spec, reflection points get reset when the previous command
    is *not* the same as the current smooth curve command.

 rust/src/path_parser.rs |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/rust/src/path_parser.rs b/rust/src/path_parser.rs
index 7e52022..1e27d80 100644
--- a/rust/src/path_parser.rs
+++ b/rust/src/path_parser.rs
@@ -24,7 +24,13 @@ pub struct PathParser<'external> {
      * the new control point for smooth cubic curve commands.
      */
     cubic_reflection_x: f64,
-    cubic_reflection_y: f64
+    cubic_reflection_y: f64,
+
+    /* Last control point from previous quadratic curve command, used to reflect
+     * the new control point for smooth quadratic curve commands.
+     */
+    quadratic_reflection_x: f64,
+    quadratic_reflection_y: f64,
 }
 
 /* This is a recursive descent parser for path data in SVG files,
@@ -69,7 +75,10 @@ impl<'external> PathParser<'external> {
             current_y: 0.0,
 
             cubic_reflection_x: 0.0,
-            cubic_reflection_y: 0.0
+            cubic_reflection_y: 0.0,
+
+            quadratic_reflection_x: 0.0,
+            quadratic_reflection_y: 0.0
         }
     }
 
@@ -264,15 +273,23 @@ impl<'external> PathParser<'external> {
     fn set_current_point (&mut self, x: f64, y: f64) {
         self.current_x = x;
         self.current_y = y;
+
         self.cubic_reflection_x = self.current_x;
         self.cubic_reflection_y = self.current_y;
+
+        self.quadratic_reflection_x = self.current_x;
+        self.quadratic_reflection_y = self.current_y;
     }
 
     fn set_cubic_reflection_and_current_point (&mut self, x3: f64, y3: f64, x4: f64, y4: f64) {
         self.cubic_reflection_x = x3;
         self.cubic_reflection_y = y3;
+
         self.current_x = x4;
         self.current_y = y4;
+
+        self.quadratic_reflection_x = self.current_x;
+        self.quadratic_reflection_y = self.current_y;
     }
 
     fn emit_move_to (&mut self, x: f64, y: f64) {


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