// Boost.Geometry // 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 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_GC_MAKE_RTREE_HPP #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_GC_MAKE_RTREE_HPP #include #include #include #include #include #include #include #include #include #include namespace boost { namespace geometry { #ifndef DOXYGEN_NO_DETAIL namespace detail { template using gc_make_rtree_box_t = geometry::model::box < geometry::model::point < typename geometry::coordinate_type::type, geometry::dimension::value, typename geometry::coordinate_system::type > >; template inline auto gc_make_rtree_iterators(GC& gc, Strategy const& strategy) { using box_t = gc_make_rtree_box_t; using iter_t = typename boost::range_iterator::type; using rtree_param_t = index::rstar<4>; using rtree_parameters_t = index::parameters; using value_t = std::pair; using rtree_t = index::rtree; // TODO: get rid of the temporary vector auto const size = boost::size(gc); std::vector values; values.reserve(size); visit_breadth_first_impl::apply([&](auto const& g, auto iter) { box_t b = geometry::return_envelope(g, strategy); detail::expand_by_epsilon(b); values.emplace_back(b, iter); return true; }, gc); return rtree_t(values.begin(), values.end(), rtree_parameters_t(rtree_param_t(), strategy)); } template inline auto gc_make_rtree_indexes(GCView const& gc, Strategy const& strategy) { // Alternatively only take random_access_view static const bool is_random_access = is_random_access_range::value; static const bool is_not_recursive = ! is_geometry_collection_recursive::value; BOOST_GEOMETRY_STATIC_ASSERT((is_random_access && is_not_recursive), "This algorithm requires random-access, non-recursive geometry collection or view.", GCView); using box_t = gc_make_rtree_box_t; using rtree_param_t = index::rstar<4>; using rtree_parameters_t = index::parameters; using value_t = std::pair; using rtree_t = index::rtree; // TODO: get rid of the temporary vector std::size_t const size = boost::size(gc); std::vector values; values.reserve(size); auto const begin = boost::begin(gc); for (std::size_t i = 0; i < size; ++i) { traits::iter_visit::apply([&](auto const& g) { box_t b = geometry::return_envelope(g, strategy); detail::expand_by_epsilon(b); values.emplace_back(b, i); }, begin + i); } return rtree_t(values.begin(), values.end(), rtree_parameters_t(rtree_param_t(), strategy)); } } // namespace detail #endif // DOXYGEN_NO_DETAIL }} // namespace boost::geometry #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_GC_MAKE_RTREE_HPP