diff --git a/include/boost/geometry/index/detail/rtree/pack_create.hpp b/include/boost/geometry/index/detail/rtree/pack_create.hpp index 6a8ffe6aa..14a14320e 100644 --- a/include/boost/geometry/index/detail/rtree/pack_create.hpp +++ b/include/boost/geometry/index/detail/rtree/pack_create.hpp @@ -2,7 +2,7 @@ // // R-tree initial packing // -// Copyright (c) 2011-2017 Adam Wulkiewicz, Lodz, Poland. +// Copyright (c) 2011-2022 Adam Wulkiewicz, Lodz, Poland. // Copyright (c) 2020 Caian Benedicto, Campinas, Brazil. // // This file was modified by Oracle on 2019-2021. @@ -75,23 +75,28 @@ template struct nth_element_and_half_boxes { template - static inline void apply(EIt first, EIt median, EIt last, Box const& box, Box & left, Box & right, std::size_t dim_index) + static inline void apply(EIt first, EIt median, EIt last, Box const& box, + Box & left, Box & right, std::size_t dim_index) { - if ( I == dim_index ) + if (I == dim_index) { index::detail::nth_element(first, median, last, point_entries_comparer()); geometry::convert(box, left); geometry::convert(box, right); - typename coordinate_type::type edge_len - = geometry::get(box) - geometry::get(box); - typename coordinate_type::type median - = geometry::get(box) + edge_len / 2; - geometry::set(left, median); - geometry::set(right, median); + auto const mi = geometry::get(box); + auto const ma = geometry::get(box); + auto const center = mi + (ma - mi) / 2; + geometry::set(left, center); + geometry::set(right, center); } else - nth_element_and_half_boxes::apply(first, median, last, box, left, right, dim_index); + { + nth_element_and_half_boxes + < + I + 1, Dimension + >::apply(first, median, last, box, left, right, dim_index); + } } };