[librsvg: 1/4] marker: move bisection tests to angle.rs



commit 5bcc328b4999fe49cc8f51101dfac53a64174da0
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Dec 15 14:16:28 2018 +0100

    marker: move bisection tests to angle.rs
    
    I forgot to move them in the recent refactoring.

 rsvg_internals/src/angle.rs  | 56 ++++++++++++++++++++++++++++++++++++
 rsvg_internals/src/marker.rs | 67 --------------------------------------------
 2 files changed, 56 insertions(+), 67 deletions(-)
---
diff --git a/rsvg_internals/src/angle.rs b/rsvg_internals/src/angle.rs
index 7e997c5e..b020181a 100644
--- a/rsvg_internals/src/angle.rs
+++ b/rsvg_internals/src/angle.rs
@@ -102,6 +102,8 @@ impl Parse for Angle {
 #[cfg(test)]
 mod tests {
     use super::*;
+    use float_cmp::ApproxEq;
+    use std::f64;
 
     #[test]
     fn parses_angle() {
@@ -121,4 +123,58 @@ mod tests {
         assert!(Angle::parse_str("foo", ()).is_err());
         assert!(Angle::parse_str("300foo", ()).is_err());
     }
+
+    fn test_bisection_angle(
+        expected: f64,
+        incoming_vx: f64,
+        incoming_vy: f64,
+        outgoing_vx: f64,
+        outgoing_vy: f64,
+    ) {
+        let i = Angle::from_vector(incoming_vx, incoming_vy);
+        let o = Angle::from_vector(outgoing_vx, outgoing_vy);
+        let bisected = i.bisect(o);
+        assert!(expected.approx_eq(&bisected.radians(), 2.0 * PI * f64::EPSILON, 1));
+    }
+
+    #[test]
+    fn bisection_angle_is_correct_from_incoming_counterclockwise_to_outgoing() {
+        // 1st quadrant
+        test_bisection_angle(FRAC_PI_4, 1.0, 0.0, 0.0, 1.0);
+
+        // 2nd quadrant
+        test_bisection_angle(FRAC_PI_2 + FRAC_PI_4, 0.0, 1.0, -1.0, 0.0);
+
+        // 3rd quadrant
+        test_bisection_angle(PI + FRAC_PI_4, -1.0, 0.0, 0.0, -1.0);
+
+        // 4th quadrant
+        test_bisection_angle(PI + FRAC_PI_2 + FRAC_PI_4, 0.0, -1.0, 1.0, 0.0);
+    }
+
+    #[test]
+    fn bisection_angle_is_correct_from_incoming_clockwise_to_outgoing() {
+        // 1st quadrant
+        test_bisection_angle(FRAC_PI_4, 0.0, 1.0, 1.0, 0.0);
+
+        // 2nd quadrant
+        test_bisection_angle(FRAC_PI_2 + FRAC_PI_4, -1.0, 0.0, 0.0, 1.0);
+
+        // 3rd quadrant
+        test_bisection_angle(PI + FRAC_PI_4, 0.0, -1.0, -1.0, 0.0);
+
+        // 4th quadrant
+        test_bisection_angle(PI + FRAC_PI_2 + FRAC_PI_4, 1.0, 0.0, 0.0, -1.0);
+    }
+
+    #[test]
+    fn bisection_angle_is_correct_for_more_than_quarter_turn_angle() {
+        test_bisection_angle(0.0, 0.1, -1.0, 0.1, 1.0);
+
+        test_bisection_angle(FRAC_PI_2, 1.0, 0.1, -1.0, 0.1);
+
+        test_bisection_angle(PI, -0.1, 1.0, -0.1, -1.0);
+
+        test_bisection_angle(PI + FRAC_PI_2, -1.0, -0.1, 1.0, -0.1);
+    }
 }
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index c9ff7c61..ac54ce1e 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -893,75 +893,8 @@ mod parser_tests {
 #[cfg(test)]
 mod directionality_tests {
     use super::*;
-    use float_cmp::ApproxEq;
     use std::f64;
 
-    fn test_bisection_angle(
-        expected: f64,
-        incoming_vx: f64,
-        incoming_vy: f64,
-        outgoing_vx: f64,
-        outgoing_vy: f64,
-    ) {
-        let i = Angle::from_vector(incoming_vx, incoming_vy);
-        let o = Angle::from_vector(outgoing_vx, outgoing_vy);
-        let bisected = i.bisect(o);
-        assert!(expected.approx_eq(&bisected.radians(), 2.0 * PI * f64::EPSILON, 1));
-    }
-
-    #[test]
-    fn bisection_angle_is_correct_from_incoming_counterclockwise_to_outgoing() {
-        // 1st quadrant
-        test_bisection_angle(FRAC_PI_4, 1.0, 0.0, 0.0, 1.0);
-
-        // 2nd quadrant
-        test_bisection_angle(FRAC_PI_2 + FRAC_PI_4, 0.0, 1.0, -1.0, 0.0);
-
-        // 3rd quadrant
-        test_bisection_angle(PI + FRAC_PI_4, -1.0, 0.0, 0.0, -1.0);
-
-        // 4th quadrant
-        test_bisection_angle(PI + FRAC_PI_2 + FRAC_PI_4, 0.0, -1.0, 1.0, 0.0);
-    }
-
-    #[test]
-    fn bisection_angle_is_correct_from_incoming_clockwise_to_outgoing() {
-        // 1st quadrant
-        test_bisection_angle(FRAC_PI_4, 0.0, 1.0, 1.0, 0.0);
-
-        // 2nd quadrant
-        test_bisection_angle(FRAC_PI_2 + FRAC_PI_4, -1.0, 0.0, 0.0, 1.0);
-
-        // 3rd quadrant
-        test_bisection_angle(PI + FRAC_PI_4, 0.0, -1.0, -1.0, 0.0);
-
-        // 4th quadrant
-        test_bisection_angle(PI + FRAC_PI_2 + FRAC_PI_4, 1.0, 0.0, 0.0, -1.0);
-    }
-
-    #[test]
-    fn bisection_angle_is_correct_for_more_than_quarter_turn_angle() {
-        test_bisection_angle(0.0, 0.1, -1.0, 0.1, 1.0);
-
-        test_bisection_angle(FRAC_PI_2, 1.0, 0.1, -1.0, 0.1);
-
-        test_bisection_angle(PI, -0.1, 1.0, -0.1, -1.0);
-
-        test_bisection_angle(PI + FRAC_PI_2, -1.0, -0.1, 1.0, -0.1);
-    }
-
-    fn degenerate(x: f64, y: f64) -> Segment {
-        super::make_degenerate(x, y)
-    }
-
-    fn line(x1: f64, y1: f64, x2: f64, y2: f64) -> Segment {
-        super::make_line(x1, y1, x2, y2)
-    }
-
-    fn curve(x1: f64, y1: f64, x2: f64, y2: f64, x3: f64, y3: f64, x4: f64, y4: f64) -> Segment {
-        super::make_curve(x1, y1, x2, y2, x3, y3, x4, y4)
-    }
-
     fn test_path_builder_to_segments(builder: &PathBuilder, expected_segments: Vec<Segment>) {
         let segments = path_builder_to_segments(builder);
         assert_eq!(expected_segments, segments);


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