// Boost.Geometry // Unit Test // Copyright (c) 2022, Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // Licensed under the Boost Software License version 1.0. // http://www.boost.org/users/license.html #include #include #include #include #include #include #include #include template void test_all(std::size_t points_count, std::size_t linestrings_count, std::size_t polygons_count, double length, double perimeter, double area) { using pt_t = P; using mpt_t = bg::model::multi_point; using seg_t = bg::model::segment; using ls_t = bg::model::linestring; using mls_t = bg::model::multi_linestring; using box_t = bg::model::box; using ring_t = bg::model::ring; using poly_t = bg::model::polygon; using mpoly_t = bg::model::multi_polygon; using var_t = boost::variant; //using var_t = boost::variant2::variant; using gc_t = bg::model::geometry_collection; gc_t gc{ poly_t{{{0, 0},{0, 10},{10, 10},{10, 0},{0, 0}}, {{1, 1},{5, 1},{5, 5},{1, 5},{1, 1}}}, mpoly_t{{{{4, 4},{4, 6},{6, 6},{6, 4},{4, 4}}}, {{{10, 10},{10, 12},{12, 12},{12, 10},{10, 10}}}}, ring_t{{11, 11},{11, 14},{14, 14},{14, 11},{11, 11}}, //box_t{{13, 13}, {16, 16}}, mls_t{{{0, 0},{20, 20}}, {{3, 3},{3, 6},{6, 6},{6, 3},{3, 3}}}, ls_t{{3, 3},{3, 20}}, mpt_t{{2, 2},{2, 2},{5, 5},{9, 9},{11, 11},{0, 20},{1, 20}}, pt_t{0, 20} }; gc_t result; bg::merge_elements(gc, result); BOOST_CHECK(boost::get(result[0]).size() == points_count); BOOST_CHECK(boost::get(result[1]).size() == linestrings_count); BOOST_CHECK(boost::get(result[2]).size() == polygons_count); auto l = bg::length(result); auto a = bg::area(result); auto p = bg::perimeter(result); decltype(l) l_expected = length; decltype(p) p_expected = perimeter; decltype(a) a_expected = area; BOOST_CHECK_CLOSE(l, l_expected, 0.000001); BOOST_CHECK_CLOSE(p, p_expected, 0.000001); BOOST_CHECK_CLOSE(a, a_expected, 0.000001); } int test_main(int, char* []) { test_all>(2, 5, 2, std::sqrt(2.0) * (3 + 6) + 4 + 10, 72, 97); // TODO: right now the elements of multi geometries are not merged, // only different geometries stored in a GC. Hence duplicated point in the result. test_all>>(4, 6, 2, 0.48141804683843953, 1.2506937915396685, 0.029392562222852522); test_all>>(4, 6, 2, 3058383.6297531724, 7951118.1434133006, 1187967114570.5911); return 0; }