// Boost.Geometry // Unit Test // Copyright (c) 2021 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 #include #include #include #include template auto get_distance(P const& p1, P const& p2) { using namespace boost::geometry; using tag = typename cs_tag

::type; using strategy_type = typename strategy::distance::services::default_strategy < point_tag, point_tag, P, P, tag, tag >::type; strategy_type s; return detail::distance::point_to_point::apply(p1, p2, s); } template bool test_approximately_equal(P const& p1, P const& p2, E const m, bool debug) { const bool result = bg::detail::overlay::approximately_equals(p1, p2, m); if (debug) { const auto d = get_distance(p1, p2); std::cout << std::boolalpha << " " << result << " " << d << std::endl; } return result; } template void test_all(E const multiplier, std::size_t expected_index) { constexpr bool debug = false; if (debug) { using ct = typename bg::coordinate_type

::type; std::cout << "EPSILON: " << std::setprecision(32) << std::numeric_limits::epsilon() << std::endl; } P p1; bg::read_wkt("POINT(1 1)", p1); std::size_t index = 0; for (double d = 1.0; d > 0; d /= 2.0, index++) { if (debug) { std::cout << index; } P p2 = p1; bg::set<0>(p2, bg::get<0>(p1) + d); if (test_approximately_equal(p1, p2, multiplier, debug)) { BOOST_CHECK_MESSAGE(index == expected_index, "Expected: " << expected_index << " Detected: " << index); return; } } } int test_main(int, char* []) { double m = 1000.0; test_all>(m, 54); test_all>(m, 43); test_all>(m, 24); m *= 1000.0; test_all>(m, 44); test_all>(m, 33); test_all>(m, 24); m *= 1000.0; test_all>(m, 34); test_all>(m, 23); test_all>(m, 23); // MP is not a floating point type, therefore approximately_equal // is behaves as exact and returns only true if they are identical. // This takes 334 steps (then "d" above is 0.0) test_all>(m, 334); return 0; }