[librsvg] parse_transform.lalrpop: Parse the "skewX" and "skewY" transforms



commit 426c583568beac561bd8d6665f9b069d844f84b7
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Mar 22 08:56:16 2017 -0600

    parse_transform.lalrpop: Parse the "skewX" and "skewY" transforms

 rust/src/parse_transform.lalrpop |   18 ++++++++++++++++++
 rust/src/parsers.rs              |   24 ++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/rust/src/parse_transform.lalrpop b/rust/src/parse_transform.lalrpop
index 735fc69..9da4537 100644
--- a/rust/src/parse_transform.lalrpop
+++ b/rust/src/parse_transform.lalrpop
@@ -52,6 +52,24 @@ pub Rotate: cairo::Matrix = {
     }
 };
 
+pub SkewX: cairo::Matrix = {
+    "skewX" "(" <angle: Num> ")" => {
+        let a = angle * PI / 180.0;
+        cairo::Matrix::new (1.0,      0.0,
+                            a.tan (), 1.0,
+                            0.0, 0.0)
+    }
+};
+
+pub SkewY: cairo::Matrix = {
+    "skewY" "(" <angle: Num> ")" => {
+        let a = angle * PI / 180.0;
+        cairo::Matrix::new (1.0,  a.tan (),
+                            0.0,  1.0,
+                            0.0, 0.0)
+    }
+};
+
 pub Num: f64 = <s:r"[+-]?([0-9]*\.[0-9]+|[0-9]+(\.[0-9]*)?)([Ee][+-]?[0-9]+)?"> =>
     f64::from_str (s).unwrap ();
 
diff --git a/rust/src/parsers.rs b/rust/src/parsers.rs
index 2ae58b8..09b47fd 100644
--- a/rust/src/parsers.rs
+++ b/rust/src/parsers.rs
@@ -348,4 +348,28 @@ mod parse_transform_tests {
         assert_eq! (parse_Rotate ("rotate (30,-1,-2)").unwrap (), make_rotation_matrix (30.0, -1.0, -2.0));
         assert_eq! (parse_Rotate ("rotate (30, -1, -2)").unwrap (), make_rotation_matrix (30.0, -1.0, -2.0));
     }
+
+    fn make_skew_x_matrix (angle_degrees: f64) -> cairo::Matrix {
+        let a = angle_degrees * PI / 180.0;
+        cairo::Matrix::new (1.0,      0.0,
+                            a.tan (), 1.0,
+                            0.0, 0.0)
+    }
+
+    fn make_skew_y_matrix (angle_degrees: f64) -> cairo::Matrix {
+        let mut m = make_skew_x_matrix (angle_degrees);
+        m.yx = m.xy;
+        m.xy = 0.0;
+        m
+    }
+
+    #[test]
+    fn parses_skew_x () {
+        assert_eq! (parse_SkewX ("skewX (30)").unwrap (), make_skew_x_matrix (30.0));
+    }
+
+    #[test]
+    fn parses_skew_y () {
+        assert_eq! (parse_SkewY ("skewY (30)").unwrap (), make_skew_y_matrix (30.0));
+    }
 }


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