[test] add cases for issues #690 #875 #876

This commit is contained in:
Barend Gehrels 2021-07-28 15:41:13 +02:00
parent 135b9264fd
commit 1030bd0d70
5 changed files with 79 additions and 46 deletions

View File

@ -15,22 +15,38 @@
#include <boost/geometry/algorithms/is_valid.hpp> #include <boost/geometry/algorithms/is_valid.hpp>
template<typename Geometry>
inline bool input_is_valid(std::string const& case_id, std::string const& subcase,
Geometry const& geometry)
{
std::string message;
bool const result = bg::is_valid(geometry, message);
if (! result)
{
std::cout << "WARNING: " << case_id << " Input [" << subcase
<< "] is not considered as valid ("
<< message << ") this can cause that output is invalid: "
<< case_id << std::endl;
}
return result;
}
template<typename Geometry, typename G1, typename G2> template<typename Geometry, typename G1, typename G2>
inline bool is_output_valid(Geometry const& geometry, inline bool is_output_valid(Geometry const& geometry,
std::string const& case_id, std::string const& case_id,
G1 const& g1, G2 const& g2, G1 const& g1, G2 const& g2,
bool ignore_validity_on_invalid_input,
std::string& message) std::string& message)
{ {
bool const result = bg::is_valid(geometry, message); bool result = bg::is_valid(geometry, message);
if (! result) if (! result && ignore_validity_on_invalid_input)
{ {
// Check if input was valid. If not, do not report output validity if (! input_is_valid(case_id, "a", g1)
if (! bg::is_valid(g1) || ! bg::is_valid(g2)) || ! input_is_valid(case_id, "b", g2))
{ {
std::cout << "WARNING: Input is not considered as valid; " // Because input is invalid, output validity is ignored
<< "this can cause that output is invalid: " << case_id result = true;
<< std::endl;
return true;
} }
} }
return result; return result;
@ -48,9 +64,11 @@ struct check_validity
bool apply(Geometry const& geometry, bool apply(Geometry const& geometry,
std::string const& case_id, std::string const& case_id,
G1 const& g1, G2 const& g2, G1 const& g1, G2 const& g2,
std::string& message) std::string& message,
bool ignore_validity_on_invalid_input = true)
{ {
return is_output_valid(geometry, case_id, g1, g2, message); return is_output_valid(geometry, case_id, g1, g2,
ignore_validity_on_invalid_input, message);
} }
}; };
@ -63,12 +81,14 @@ struct check_validity<Geometry, void>
bool apply(Geometry const& geometry, bool apply(Geometry const& geometry,
std::string const& case_id, std::string const& case_id,
G1 const& g1, G2 const& g2, G1 const& g1, G2 const& g2,
std::string& message) std::string& message,
bool ignore_validity_on_invalid_input = true)
{ {
typedef typename boost::range_value<Geometry>::type single_type; typedef typename boost::range_value<Geometry>::type single_type;
for (single_type const& element : geometry) for (single_type const& element : geometry)
{ {
if (! is_output_valid(element, case_id, g1, g2, message)) if (! is_output_valid(element, case_id, g1, g2,
ignore_validity_on_invalid_input, message))
{ {
return false; return false;
} }

View File

@ -1041,6 +1041,12 @@ static std::string issue_566_b[2] =
"POLYGON((0 0,0.148086 -7.06952,10.1459 -6.86009,9.99781 0.209424,0 0))" "POLYGON((0 0,0.148086 -7.06952,10.1459 -6.86009,9.99781 0.209424,0 0))"
}; };
static std::string issue_690[2] =
{
"POLYGON((667.934919263624237828481 -491.49318253425167313253,963.147330411699954311189 -168.898750642006632460834,972.814262587873145093909 -165.027657854956288474568,981.868038427448027505307 -170.171982894396819574467,983.490980059854678074771 -180.457944080522594276772,980.852669588300045688811 -185.101249357993367539166,290.852669588299988845392 -939.101249357993424382585,281.185737412126854906091 -942.972342145043739947141,272.131961572551972494693 -937.828017105603180425533,270.50901994014526508181 -927.542055919477434144937,273.147330411700011154608 -922.898750642006575617415,652.663832735933624462632 -508.180717667409339810547,658.329748792524242162472 -512.69913494618185723084,650.188373585171007107419 -506.206604869410682567832,650.188373585171007107419 -495.793395130589317432168,658.329748792524242162472 -489.30086505381814276916,667.934919263624237828481 -491.49318253425167313253))",
"POLYGON((925 686,920.481877622304750730109 676.618022210383628589625,910.329748792524242162472 674.30086505381814276916,902.188373585171007107419 680.793395130589260588749,902.188373585171007107419 691.206604869410739411251,910.329748792524242162472 697.69913494618185723084,920.481877622304750730109 695.381977789616371410375,925 686))"
};
static std::string issue_838[2] = static std::string issue_838[2] =
{ {
"POLYGON((27162.5232832765 -40045.435290614478,27162.764636849268 -40045.321663646188,27164.74034168441 -40044.391828870466,27164.854765308635 -40044.634874609801,27164.613411735867 -40044.748501578091,27162.637706900725 -40045.678336353812,27162.5232832765 -40045.435290614478))", "POLYGON((27162.5232832765 -40045.435290614478,27162.764636849268 -40045.321663646188,27164.74034168441 -40044.391828870466,27164.854765308635 -40044.634874609801,27164.613411735867 -40044.748501578091,27162.637706900725 -40045.678336353812,27162.5232832765 -40045.435290614478))",
@ -1053,6 +1059,24 @@ static std::string issue_861[2] =
"POLYGON((0.999994299999858893279736093973 0.000000000000000000000000000000 , 0.239056281157559169514570385218 0.000000000000000000000000000000 , 0.073239184141848157061360780062 0.213576637616646664019626200570 , 0.999994299999858893279736093973 0.000000000000000000000000000000))" "POLYGON((0.999994299999858893279736093973 0.000000000000000000000000000000 , 0.239056281157559169514570385218 0.000000000000000000000000000000 , 0.073239184141848157061360780062 0.213576637616646664019626200570 , 0.999994299999858893279736093973 0.000000000000000000000000000000))"
}; };
static std::string issue_875[2] =
{
"POLYGON((-46.499997761818364 -23.318506263117456,-46.499999998470159 26.305250946791375,-5.3405104310993323 15.276598956337693,37.500000001521741 -9.4573812741570009,37.500000001521741 -29.970448623772313,-38.166710648232517 -29.970440761860232,-46.094160894726727 -23.318520183850637,-46.499997761818364 -23.318506263117456))",
"POLYGON((-67.554314795325794 -23.318900735763236,-62.596713294359084 -17.33359695046795,-60.775620215083222 -15.852879652420938,-58.530163386780792 -15.186307709861694,-56.202193256444019 -15.435360658555282,-54.146122173314907 -16.562122444733632,-46.093707539928616 -23.318900593694593,-67.554314795325794 -23.318900735763236))"
};
static std::string issue_876a[2] =
{
"POLYGON((-12.348592836283077 -24.307738740001128,-41.849629816470362 0.44657841289972566,-43.93192354390343 1.5953436102420255,-46.29667314132071 1.8752581961977057,-46.50000184857911 1.8191141367510681,-46.499999998470003 33.093636483932755,37.500000001521677 33.093636483932414,37.500000001521677 -33.09363648327178,-1.8779562757967945 -33.093638112618237,-12.348592836283077 -24.307738740001128))",
"POLYGON((-24.958697324691109 -13.726596811192508,-23.487544907371284 -15.559526963320764,-22.825279893545986 -17.819579221226945,-23.07272612812282 -20.162681116069621,-24.165778212709604 -22.183251915571645,-89.244978527106397 -22.179296124972666,-78.129783911175977 -8.7599622312850443,-30.874278746584466 -8.7628346218826891,-24.958697324691109 -13.726596811192508))"
};
static std::string issue_876b[2] =
{
"POLYGON((-24.0482387183879496 -37.4313973992433375,-33.3495047556582449 -29.626708497888103,-36.5200226063477373 -27.5648148400831587,-39.4272653484940747 -26.8296944564690421,-41.9200722819054548 -27.2887150170597579,-43.732554394428881 -28.7766577741327865,-46.4999999984738537 -32.7358335543285648,-46.4999999984700025 37.4313974000880307,37.5000000015215846 37.4313974000876897,37.5000000015215846 -37.4313973992433375,-24.0482387183879496 -37.4313973992433375))",
"POLYGON((-71.6230763305201634 -132.587678014412745,-106.959839171856814 -102.936613347248112,-40.4477408440520776 -23.6705812141075285,-5.11097800271543878 -53.3216458812721612,-71.6230763305201634 -132.587678014412745))"
};
static std::string ggl_list_20120229_volker[3] = static std::string ggl_list_20120229_volker[3] =
{ {
"POLYGON((1716 1554,2076 2250,2436 2352,2796 1248,3156 2484,3516 2688,3516 2688,3156 2484,2796 1248,2436 2352,2076 2250, 1716 1554))", "POLYGON((1716 1554,2076 2250,2436 2352,2796 1248,3156 2484,3516 2688,3516 2688,3156 2484,2796 1248,2436 2352,2076 2250, 1716 1554))",

View File

@ -570,6 +570,12 @@ void test_all()
settings); settings);
} }
TEST_DIFFERENCE(issue_875, 1, 3468.77515, 1, 105.425816, 2);
#if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
TEST_DIFFERENCE(issue_876a, 1, 4728.89916, 1, 786.29563, 2);
#endif
TEST_DIFFERENCE(issue_876b, 1, 6114.18234, 1, 4754.29449, count_set(1, 2));
TEST_DIFFERENCE(mysql_21977775, 2, 160.856568913, 2, 92.3565689126, 4); TEST_DIFFERENCE(mysql_21977775, 2, 160.856568913, 2, 92.3565689126, 4);
TEST_DIFFERENCE(mysql_21965285, 1, 92.0, 1, 14.0, 1); TEST_DIFFERENCE(mysql_21965285, 1, 92.0, 1, 14.0, 1);
TEST_DIFFERENCE(mysql_23023665_1, 1, 92.0, 1, 142.5, 2); TEST_DIFFERENCE(mysql_23023665_1, 1, 92.0, 1, 142.5, 2);
@ -627,7 +633,7 @@ int test_main(int, char* [])
// Not yet fully tested for float and long double. // Not yet fully tested for float and long double.
// The difference algorithm can generate (additional) slivers // The difference algorithm can generate (additional) slivers
// Many of the failures are self-intersection points. // Many of the failures are self-intersection points.
BoostGeometryWriteExpectedFailures(12, 10, 17, 12); BoostGeometryWriteExpectedFailures(19, 10, 17, 12);
#endif #endif
return 0; return 0;

