From 9c18680f319e8962228d8992b3495b4012117905 Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 26 Jan 2022 13:48:23 +0100 Subject: [PATCH 1/2] [fix] for integer coordinates, segment intersection now rounds to nearest point --- .../algorithms/detail/overlay/overlay.hpp | 7 +-- include/boost/geometry/core/config.hpp | 4 +- .../strategies/cartesian/intersection.hpp | 13 ++-- include/boost/geometry/util/math.hpp | 35 +++++++++++ .../overlay/multi_overlay_cases.hpp | 7 +++ test/algorithms/overlay/overlay.cpp | 55 ++++++++-------- .../set_operations/difference/difference.cpp | 13 ++-- .../difference/difference_areal_linear.cpp | 4 +- .../difference/difference_multi.cpp | 27 ++++---- .../difference/difference_multi_spike.cpp | 16 ++--- test/util/Jamfile | 1 + test/util/math_divide.cpp | 62 +++++++++++++++++++ 12 files changed, 169 insertions(+), 75 deletions(-) create mode 100644 test/util/math_divide.cpp diff --git a/include/boost/geometry/algorithms/detail/overlay/overlay.hpp b/include/boost/geometry/algorithms/detail/overlay/overlay.hpp index 7d960987d..4e77ca97e 100644 --- a/include/boost/geometry/algorithms/detail/overlay/overlay.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/overlay.hpp @@ -369,12 +369,9 @@ std::cout << "traverse" << std::endl; // Add rings created during traversal { ring_identifier id(2, 0, -1); - for (typename boost::range_iterator::type - it = boost::begin(rings); - it != boost::end(rings); - ++it) + for (auto const& ring : rings) { - selected_ring_properties[id] = properties(*it, strategy); + selected_ring_properties[id] = properties(ring, strategy); selected_ring_properties[id].reversed = ReverseOut; id.multi_index++; } diff --git a/include/boost/geometry/core/config.hpp b/include/boost/geometry/core/config.hpp index 90677cfd3..c77619ebc 100644 --- a/include/boost/geometry/core/config.hpp +++ b/include/boost/geometry/core/config.hpp @@ -35,8 +35,8 @@ // Rescaling is turned on, unless NO_ROBUSTNESS is defined // In future versions of Boost.Geometry, it will be turned off by default -#if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS) -#define BOOST_GEOMETRY_USE_RESCALING +#if !defined(BOOST_GEOMETRY_NO_ROBUSTNESS) && !defined(BOOST_GEOMETRY_USE_RESCALING) + #define BOOST_GEOMETRY_USE_RESCALING #endif #endif // BOOST_GEOMETRY_CORE_CONFIG_HPP diff --git a/include/boost/geometry/strategies/cartesian/intersection.hpp b/include/boost/geometry/strategies/cartesian/intersection.hpp index dbfa08224..605163a36 100644 --- a/include/boost/geometry/strategies/cartesian/intersection.hpp +++ b/include/boost/geometry/strategies/cartesian/intersection.hpp @@ -170,9 +170,8 @@ struct cartesian_segments SegmentRatio const& ratio) const { // Calculate the intersection point based on segment_ratio - // Up to now, division was postponed. Here we divide using numerator/ - // denominator. In case of integer this results in an integer - // division. + // The division, postponed until here, is done now. In case of integer this + // results in an integer which rounds to the nearest integer. BOOST_GEOMETRY_ASSERT(ratio.denominator() != typename SegmentRatio::int_type(0)); typedef typename promote_integral::type calc_type; @@ -185,11 +184,11 @@ struct cartesian_segments calc_type const dy_calc = boost::numeric_cast(dy); set<0>(point, get<0, 0>(segment) - + boost::numeric_cast(numerator * dx_calc - / denominator)); + + boost::numeric_cast( + math::divide(numerator * dx_calc, denominator))); set<1>(point, get<0, 1>(segment) - + boost::numeric_cast(numerator * dy_calc - / denominator)); + + boost::numeric_cast( + math::divide(numerator * dy_calc, denominator))); } template diff --git a/include/boost/geometry/util/math.hpp b/include/boost/geometry/util/math.hpp index c39341a20..3acea4ee5 100644 --- a/include/boost/geometry/util/math.hpp +++ b/include/boost/geometry/util/math.hpp @@ -525,6 +525,30 @@ struct rounding_cast } }; +template ::value> +struct divide +{ + static inline T apply(T const& n, T const& d) + { + return n / d; + } +}; + +template +struct divide +{ + static inline T apply(T const& n, T const& d) + { + return n == 0 ? 0 + : n < 0 + ? (d < 0 ? (n + (-d + 1) / 2) / d + 1 + : (n + ( d + 1) / 2) / d - 1 ) + : (d < 0 ? (n - (-d + 1) / 2) / d - 1 + : (n - ( d + 1) / 2) / d + 1 ) + ; + } +}; + } // namespace detail #endif @@ -796,6 +820,17 @@ inline Result rounding_cast(T const& v) return detail::rounding_cast::apply(v); } +/* +\brief Short utility to divide. If the division is integer, it rounds the division + to the nearest value, without using floating point calculations +\ingroup utility +*/ +template +inline T divide(T const& n, T const& d) +{ + return detail::divide::apply(n, d); +} + /*! \brief Evaluate the sine and cosine function with the argument in degrees \note The results obey exactly the elementary properties of the trigonometric diff --git a/test/algorithms/overlay/multi_overlay_cases.hpp b/test/algorithms/overlay/multi_overlay_cases.hpp index 701c1f4e9..8c7ae2ee8 100644 --- a/test/algorithms/overlay/multi_overlay_cases.hpp +++ b/test/algorithms/overlay/multi_overlay_cases.hpp @@ -1561,6 +1561,13 @@ static std::string issue_888_53[2] = "MULTIPOLYGON(((0.659074 0.243756,0.649585 0.255543,0.651004 0.267233,0.699286 0.310525,0.701216 0.308798,0.659074 0.243756)),((0.65607 0.730838,0.614949 0.760619,0.558286 0.779383,0.569893 0.875763,0.926464 0.956953,0.711407 0.711132,0.702942 0.714146,0.699891 0.720104,0.697876 0.71595,0.65607 0.730838)),((0.6251 0.244006,0.638996 0.227311,0.643368 0.219514,0.606658 0.162855,0.590598 0.213071,0.6251 0.244006)),((0.338625 0.733712,0.323461 0.693095,0.220913 0.771732,0.287708 0.782026,0.338625 0.733712)),((0.315174 0.670899,0.28149 0.712736,0.315658 0.672196,0.315174 0.670899)),((0.625653 0.461363,0.623608 0.462931,0.62395 0.462979,0.625653 0.461363)),((0.794671 0.168431,0.730585 0.154935,0.713413 0.176264,0.756461 0.22946,0.794671 0.168431)),((0.597976 0.482587,0.619207 0.466306,0.621457 0.462628,0.611365 0.461203,0.597976 0.482587)),((0.679066 0.498397,0.646318 0.526268,0.676403 0.53804,0.682592 0.527448,0.679066 0.498397)),((0.402869 0.800065,0.401491 0.804374,0.540911 0.757512,0.402869 0.800065)),((0.402869 0.800065,0.406699 0.78809,0.398324 0.801466,0.402869 0.800065)),((0.719855 0.46368,0.757461 0.431674,0.746845 0.417494,0.719855 0.46368)),((0.719855 0.46368,0.696391 0.483651,0.701969 0.494288,0.719855 0.46368)),((0.746845 0.417494,0.77151 0.375285,0.749286 0.355358,0.736399 0.363101,0.750855 0.385413,0.725474 0.369665,0.721777 0.371886,0.701659 0.354888,0.691299 0.34846,0.665904 0.389973,0.666125 0.391796,0.698833 0.391926,0.669517 0.419742,0.670404 0.427047,0.716114 0.391995,0.727787 0.392041,0.746845 0.417494)),((0.708595 0.320188,0.709115 0.319338,0.706561 0.317049,0.708595 0.320188)),((0.708595 0.320188,0.692237 0.346927,0.701659 0.354888,0.725474 0.369665,0.736399 0.363101,0.708595 0.320188)),((0.473998 0.577658,0.465083 0.605533,0.471121 0.607993,0.530823 0.551344,0.52892 0.535542,0.473998 0.577658)),((0.473998 0.577658,0.487873 0.534273,0.527391 0.522848,0.524311 0.49727,0.509505 0.480347,0.503361 0.485845,0.506294 0.476676,0.501948 0.471709,0.484614 0.50262,0.430805 0.55077,0.4628 0.541521,0.434005 0.592872,0.447166 0.598234,0.473998 0.577658)),((0.509505 0.480347,0.515424 0.475051,0.507771 0.472056,0.506294 0.476676,0.509505 0.480347)),((0.502836 0.470125,0.507771 0.472056,0.515566 0.447682,0.515432 0.447663,0.502836 0.470125)),((0.502836 0.470125,0.499379 0.468772,0.501948 0.471709,0.502836 0.470125)),((0.502031 0.312271,0.526427 0.362556,0.518569 0.371997,0.535749 0.384573,0.533607 0.391271,0.511534 0.391183,0.515288 0.422347,0.497 0.445061,0.515432 0.447663,0.515759 0.44708,0.515566 0.447682,0.518387 0.44808,0.521031 0.470034,0.541862 0.451393,0.57156 0.455585,0.561152 0.434132,0.580186 0.417099,0.620502 0.446609,0.654849 0.391752,0.608717 0.391569,0.660475 0.345254,0.658385 0.328037,0.613594 0.300245,0.623065 0.288482,0.6106 0.27795,0.602098 0.293112,0.590314 0.2858,0.553002 0.330628,0.571143 0.273905,0.445637 0.196032,0.494788 0.297342,0.499477 0.291064,0.502031 0.312271),(0.537856 0.386115,0.535749 0.384573,0.536289 0.382885,0.537856 0.386115),(0.537856 0.386115,0.54201 0.389156,0.540339 0.391232,0.537856 0.386115)),((0.502031 0.312271,0.494788 0.297342,0.467142 0.334354,0.50832 0.364495,0.502031 0.312271)),((0.50832 0.364495,0.510405 0.381806,0.518569 0.371997,0.50832 0.364495)),((0.509635 0.623684,0.524665 0.629807,0.538821 0.617759,0.534711 0.583632,0.509635 0.623684)),((0.509635 0.623684,0.471121 0.607993,0.461323 0.617289,0.432133 0.708562,0.48428 0.664179,0.509635 0.623684)),((0.465083 0.605533,0.447166 0.598234,0.418801 0.619985,0.373678 0.700452,0.461323 0.617289,0.465083 0.605533)),((0.374931 0.830954,0.37797 0.839093,0.529874 0.788791,0.539477 0.772358,0.374931 0.830954)),((0.374931 0.830954,0.369376 0.816075,0.340592 0.843183,0.374931 0.830954)),((0.524311 0.49727,0.542793 0.518396,0.556414 0.514458,0.576592 0.498985,0.521942 0.477601,0.524311 0.49727)),((0.530823 0.551344,0.534711 0.583632,0.561889 0.540224,0.553113 0.530193,0.530823 0.551344)),((0.527391 0.522848,0.52892 0.535542,0.5462 0.522291,0.542793 0.518396,0.527391 0.522848)),((0.539477 0.772358,0.556701 0.766224,0.55437 0.746871,0.539477 0.772358)),((0.483053 0.462384,0.453094 0.450661,0.359867 0.562668,0.372228 0.567704,0.406154 0.557896,0.483053 0.462384)),((0.483053 0.462384,0.499379 0.468772,0.488199 0.455992,0.483053 0.462384)),((0.430805 0.55077,0.406154 0.557896,0.391829 0.575689,0.399476 0.578805,0.430805 0.55077)),((0.359867 0.562668,0.315812 0.54472,0.320962 0.582524,0.350431 0.574005,0.359867 0.562668)),((0.467142 0.334354,0.420948 0.300541,0.387037 0.34036,0.427828 0.386985,0.467142 0.334354)),((0.431222 0.390865,0.467936 0.43283,0.502629 0.391148,0.431222 0.390865)),((0.431222 0.390865,0.427828 0.386985,0.424949 0.39084,0.431222 0.390865)),((0.467936 0.43283,0.461881 0.440105,0.476049 0.442104,0.467936 0.43283)),((0.453094 0.450661,0.461881 0.440105,0.405934 0.432208,0.453094 0.450661)),((0.340592 0.843183,0.281925 0.864075,0.277228 0.872453,0.327022 0.855964,0.340592 0.843183)),((0.350431 0.574005,0.324109 0.60563,0.33042 0.651962,0.391829 0.575689,0.372228 0.567704,0.350431 0.574005)),((0.354048 0.77502,0.369376 0.816075,0.409979 0.777834,0.432133 0.708562,0.354048 0.77502)),((0.354048 0.77502,0.345181 0.751271,0.344189 0.75304,0.347896 0.780256,0.354048 0.77502)),((0.434005 0.592872,0.399476 0.578805,0.378706 0.59739,0.330739 0.654302,0.334835 0.684373,0.418801 0.619985,0.434005 0.592872)),((0.373678 0.700452,0.341221 0.73125,0.34324 0.746072,0.345181 0.751271,0.373678 0.700452)),((0.281925 0.864075,0.311609 0.81114,0.226024 0.883982,0.281925 0.864075)),((0.311609 0.81114,0.336908 0.789608,0.324735 0.787732,0.311609 0.81114)),((0.347896 0.780256,0.336908 0.789608,0.349433 0.791538,0.347896 0.780256)),((0.712142 0.513687,0.759426 0.603857,0.780122 0.563447,0.712142 0.513687)),((0.712142 0.513687,0.701969 0.494288,0.697077 0.50266,0.712142 0.513687)),((0.582796 0.506832,0.561889 0.540224,0.590925 0.573414,0.617678 0.550644,0.59637 0.506724,0.590761 0.504529,0.582796 0.506832)),((0.582796 0.506832,0.585522 0.502479,0.583256 0.501592,0.575516 0.508936,0.582796 0.506832)),((0.575516 0.508936,0.556414 0.514458,0.5462 0.522291,0.553113 0.530193,0.575516 0.508936)),((0.759426 0.603857,0.716989 0.686719,0.779237 0.641637,0.759426 0.603857)),((0.675652 0.470277,0.670404 0.427047,0.632981 0.455744,0.647385 0.466287,0.675652 0.470277)),((0.675652 0.470277,0.677877 0.488607,0.6847 0.493601,0.696391 0.483651,0.690475 0.472369,0.675652 0.470277)),((0.669517 0.419742,0.666125 0.391796,0.664792 0.391791,0.62793 0.452047,0.632188 0.455163,0.669517 0.419742)),((0.660475 0.345254,0.664289 0.376674,0.684569 0.344284,0.670981 0.335853,0.660475 0.345254)),((0.576592 0.498985,0.583256 0.501592,0.590205 0.494998,0.590473 0.49457,0.58827 0.49003,0.576592 0.498985)),((0.692237 0.346927,0.686139 0.341775,0.684569 0.344284,0.691299 0.34846,0.692237 0.346927)),((0.675782 0.67041,0.640975 0.598666,0.629779 0.617826,0.675782 0.67041)),((0.675782 0.67041,0.692351 0.704562,0.700498 0.698662,0.675782 0.67041)),((0.629779 0.617826,0.590925 0.573414,0.538821 0.617759,0.541078 0.636494,0.554323 0.64189,0.54301 0.652544,0.55437 0.746871,0.629779 0.617826)),((0.716989 0.686719,0.700498 0.698662,0.707042 0.706142,0.716989 0.686719)))" }; +// For intersection / integer +static std::string issue_930[2] = +{ + "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))", + "MULTIPOLYGON(((-10 2,5 3,20 2,-10 2)))" +}; + static std::string bug_21155501[2] = { "MULTIPOLYGON(((-8.3935546875 27.449790329784214,4.9658203125 18.729501999072138,11.8212890625 23.563987128451217,9.7119140625 25.48295117535531,9.8876953125 31.728167146023935,8.3056640625 32.99023555965106,8.5693359375 37.16031654673677,-1.8896484375 35.60371874069731,-0.5712890625 32.02670629333614,-8.9208984375 29.458731185355344,-8.3935546875 27.449790329784214)))", diff --git a/test/algorithms/overlay/overlay.cpp b/test/algorithms/overlay/overlay.cpp index ee1463216..8162a848c 100644 --- a/test/algorithms/overlay/overlay.cpp +++ b/test/algorithms/overlay/overlay.cpp @@ -18,10 +18,6 @@ #include #include -#if defined(TEST_WITH_SVG) -# include -#endif - #include #include @@ -29,15 +25,12 @@ #include #include #include - -//#include +#include #if defined(TEST_WITH_SVG) # include #endif -#include - #include "multi_overlay_cases.hpp" @@ -71,9 +64,8 @@ struct map_visitor template void visit_turns(int phase, Turns const& turns) { - typedef typename boost::range_value::type turn_type; int index = 0; - for (turn_type const& turn : turns) + for (auto const& turn : turns) { switch (phase) { @@ -128,9 +120,8 @@ struct map_visitor template void visit_clusters(Clusters const& clusters, Turns const& turns) { - typedef typename boost::range_value::type turn_type; int index = 0; - for (turn_type const& turn : turns) + for (auto const& turn : turns) { if (turn.cluster_id >= 0) { @@ -158,8 +149,6 @@ struct map_visitor template void visit_traverse(Turns const& turns, Turn const& turn, Operation const& op, const std::string& header) { - typedef typename boost::range_value::type turn_type; - if (! m_do_output) { return; @@ -381,7 +370,7 @@ void test_overlay(std::string const& caseid, std::ofstream svg(filename.str().c_str()); - typedef bg::svg_mapper::type> svg_mapper; + using svg_mapper = bg::svg_mapper::type>; svg_mapper mapper(svg, 500, 500); mapper.add(g1); @@ -395,8 +384,8 @@ void test_overlay(std::string const& caseid, #endif - typedef typename boost::range_value::type geometry_out; - typedef bg::detail::overlay::overlay + using geometry_out = typename boost::range_value::type ; + using overlay = bg::detail::overlay::overlay < Geometry, Geometry, bg::detail::overlay::do_reverse::value>::value, @@ -406,20 +395,20 @@ void test_overlay(std::string const& caseid, bg::detail::overlay::do_reverse::value>::value, geometry_out, OverlayType - > overlay; + >; - typedef typename bg::strategies::relate::services::default_strategy + using strategy_type = typename bg::strategies::relate::services::default_strategy < Geometry, Geometry - >::type strategy_type; + >::type; strategy_type strategy; - typedef typename bg::rescale_overlay_policy_type + using rescale_policy_type = typename bg::rescale_overlay_policy_type < Geometry, Geometry - >::type rescale_policy_type; + >::type; rescale_policy_type robust_policy = bg::get_rescale_policy(g1, g2); @@ -474,9 +463,9 @@ void test_overlay(std::string const& caseid, template void test_all() { - typedef bg::model::point point_type; - typedef bg::model::polygon polygon; - typedef bg::model::multi_polygon multi_polygon; + using point_type = bg::model::point; + using polygon = bg::model::polygon; + using multi_polygon = bg::model::multi_polygon; TEST_UNION(case_multi_simplex, 14.58, 1, 0); TEST_INTERSECTION(case_multi_simplex, 6.42, 2, 0); @@ -510,16 +499,22 @@ void test_all() TEST_UNION(case_recursive_boxes_12, 6.0, 6, 0); TEST_UNION(case_recursive_boxes_13, 10.25, 3, 0); + TEST_INTERSECTION(issue_930, 8.3333333, 1, 0); +} -// std::cout -// << " \"" -// << bg::inverse(case_65_multi[0], 1.0) -// << "\"" << std::endl; +template +void test_integer() +{ + using point_type = bg::model::point; + using polygon = bg::model::polygon; + using multi_polygon = bg::model::multi_polygon; + + TEST_INTERSECTION(issue_930, 10, 1, 0); } int test_main(int, char* []) { + test_integer(); test_all(); -// test_all(); return 0; } diff --git a/test/algorithms/set_operations/difference/difference.cpp b/test/algorithms/set_operations/difference/difference.cpp index 910cf6df1..21c2094d4 100644 --- a/test/algorithms/set_operations/difference/difference.cpp +++ b/test/algorithms/set_operations/difference/difference.cpp @@ -612,9 +612,9 @@ void test_specific() test_one("ggl_list_20120717_volker", ggl_list_20120717_volker[0], ggl_list_20120717_volker[1], - 1, 11, 3371540, - 1, 4, 385, - 1, 16, 3371540 + 385); + 1, 11, 3370444, + 1, 4, 383, + 2, 16, 3370444 + 383); test_one("ticket_10658", ticket_10658[0], ticket_10658[1], @@ -623,11 +623,12 @@ void test_specific() test_one("ticket_11121", ticket_11121[0], ticket_11121[1], - 2, 8, 489763.5, - 1, 4, 6731652.0); + 2, 8, 489904.5, + 1, 4, 6755355, + 1); // Generates spikes, both a-b and b-a - TEST_DIFFERENCE(ticket_11676, 2, 2537992.5, 2, 294963.5, 3); + TEST_DIFFERENCE(ticket_11676, 2, 2537404.5, 2, 295353, 3); } int test_main(int, char* []) diff --git a/test/algorithms/set_operations/difference/difference_areal_linear.cpp b/test/algorithms/set_operations/difference/difference_areal_linear.cpp index 6fa40fd7d..046b8c800 100644 --- a/test/algorithms/set_operations/difference/difference_areal_linear.cpp +++ b/test/algorithms/set_operations/difference/difference_areal_linear.cpp @@ -240,8 +240,8 @@ int test_main(int, char* []) test_all >(); test_ticket_10835 - ("MULTILINESTRING((5239 2113,5232 2115),(4794 2205,1020 2986))", - "MULTILINESTRING((5239 2113,5232 2115),(4794 2205,1460 2895))"); + ("MULTILINESTRING((5239 2113,5233 2114),(4794 2205,1020 2986))", + "MULTILINESTRING((5239 2113,5233 2114),(4794 2205,1460 2895))"); test_ticket_10835 ("MULTILINESTRING((5239 2113,5232.52 2114.34),(4794.39 2205,1020 2986))", diff --git a/test/algorithms/set_operations/difference/difference_multi.cpp b/test/algorithms/set_operations/difference/difference_multi.cpp index 2d1a9fcc6..60447937d 100644 --- a/test/algorithms/set_operations/difference/difference_multi.cpp +++ b/test/algorithms/set_operations/difference/difference_multi.cpp @@ -440,10 +440,10 @@ void test_specific_areal() settings.set_test_validity(false); TEST_DIFFERENCE_WITH(0, 1, ticket_11674, - count_set(3, 4), - expectation_limits(9105473, 9105782), - 5, - expectation_limits(119059, 119424), ignore_count()); + count_set(2, 3, 4), + expectation_limits(9105196, 9105705), + 6, + expectation_limits(119059, 119757), ignore_count()); } { @@ -458,8 +458,8 @@ void test_specific_areal() expectation_limits(597.0, 598.0), 2); TEST_DIFFERENCE_WITH(2, 3, ticket_12751, - 2, expectation_limits(2537992, 2538306), - 2, expectation_limits(294736, 294964), + 2, expectation_limits(2537404, 2538306), + 2, expectation_limits(294736, 295353), 3); } @@ -469,9 +469,10 @@ void test_specific_areal() ut_settings settings; settings.remove_spikes = true; settings.sym_difference = false; + settings.set_test_validity(false); TEST_DIFFERENCE_WITH(0, 1, ticket_12752, - count_set(2, 3), expectation_limits(2776656, 2776693), - 3, expectation_limits(7710, 7894), + count_set(2, 3), expectation_limits(2775740, 2776693), + 3, expectation_limits(7710, 7903), 2); } @@ -479,13 +480,13 @@ void test_specific_areal() const std::string a_min_b = test_one("ticket_10661", ticket_10661[0], ticket_10661[1], - 2, -1, expectation_limits(1441632, 1441855), + 2, -1, expectation_limits(1441855, 1442081), 2, -1, expectation_limits(13167454, 13182415), count_set(3, 4)); test_one("ticket_10661_2", a_min_b, ticket_10661[2], - 1, 8, 825192.0, + 1, 8, 825640.5, 1, 10, expectation_limits(27226148, 27842812), count_set(1, 2)); } @@ -495,9 +496,9 @@ void test_specific_areal() settings.sym_difference = false; TEST_DIFFERENCE_WITH(0, 1, ticket_9942, 4, - expectation_limits(7427727, 7428108), 4, - expectation_limits(130083, 131823), 4); - TEST_DIFFERENCE_WITH(0, 1, ticket_9942a, 2, + expectation_limits(7427727, 7428549), 5, + expectation_limits(184653, 184687), 5); + TEST_DIFFERENCE_WITH(0, 1, ticket_9942a, 1, expectation_limits(412676, 413469), 2, expectation_limits(76779, 77038), 4); } diff --git a/test/algorithms/set_operations/difference/difference_multi_spike.cpp b/test/algorithms/set_operations/difference/difference_multi_spike.cpp index 3937ea2df..94efb9419 100644 --- a/test/algorithms/set_operations/difference/difference_multi_spike.cpp +++ b/test/algorithms/set_operations/difference/difference_multi_spike.cpp @@ -41,17 +41,17 @@ void test_spikes_in_ticket_8364() test_one("ticket_8364_step3", "MULTIPOLYGON(((3232 2532,2136 2790,1032 1764,1032 1458,1032 1212,2136 2328,3232 2220,3232 1056,1031 1056,1031 2856,3232 2856,3232 2532)))", "MULTIPOLYGON(((1032 2130,2052 2712,1032 1764,1032 2130)),((3234 2580,3234 2532,2558 2690,3234 2580)),((2558 2690,2136 2760,2052 2712,2136 2790,2558 2690)))", - count_set(2, 3), -1, expectation_limits(2775256, 2775610), // SQL Server: 2775256.47588724 - 3, -1, expectation_limits(7810, 7893), // SQL Server: 7810.48711165739 - count_set(2, 6), ignore_validity); + count_set(1, 2, 3), -1, expectation_limits(2774644, 2775610), // SQL Server: 2775256.47588724 + 3, -1, expectation_limits(7810, 7903), // SQL Server: 7810.48711165739 + count_set(2, 3, 6), ignore_validity); // TODO: behaviour is not good yet. It is changed at introduction of self-turns. test_one("ticket_8364_step4", "MULTIPOLYGON(((2567 2688,2136 2790,2052 2712,1032 2130,1032 1764,1032 1458,1032 1212,2136 2328,3232 2220,3232 1056,1031 1056,1031 2856,3232 2856,3232 2580,2567 2688)))", "MULTIPOLYGON(((1032 2556,1778 2556,1032 2130,1032 2556)),((3234 2580,3234 2556,1778 2556,2136 2760,3234 2580)))", - count_set(1, 2), -1, expectation_limits(2615783, 2616030), // SQL Server: 2616029.55616044 - 1, -1, expectation_limits(161054, 161134), // SQL Server: 161054.560110092 - count_set(1, 3), ignore_validity); + count_set(1, 2), -1, expectation_limits(2615783, 2616400), // SQL Server: 2616029.55616044 + 1, -1, expectation_limits(160954, 161134), // SQL Server: 161054.560110092 + count_set(1, 2, 3), ignore_validity); } template @@ -75,10 +75,6 @@ void test_spikes_in_ticket_8365() count_set(2, 4)); } - - - - int test_main(int, char* []) { test_spikes_in_ticket_8364, true, true>(); diff --git a/test/util/Jamfile b/test/util/Jamfile index 808897af5..238e818c1 100644 --- a/test/util/Jamfile +++ b/test/util/Jamfile @@ -20,6 +20,7 @@ test-suite boost-geometry-util [ run calculation_type.cpp : : : : util_calculation_type ] [ run for_each_coordinate.cpp : : : : util_for_each_coordinate ] [ run math_abs.cpp : : : : util_math_abs ] + [ run math_divide.cpp : : : : util_math_divide ] [ run math_equals.cpp : : : : util_math_equals ] [ run math_sqrt.cpp : : : : util_math_sqrt ] [ run promote_integral.cpp : : : : util_promote_integral ] diff --git a/test/util/math_divide.cpp b/test/util/math_divide.cpp new file mode 100644 index 000000000..28bf914f3 --- /dev/null +++ b/test/util/math_divide.cpp @@ -0,0 +1,62 @@ +// Boost.Geometry +// Unit Test + +// Copyright (c) 2022 Barend Gehrels, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + + +#include + +#include + +namespace bgm = bg::math; + +template +void test_integer() +{ + BOOST_CHECK_EQUAL(0, bgm::divide(0, 2)); + + BOOST_CHECK_EQUAL(1, bgm::divide(1, 2)); + BOOST_CHECK_EQUAL(-1, bgm::divide(-1, 2)); + BOOST_CHECK_EQUAL(-1, bgm::divide(1, -2)); + BOOST_CHECK_EQUAL(1, bgm::divide(-1, -2)); + + BOOST_CHECK_EQUAL(2, bgm::divide(4, 2)); + BOOST_CHECK_EQUAL(3, bgm::divide(5, 2)); + + BOOST_CHECK_EQUAL(9, bgm::divide(94, 10)); + BOOST_CHECK_EQUAL(10, bgm::divide(95, 10)); + BOOST_CHECK_EQUAL(10, bgm::divide(99, 10)); + + BOOST_CHECK_EQUAL(-9, bgm::divide(94, -10)); + BOOST_CHECK_EQUAL(-10, bgm::divide(95, -10)); + BOOST_CHECK_EQUAL(-10, bgm::divide(99, -10)); + + BOOST_CHECK_EQUAL(-9, bgm::divide(-94, 10)); + BOOST_CHECK_EQUAL(-10, bgm::divide(-95, 10)); + BOOST_CHECK_EQUAL(-10, bgm::divide(-99, 10)); + + BOOST_CHECK_EQUAL(9, bgm::divide(-94, -10)); + BOOST_CHECK_EQUAL(10, bgm::divide(-95, -10)); + BOOST_CHECK_EQUAL(10, bgm::divide(-99, -10)); + + BOOST_CHECK_EQUAL(5, bgm::divide(4567, 1000)); +} + +template +void test_floating_point() +{ + constexpr double eps = 1.0e-6; + BOOST_CHECK_CLOSE(4.567, bgm::divide(4567, 1000), eps); +} + +int test_main(int, char* []) +{ + test_integer(); + test_floating_point(); + + return 0; +} From 64803f39c1f1f9201ab2567c880f7b2e96d4830d Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Mon, 7 Feb 2022 17:27:40 +0100 Subject: [PATCH 2/2] [ci] Update msvc version in gh workflow --- .github/workflows/minimal.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/minimal.yml b/.github/workflows/minimal.yml index f6f01369d..c54fd9ce4 100644 --- a/.github/workflows/minimal.yml +++ b/.github/workflows/minimal.yml @@ -232,14 +232,12 @@ jobs: strategy: fail-fast: false matrix: - # TODO: Waiting for msvc-14.0, msvc-14.1 - # https://github.com/actions/virtual-environments/issues/68#issuecomment-596817066 b2_toolset: [ - msvc-14.2 + msvc-14.3 ] include: - - b2_toolset: msvc-14.2 + - b2_toolset: msvc-14.3 b2_cxxstd: 14,17,2a steps: