File indexing completed on 2025-01-18 09:35:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_CENTROID_HPP
0016 #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_CENTROID_HPP
0017
0018 #include <boost/geometry/algorithms/detail/comparable_distance/interface.hpp>
0019 #include <boost/geometry/core/access.hpp>
0020
0021 #include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
0022 #include <boost/geometry/index/detail/algorithms/diff_abs.hpp>
0023
0024 namespace boost { namespace geometry { namespace index { namespace detail {
0025
0026 struct comparable_distance_centroid_tag {};
0027
0028 template <
0029 typename Point,
0030 typename PointIndexable,
0031 size_t N>
0032 struct sum_for_indexable<Point, PointIndexable, point_tag, comparable_distance_centroid_tag, N>
0033 {
0034 typedef typename geometry::default_comparable_distance_result<Point, PointIndexable>::type result_type;
0035
0036 inline static result_type apply(Point const& pt, PointIndexable const& i)
0037 {
0038 return geometry::comparable_distance(pt, i);
0039 }
0040 };
0041
0042 template <
0043 typename Point,
0044 typename BoxIndexable,
0045 size_t DimensionIndex>
0046 struct sum_for_indexable_dimension<Point, BoxIndexable, box_tag, comparable_distance_centroid_tag, DimensionIndex>
0047 {
0048 typedef typename geometry::default_comparable_distance_result<Point, BoxIndexable>::type result_type;
0049
0050 inline static result_type apply(Point const& pt, BoxIndexable const& i)
0051 {
0052 typedef typename coordinate_type<Point>::type point_coord_t;
0053 typedef typename coordinate_type<BoxIndexable>::type indexable_coord_t;
0054
0055 point_coord_t pt_c = geometry::get<DimensionIndex>(pt);
0056 indexable_coord_t ind_c_min = geometry::get<geometry::min_corner, DimensionIndex>(i);
0057 indexable_coord_t ind_c_max = geometry::get<geometry::max_corner, DimensionIndex>(i);
0058
0059 indexable_coord_t ind_c_avg = ind_c_min + (ind_c_max - ind_c_min) / 2;
0060
0061
0062 result_type diff = detail::diff_abs(ind_c_avg, pt_c);
0063
0064 return diff * diff;
0065 }
0066 };
0067
0068 template <typename Point, typename Indexable>
0069 typename geometry::default_comparable_distance_result<Point, Indexable>::type
0070 comparable_distance_centroid(Point const& pt, Indexable const& i)
0071 {
0072 return detail::sum_for_indexable<
0073 Point,
0074 Indexable,
0075 typename tag<Indexable>::type,
0076 detail::comparable_distance_centroid_tag,
0077 dimension<Indexable>::value
0078 >::apply(pt, i);
0079 }
0080
0081 }}}}
0082
0083 #endif
0084