View File

@ -51,30 +51,10 @@
struct ut_settings : public ut_base_settings struct ut_settings : public ut_base_settings
{ {
ut_settings() double percentage = 0.001;
: percentage(0.001) bool ignore_validity_on_invalid_input = true;
{}
double percentage;
}; };
#if defined(BOOST_GEOMETRY_TEST_CHECK_VALID_INPUT)
template <typename Geometry>
inline void check_input_validity(std::string const& caseid, int case_index,
Geometry const& geometry)
{
std::string message;
if (!bg::is_valid(geometry, message))
{
std::cout << caseid << " Input ["
<< case_index << "] not valid" << std::endl
<< " (" << message << ")" << std::endl;
}
}
#endif
template <typename Range> template <typename Range>
inline std::size_t num_points(Range const& rng, bool add_for_open = false) inline std::size_t num_points(Range const& rng, bool add_for_open = false)
{ {
@ -100,15 +80,6 @@ void test_union(std::string const& caseid, G1 const& g1, G2 const& g2,
typedef typename setop_output_type<OutputType>::type result_type; typedef typename setop_output_type<OutputType>::type result_type;
result_type clip; result_type clip;
#if defined(BOOST_GEOMETRY_DEBUG_ROBUSTNESS)
std::cout << "*** UNION " << caseid << std::endl;
#endif
#if defined(BOOST_GEOMETRY_TEST_CHECK_VALID_INPUT)
check_input_validity(caseid, 0, g1);
check_input_validity(caseid, 1, g2);
#endif
// Check normal behaviour // Check normal behaviour
bg::union_(g1, g2, clip); bg::union_(g1, g2, clip);
@ -128,7 +99,8 @@ void test_union(std::string const& caseid, G1 const& g1, G2 const& g2,
if (settings.test_validity()) if (settings.test_validity())
{ {
std::string message; std::string message;
bool const valid = check_validity<result_type>::apply(clip, caseid, g1, g2, message); bool const valid = check_validity<result_type>::apply(clip, caseid,
g1, g2, message, settings.ignore_validity_on_invalid_input);
BOOST_CHECK_MESSAGE(valid, BOOST_CHECK_MESSAGE(valid,
"union: " << caseid << " not valid: " << message "union: " << caseid << " not valid: " << message
<< " type: " << (type_for_assert_message<G1, G2>())); << " type: " << (type_for_assert_message<G1, G2>()));

View File

@ -430,6 +430,17 @@ void test_areal()
TEST_UNION_REV(issue_566_a, 1, 0, -1, 214.3728); TEST_UNION_REV(issue_566_a, 1, 0, -1, 214.3728);
TEST_UNION_REV(issue_566_b, 1, 0, -1, 214.3728); TEST_UNION_REV(issue_566_b, 1, 0, -1, 214.3728);
#if ! defined(BOOST_GEOMETRY_USE_RESCALING) || defined(BOOST_GEOMETRY_TEST_FAILURES)
{
// With rescaling, the input (was already an output of a previous step)
// is somehow considered as invalid. Output is also invalid.
// Without rescaling, the same input is considered as valid
ut_settings settings;
settings.ignore_validity_on_invalid_input = false;
TEST_UNION_WITH(issue_690, 2, 0, -1, 25492.0505);
}
#endif
TEST_UNION(issue_838, 1, 0, -1, expectation_limits(1.3333, 1.33785)); TEST_UNION(issue_838, 1, 0, -1, expectation_limits(1.3333, 1.33785));
TEST_UNION_REV(issue_838, 1, 0, -1, expectation_limits(1.3333, 1.33785)); TEST_UNION_REV(issue_838, 1, 0, -1, expectation_limits(1.3333, 1.33785));
@ -597,7 +608,7 @@ int test_main(int, char* [])
#endif #endif
#if defined(BOOST_GEOMETRY_TEST_FAILURES) #if defined(BOOST_GEOMETRY_TEST_FAILURES)
BoostGeometryWriteExpectedFailures(3, 1, 2, 0); BoostGeometryWriteExpectedFailures(4, 1, 2, 0);
#endif #endif
return 0; return 0;