diff --git a/include/boost/geometry/index/detail/rtree/pack_create.hpp b/include/boost/geometry/index/detail/rtree/pack_create.hpp index 94ce695a3..4cfd39669 100644 --- a/include/boost/geometry/index/detail/rtree/pack_create.hpp +++ b/include/boost/geometry/index/detail/rtree/pack_create.hpp @@ -196,8 +196,10 @@ public: values_count = static_cast(diff); entries.reserve(values_count); + + auto const& strategy = index::detail::get_strategy(parameters); - expandable_box hint_box(detail::get_strategy(parameters)); + expandable_box hint_box(strategy); for ( ; first != last ; ++first ) { // NOTE: support for iterators not returning true references adapted @@ -214,7 +216,7 @@ public: hint_box.expand(indexable); point_type pt; - geometry::centroid(indexable, pt); + geometry::centroid(indexable, pt, strategy); entries.push_back(std::make_pair(pt, first)); } diff --git a/include/boost/geometry/index/detail/rtree/rstar/insert.hpp b/include/boost/geometry/index/detail/rtree/rstar/insert.hpp index 4232978d3..8517b7f1b 100644 --- a/include/boost/geometry/index/detail/rtree/rstar/insert.hpp +++ b/include/boost/geometry/index/detail/rtree/rstar/insert.hpp @@ -101,9 +101,12 @@ public: BOOST_GEOMETRY_INDEX_ASSERT(elements.size() == elements_count, "unexpected elements number"); BOOST_GEOMETRY_INDEX_ASSERT(0 < reinserted_elements_count, "wrong value of elements to reinsert"); + auto const& strategy = index::detail::get_strategy(parameters); + // calculate current node's center point_type node_center; - geometry::centroid(rtree::elements(*parent)[current_child_index].first, node_center); + geometry::centroid(rtree::elements(*parent)[current_child_index].first, node_center, + strategy); // fill the container of centers' distances of children from current node's center typedef typename index::detail::rtree::container_from_elements_type< @@ -115,13 +118,12 @@ public: // If constructor is used instead of resize() MS implementation leaks here sorted_elements.reserve(elements_count); // MAY THROW, STRONG (V, E: alloc, copy) - auto const& strategy = index::detail::get_strategy(parameters); - for ( typename elements_type::const_iterator it = elements.begin() ; it != elements.end() ; ++it ) { point_type element_center; - geometry::centroid( rtree::element_indexable(*it, translator), element_center); + geometry::centroid(rtree::element_indexable(*it, translator), element_center, + strategy); sorted_elements.push_back(std::make_pair( comparable_distance_pp::call(node_center, element_center, strategy), *it)); // MAY THROW (V, E: copy) diff --git a/include/boost/geometry/strategies/centroid/geographic.hpp b/include/boost/geometry/strategies/centroid/geographic.hpp index a1634ce43..26619e9e2 100644 --- a/include/boost/geometry/strategies/centroid/geographic.hpp +++ b/include/boost/geometry/strategies/centroid/geographic.hpp @@ -12,13 +12,8 @@ #include -#include - -#include -// TODO - for backwards compatibility, remove? -#include -#include -#include +#include +#include namespace boost { namespace geometry @@ -27,7 +22,6 @@ namespace boost { namespace geometry namespace strategies { namespace centroid { -/* template < typename FormulaPolicy = strategy::andoyer, @@ -45,12 +39,29 @@ public: explicit geographic(Spheroid const& spheroid) : base_t(spheroid) {} + + // TODO: Box and Segment should have proper strategies. + template + static auto centroid(Geometry const&, Point const&, + std::enable_if_t + < + util::is_segment::value + || util::is_box::value + > * = nullptr) + { + return strategy::centroid::not_applicable_strategy(); + } }; -*/ namespace services { +template +struct default_strategy +{ + using type = strategies::centroid::geographic<>; +}; + } // namespace services }} // namespace strategies::centroid diff --git a/include/boost/geometry/strategies/centroid/spherical.hpp b/include/boost/geometry/strategies/centroid/spherical.hpp index 4dfae1e66..4d7634dc1 100644 --- a/include/boost/geometry/strategies/centroid/spherical.hpp +++ b/include/boost/geometry/strategies/centroid/spherical.hpp @@ -12,9 +12,8 @@ #include -#include - -#include +#include +#include namespace boost { namespace geometry @@ -23,30 +22,41 @@ namespace boost { namespace geometry namespace strategies { namespace centroid { -/* template < - typename RadiusTypeOrSphere = double, typename CalculationType = void > class spherical - : public strategies::detail::spherical_base + : public strategies::detail::spherical_base { - using base_t = strategies::detail::spherical_base; + using base_t = strategies::detail::spherical_base; public: spherical() = default; - template - explicit spherical(RadiusOrSphere const& radius_or_sphere) - : base_t(radius_or_sphere) - {} + // TODO: Box and Segment should have proper strategies. + template + static auto centroid(Geometry const&, Point const&, + std::enable_if_t + < + util::is_segment::value + || util::is_box::value + > * = nullptr) + { + return strategy::centroid::not_applicable_strategy(); + } }; -*/ + namespace services { +template +struct default_strategy +{ + using type = strategies::centroid::spherical<>; +}; + } // namespace services }} // namespace strategies::centroid diff --git a/test/cs_undefined/other.cpp b/test/cs_undefined/other.cpp index 8475d141a..5608a8abb 100644 --- a/test/cs_undefined/other.cpp +++ b/test/cs_undefined/other.cpp @@ -24,13 +24,19 @@ inline void simplify(G const& g1, G & g2) bg::simplify(g1, g2, 1, bg::strategies::simplify::geographic<>()); } +template +inline void centroid(G const& g, P & p) +{ + bg::centroid(g, p, bg::strategies::centroid::cartesian<>()); + bg::centroid(g, p, bg::strategies::centroid::spherical<>()); + bg::centroid(g, p, bg::strategies::centroid::geographic<>()); +} + int test_main(int, char*[]) { geom g, o; - // this compiles but it shouldn't! - // internally default_strategy is defined as not_applicable_strategy for box - bg::centroid(g.b, o.pt); + ::centroid(g.b, o.pt); ::simplify(g.pt, o.pt); ::simplify(g.ls, o.ls);