[index] Fix msvc warning and refactor the code

This commit is contained in:
Adam Wulkiewicz 2022-07-09 20:36:47 +02:00
parent 4241b6a777
commit 947dca1562

View File

@ -2,7 +2,7 @@
// //
// R-tree initial packing // 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. // Copyright (c) 2020 Caian Benedicto, Campinas, Brazil.
// //
// This file was modified by Oracle on 2019-2021. // This file was modified by Oracle on 2019-2021.
@ -75,23 +75,28 @@ template <std::size_t I, std::size_t Dimension>
struct nth_element_and_half_boxes struct nth_element_and_half_boxes
{ {
template <typename EIt, typename Box> template <typename EIt, typename Box>
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<I>()); index::detail::nth_element(first, median, last, point_entries_comparer<I>());
geometry::convert(box, left); geometry::convert(box, left);
geometry::convert(box, right); geometry::convert(box, right);
typename coordinate_type<Box>::type edge_len auto const mi = geometry::get<min_corner, I>(box);
= geometry::get<max_corner, I>(box) - geometry::get<min_corner, I>(box); auto const ma = geometry::get<max_corner, I>(box);
typename coordinate_type<Box>::type median auto const center = mi + (ma - mi) / 2;
= geometry::get<min_corner, I>(box) + edge_len / 2; geometry::set<max_corner, I>(left, center);
geometry::set<max_corner, I>(left, median); geometry::set<min_corner, I>(right, center);
geometry::set<min_corner, I>(right, median);
} }
else else
nth_element_and_half_boxes<I+1, Dimension>::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);
}
} }
}; };