diff --git a/include/boost/geometry/algorithms/intersection.hpp b/include/boost/geometry/algorithms/intersection.hpp index f429a54f5..2316d6ee9 100644 --- a/include/boost/geometry/algorithms/intersection.hpp +++ b/include/boost/geometry/algorithms/intersection.hpp @@ -233,8 +233,8 @@ struct intersection > }; -template -struct intersection, variant > +template +struct intersection, variant > { template struct visitor: static_visitor @@ -263,10 +263,10 @@ struct intersection, variant - static inline void + static inline bool apply( - const variant& geometry1, - const variant& geometry2, + const variant& geometry1, + const variant& geometry2, GeometryOut& geometry_out) { return apply_visitor(visitor(geometry_out), geometry1, geometry2); diff --git a/test/algorithms/test_intersection.hpp b/test/algorithms/test_intersection.hpp index 4050af8a6..82374cbd8 100644 --- a/test/algorithms/test_intersection.hpp +++ b/test/algorithms/test_intersection.hpp @@ -33,50 +33,24 @@ #include - -template -typename bg::default_area_result::type test_intersection(std::string const& caseid, - G1 const& g1, G2 const& g2, - std::size_t expected_count = 0, int expected_point_count = 0, - double expected_length_or_area = 0, - double percentage = 0.0001, - bool debug = false) +template +typename bg::default_area_result::type +check_result( + std::vector const& intersection_output, + std::string const& caseid, + std::size_t expected_count = 0, int expected_point_count = 0, + double expected_length_or_area = 0, + double percentage = 0.0001, + bool debug = false) { bool const is_line = bg::geometry_id::type::value == 2; - if (debug) - { - std::cout << std::endl << "case " << caseid << std::endl; - } - - typedef typename bg::coordinate_type::type coordinate_type; typedef typename bg::point_type::type point_type; - if (! debug) - { - // Check _inserter behaviour with stratey - typedef bg::strategy_intersection - < - typename bg::cs_tag::type, - G1, - G2, - point_type, - typename bg::rescale_policy_type::type, - CalculationType - > strategy; - std::vector clip; - bg::detail::intersection::intersection_insert(g1, g2, std::back_inserter(clip), strategy()); - } - - // Check normal behaviour - std::vector intersection_output; - bg::intersection(g1, g2, intersection_output); - - typename bg::default_area_result::type length_or_area = 0; int n = 0; - for (typename std::vector::iterator it = intersection_output.begin(); + for (typename std::vector::const_iterator it = intersection_output.begin(); it != intersection_output.end(); ++it) { @@ -96,7 +70,6 @@ typename bg::default_area_result::type test_intersection(std::string const& } } - #if ! defined(BOOST_GEOMETRY_NO_BOOST_TEST) #if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS) if (expected_point_count > 0) @@ -124,7 +97,6 @@ typename bg::default_area_result::type test_intersection(std::string const& BOOST_CHECK_CLOSE(detected_length_or_area, expected_length_or_area, percentage); #endif - #if defined(TEST_WITH_SVG) { bool const ccw = @@ -169,6 +141,70 @@ typename bg::default_area_result::type test_intersection(std::string const& } #endif + return length_or_area; +} + + +template +typename bg::default_area_result::type test_intersection(std::string const& caseid, + G1 const& g1, G2 const& g2, + std::size_t expected_count = 0, int expected_point_count = 0, + double expected_length_or_area = 0, + double percentage = 0.0001, + bool debug = false) +{ + if (debug) + { + std::cout << std::endl << "case " << caseid << std::endl; + } + + typedef typename bg::coordinate_type::type coordinate_type; + typedef typename bg::point_type::type point_type; + + if (! debug) + { + // Check _inserter behaviour with stratey + typedef bg::strategy_intersection + < + typename bg::cs_tag::type, + G1, + G2, + point_type, + typename bg::rescale_policy_type::type, + CalculationType + > strategy; + std::vector clip; + bg::detail::intersection::intersection_insert(g1, g2, std::back_inserter(clip), strategy()); + } + + typename bg::default_area_result::type length_or_area = 0; + + // Check normal behaviour + std::vector intersection_output; + bg::intersection(g1, g2, intersection_output); + + check_result(intersection_output, caseid, expected_count, expected_point_count, + expected_length_or_area, percentage, debug); + + // Check variant behaviour + intersection_output.clear(); + bg::intersection(boost::variant(g1), g2, intersection_output); + + check_result(intersection_output, caseid, expected_count, expected_point_count, + expected_length_or_area, percentage, debug); + + intersection_output.clear(); + bg::intersection(g1, boost::variant(g2), intersection_output); + + check_result(intersection_output, caseid, expected_count, expected_point_count, + expected_length_or_area, percentage, debug); + + intersection_output.clear(); + bg::intersection(boost::variant(g1), boost::variant(g2), intersection_output); + + check_result(intersection_output, caseid, expected_count, expected_point_count, + expected_length_or_area, percentage, debug); + if (debug) { std::cout << "end case " << caseid << std::endl;