diff --git a/test/algorithms/set_operations/union/test_union.hpp b/test/algorithms/set_operations/union/test_union.hpp index 4ec8d758c..9b32292c5 100644 --- a/test/algorithms/set_operations/union/test_union.hpp +++ b/test/algorithms/set_operations/union/test_union.hpp @@ -21,6 +21,7 @@ #include "../setop_output_type.hpp" #include +#include #include #include @@ -70,6 +71,44 @@ inline void check_input_validity(std::string const& caseid, int case_index, } #endif +template +< + typename Geometry, + typename Tag = typename bg::tag::type +> +struct check_validity +{ + static inline + bool apply(Geometry const& geometry, std::string& message) + { + if (! bg::is_valid(geometry, message)) + { + std::cout << bg::wkt(geometry) << std::endl; + } + return bg::is_valid(geometry, message); + } +}; + +// Specialization for vector of (e.g. rings) +template +struct check_validity +{ + static inline + bool apply(Geometry const& geometry, std::string& message) + { + typedef typename boost::range_value::type single_type; + BOOST_FOREACH(single_type const& element, geometry) + { + if (! bg::is_valid(element, message)) + { + return false; + } + } + return true; + } +}; + + template inline std::size_t num_points(Range const& rng, bool add_for_open = false) { @@ -121,6 +160,16 @@ void test_union(std::string const& caseid, G1 const& g1, G2 const& g2, } #endif + if (settings.test_validity) + { + std::string message; + bool const valid = check_validity::apply(clip, message); + BOOST_CHECK_MESSAGE(valid, + "union: " << caseid << " not valid: " << message + << " type: " << (type_for_assert_message())); + } + + typename bg::default_area_result::type area = 0; std::size_t n = 0; std::size_t holes = 0; @@ -130,17 +179,6 @@ void test_union(std::string const& caseid, G1 const& g1, G2 const& g2, area += bg::area(*it); holes += bg::num_interior_rings(*it); n += bg::num_points(*it, true); - - if (settings.test_validity) - { - // Check validity (currently on separate clips only) - // std::cout << bg::dsv(*it) << std::endl; - std::string message; - bool const valid = bg::is_valid(*it, message); - BOOST_CHECK_MESSAGE(valid, - "union: " << caseid << " not valid: " << message - << " type: " << (type_for_assert_message())); - } }