// Boost.Geometry // Unit Test // Copyright (c) 2022 Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // 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 using point_t = bg::model::point; using linestring_t = bg::model::linestring; using polygon_t = bg::model::polygon; using variant_t = boost::variant; using gc_t = bg::model::geometry_collection; using nra_gc_t = bg::model::geometry_collection; struct rec_gc_t; using rec_var_t = boost::variant; struct rec_gc_t : std::vector { rec_gc_t() = default; rec_gc_t(std::initializer_list l) : std::vector(l) {} }; struct rec_nra_gc_t; using rec_nra_var_t = boost::variant; struct rec_nra_gc_t : std::list { rec_nra_gc_t() = default; rec_nra_gc_t(std::initializer_list l) : std::list(l) {} }; namespace boost { namespace geometry { namespace traits { template<> struct tag { typedef geometry_collection_tag type; }; template<> struct geometry_types { typedef util::type_sequence type; }; }}} namespace boost { namespace geometry { namespace traits { template<> struct tag { typedef geometry_collection_tag type; }; template<> struct geometry_types { typedef util::type_sequence type; }; }}} template GC make_gc() { return GC{ point_t{0, 0}, linestring_t{{1, 1}, {2, 2}}, polygon_t{{{3, 3}, {3, 4}, {4, 4}, {4, 3}, {3, 3}}}, polygon_t{{{5, 5}, {5, 6}, {6, 6}, {6, 5}, {5, 5}}} }; } template GC make_rec_gc() { return GC{ point_t{0, 0}, GC { // This should be put at the end because GC is processed in a BFS manner. // So both GCs should be equivalent. polygon_t{{{5, 5}, {5, 6}, {6, 6}, {6, 5}, {5, 5}}} }, linestring_t{{1, 1}, {2, 2}}, polygon_t{{{3, 3}, {3, 4}, {4, 4}, {4, 3}, {3, 3}}}, }; } template void test_all(Make make) { using view_t = bg::detail::random_access_view; GC gc = make(); view_t rav{gc}; using non_gc_types = bg::util::type_sequence; using view_types = typename bg::traits::geometry_types::type; BOOST_STATIC_ASSERT((std::is_same::value)); BOOST_STATIC_ASSERT(bg::detail::is_random_access_range::value); BOOST_STATIC_ASSERT(! bg::detail::is_geometry_collection_recursive::value); size_t s = boost::size(gc); for (size_t i = 0 ; i < s ; ++i) { bg::traits::iter_visit>::apply([&](auto&& g) { using geom_t = bg::util::remove_cref_t; if (i == 0) { BOOST_CHECK(bg::util::is_point::value); } else if (i == 1) { BOOST_CHECK(bg::util::is_linestring::value); } else { BOOST_CHECK(bg::util::is_polygon::value); } }, rav.begin() + i); } } int test_main(int, char* []) { BOOST_STATIC_ASSERT(bg::detail::is_random_access_range::value); BOOST_STATIC_ASSERT(! bg::detail::is_random_access_range::value); BOOST_STATIC_ASSERT(bg::detail::is_random_access_range::value); BOOST_STATIC_ASSERT(! bg::detail::is_random_access_range::value); BOOST_STATIC_ASSERT(! bg::detail::is_geometry_collection_recursive::value); BOOST_STATIC_ASSERT(! bg::detail::is_geometry_collection_recursive::value); BOOST_STATIC_ASSERT(bg::detail::is_geometry_collection_recursive::value); BOOST_STATIC_ASSERT(bg::detail::is_geometry_collection_recursive::value); test_all(make_gc); test_all(make_gc); test_all(make_gc); test_all(make_gc); return 0; }