From 41f9c94e31cb0bd58e45b1262806d423284b98d7 Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Sun, 19 Jan 2014 22:33:58 +0100 Subject: [PATCH] [geometry] Fixed unit test for collinear intersections w.r.t new parameters --- .../detail/overlay/segment_ratio.hpp | 10 ++++ test/strategies/Jamfile.v2 | 1 + test/strategies/segment_intersection.cpp | 29 ++++++---- .../segment_intersection_collinear.cpp | 55 ++++++++++++------- 4 files changed, 63 insertions(+), 32 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/overlay/segment_ratio.hpp b/include/boost/geometry/algorithms/detail/overlay/segment_ratio.hpp index d881e0d11..e2b72182b 100644 --- a/include/boost/geometry/algorithms/detail/overlay/segment_ratio.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/segment_ratio.hpp @@ -127,6 +127,16 @@ public : return result; } +#if defined(BOOST_GEOMETRY_DEFINE_STREAM_OPERATOR_SEGMENT_RATIO) + friend std::ostream& operator<<(std::ostream &os, segment_ratio const& ratio) + { + os << ratio.m_numerator << "/" << ratio.m_denominator; + return os; + } +#endif + + + private : Type m_numerator; Type m_denominator; diff --git a/test/strategies/Jamfile.v2 b/test/strategies/Jamfile.v2 index 889ce66a9..9475f6a5d 100644 --- a/test/strategies/Jamfile.v2 +++ b/test/strategies/Jamfile.v2 @@ -15,6 +15,7 @@ test-suite boost-geometry-strategies [ run projected_point.cpp ] [ run pythagoras.cpp ] [ run spherical_side.cpp ] + [ run segment_intersection_collinear.cpp ] [ run transform_cs.cpp ] [ run transformer.cpp ] [ run within.cpp ] diff --git a/test/strategies/segment_intersection.cpp b/test/strategies/segment_intersection.cpp index c0191c18f..fdd66eeb9 100644 --- a/test/strategies/segment_intersection.cpp +++ b/test/strategies/segment_intersection.cpp @@ -103,16 +103,23 @@ static void test_segment_intersection(int caseno, segment_type s34(p3,p4); // Get the intersection point (or two points) - segment_intersection_points

is - = strategy::intersection::relate_cartesian_segments + typedef bg::detail::no_rescale_policy rescale_policy_type; + rescale_policy_type rescale_policy; + + typedef bg::segment_intersection_points + < + P, + typename bg::segment_ratio_type < - policies::relate::segments_intersection_points - < - segment_type, - segment_type, - segment_intersection_points

- > - >::apply(s12, s34); + P, + rescale_policy_type + >::type + > result_type; + + result_type is = strategy::intersection::relate_cartesian_segments + < + bg::policies::relate::segments_intersection_points + >::apply(s12, s34, rescale_policy); // Get the Dimension Extended 9 Intersection Matrix (de9im) for Segments // (this one is extended by GGL having opposite) @@ -127,8 +134,8 @@ static void test_segment_intersection(int caseno, // Get just a character for Left/Right/intersects/etc, purpose is more for debugging policies::relate::direction_type dir = strategy::intersection::relate_cartesian_segments < - policies::relate::segments_direction - >::apply(s12, s34); + policies::relate::segments_direction + >::apply(s12, s34, rescale_policy); int expected_count = 0; diff --git a/test/strategies/segment_intersection_collinear.cpp b/test/strategies/segment_intersection_collinear.cpp index 6f51f6311..a88d84dae 100644 --- a/test/strategies/segment_intersection_collinear.cpp +++ b/test/strategies/segment_intersection_collinear.cpp @@ -12,6 +12,7 @@ // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) +#define BOOST_GEOMETRY_DEFINE_STREAM_OPERATOR_SEGMENT_RATIO #include @@ -75,28 +76,32 @@ static void test_segment_intersection(std::string const& case_id, segment_type s12(p1,p2); segment_type s34(p3,p4); + typedef bg::detail::no_rescale_policy rescale_policy_type; + rescale_policy_type rescale_policy; + + typedef bg::segment_intersection_points + < + P, + typename bg::segment_ratio_type + < + P, + rescale_policy_type + >::type + > result_type; + // Get the intersection point (or two points) - bg::segment_intersection_points

is + result_type is = bg::strategy::intersection::relate_cartesian_segments < - bg::policies::relate::segments_intersection_points - < - segment_type, - segment_type, - bg::segment_intersection_points

- > - >::apply(s12, s34, p1, p2, p3, p4); + bg::policies::relate::segments_intersection_points + >::apply(s12, s34, rescale_policy, p1, p2, p3, p4); // Get just a character for Left/Right/intersects/etc, purpose is more for debugging bg::policies::relate::direction_type dir = bg::strategy::intersection::relate_cartesian_segments < bg::policies::relate::segments_direction - < - segment_type, - segment_type - > - >::apply(s12, s34, p1, p2, p3, p4); + >::apply(s12, s34, rescale_policy, p1, p2, p3, p4); std::size_t expected_count = check(is, 0, expected_x1, expected_y1) @@ -132,17 +137,25 @@ static void test_segment_ratio(std::string const& case_id, segment_type s12(p1, p2); segment_type s34(p3, p4); + typedef bg::detail::no_rescale_policy rescale_policy_type; + rescale_policy_type rescale_policy; + + typedef bg::segment_intersection_points + < + P, + typename bg::segment_ratio_type + < + P, + rescale_policy_type + >::type + > result_type; + // Get the intersection point (or two points) - bg::segment_intersection_points

is + result_type is = bg::strategy::intersection::relate_cartesian_segments < - bg::policies::relate::segments_intersection_points - < - segment_type, - segment_type, - bg::segment_intersection_points

- > - >::apply(s12, s34, p1, p2, p3, p4); + bg::policies::relate::segments_intersection_points + >::apply(s12, s34, rescale_policy, p1, p2, p3, p4); BOOST_CHECK_EQUAL(is.count, 2u); BOOST_CHECK_EQUAL(is.fractions[0].robust_ra, expected_a1);