// Boost.Geometry Index // // Spatial index distance predicates, calculators and checkers // used in nearest query - specialized for envelopes // // Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland. // // This file was modified by Oracle on 2019. // Modifications copyright (c) 2019 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) #ifndef BOOST_GEOMETRY_INDEX_DETAIL_DISTANCE_PREDICATES_HPP #define BOOST_GEOMETRY_INDEX_DETAIL_DISTANCE_PREDICATES_HPP #include #include #include #include #include namespace boost { namespace geometry { namespace index { namespace detail { // ------------------------------------------------------------------ // // relations // ------------------------------------------------------------------ // template struct to_nearest { to_nearest(T const& v) : value(v) {} T value; }; template struct to_centroid { to_centroid(T const& v) : value(v) {} T value; }; template struct to_furthest { to_furthest(T const& v) : value(v) {} T value; }; // tags struct to_nearest_tag {}; struct to_centroid_tag {}; struct to_furthest_tag {}; // ------------------------------------------------------------------ // // relation traits and access // ------------------------------------------------------------------ // template struct relation { typedef T value_type; typedef to_nearest_tag tag; static inline T const& value(T const& v) { return v; } static inline T & value(T & v) { return v; } }; template struct relation< to_nearest > { typedef T value_type; typedef to_nearest_tag tag; static inline T const& value(to_nearest const& r) { return r.value; } static inline T & value(to_nearest & r) { return r.value; } }; template struct relation< to_centroid > { typedef T value_type; typedef to_centroid_tag tag; static inline T const& value(to_centroid const& r) { return r.value; } static inline T & value(to_centroid & r) { return r.value; } }; template struct relation< to_furthest > { typedef T value_type; typedef to_furthest_tag tag; static inline T const& value(to_furthest const& r) { return r.value; } static inline T & value(to_furthest & r) { return r.value; } }; // ------------------------------------------------------------------ // template < typename G1, typename G2, typename Strategy, typename Tag1 = typename geometry::tag::type, typename Tag2 = typename geometry::tag::type > struct comparable_distance_call_base { typedef typename geometry::default_comparable_distance_result < G1, G2 >::type result_type; static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const&) { return geometry::comparable_distance(g1, g2); } }; template < typename G1, typename G2, typename Strategy > struct comparable_distance_call_base { typedef typename geometry::comparable_distance_result < G1, G2, typename Strategy::comparable_distance_point_point_strategy_type >::type result_type; static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const& s) { return geometry::comparable_distance(g1, g2, s.get_comparable_distance_point_point_strategy()); } }; template < typename G1, typename G2, typename Strategy > struct comparable_distance_call_base { typedef typename geometry::comparable_distance_result < G1, G2, typename Strategy::comparable_distance_point_box_strategy_type >::type result_type; static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const& s) { return geometry::comparable_distance(g1, g2, s.get_comparable_distance_point_box_strategy()); } }; template < typename G1, typename G2, typename Strategy > struct comparable_distance_call_base { typedef typename geometry::comparable_distance_result < G1, G2, typename Strategy::comparable_distance_point_segment_strategy_type >::type result_type; static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const& s) { return geometry::comparable_distance(g1, g2, s.get_comparable_distance_point_segment_strategy()); } }; template < typename G1, typename G2, typename Strategy > struct comparable_distance_call_base { typedef typename geometry::comparable_distance_result < G1, G2, typename Strategy::comparable_distance_segment_box_strategy_type >::type result_type; static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const& s) { return geometry::comparable_distance(g1, g2, s.get_comparable_distance_segment_box_strategy()); } }; template < typename G1, typename G2, typename Strategy > struct comparable_distance_call_base { typedef typename geometry::comparable_distance_result < G1, G2, typename Strategy::comparable_distance_point_segment_strategy_type >::type result_type; static inline result_type apply(G1 const& g1, G2 const& g2, Strategy const& s) { return geometry::comparable_distance(g1, g2, s.get_comparable_distance_point_segment_strategy()); } }; template < typename G1, typename G2, typename Strategy > struct comparable_distance_call : comparable_distance_call_base {}; template < typename G1, typename G2 > struct comparable_distance_call : comparable_distance_call_base {}; // ------------------------------------------------------------------ // // calculate_distance // ------------------------------------------------------------------ // template struct calculate_distance { BOOST_MPL_ASSERT_MSG((false), INVALID_PREDICATE_OR_TAG, (calculate_distance)); }; // this handles nearest() with default Point parameter, to_nearest() and bounds template struct calculate_distance< predicates::nearest, Indexable, Strategy, Tag> { typedef detail::relation relation; typedef comparable_distance_call < typename relation::value_type, Indexable, Strategy > call_type; typedef typename call_type::result_type result_type; static inline bool apply(predicates::nearest const& p, Indexable const& i, Strategy const& s, result_type & result) { result = call_type::apply(relation::value(p.point_or_relation), i, s); return true; } }; template struct calculate_distance< predicates::nearest< to_centroid >, Indexable, Strategy, value_tag> { typedef Point point_type; typedef typename geometry::default_comparable_distance_result < point_type, Indexable >::type result_type; static inline bool apply(predicates::nearest< to_centroid > const& p, Indexable const& i, Strategy const& , result_type & result) { result = index::detail::comparable_distance_centroid(p.point_or_relation.value, i); return true; } }; template struct calculate_distance< predicates::nearest< to_furthest >, Indexable, Strategy, value_tag> { typedef Point point_type; typedef typename geometry::default_comparable_distance_result < point_type, Indexable >::type result_type; static inline bool apply(predicates::nearest< to_furthest > const& p, Indexable const& i, Strategy const& , result_type & result) { result = index::detail::comparable_distance_far(p.point_or_relation.value, i); return true; } }; template struct calculate_distance< predicates::path, Indexable, Strategy, Tag> { typedef typename index::detail::default_path_intersection_distance_type< Indexable, SegmentOrLinestring >::type result_type; static inline bool apply(predicates::path const& p, Indexable const& i, Strategy const& , result_type & result) { return index::detail::path_intersection(i, p.geometry, result); } }; }}}} // namespace boost::geometry::index::detail #endif // BOOST_GEOMETRY_INDEX_RTREE_DISTANCE_PREDICATES_HPP