1 // Boost.Geometry Index
3 // squared distance between point and centroid of the box or point
5 // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_CENTROID_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_CENTROID_HPP
14 #include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
15 #include <boost/geometry/index/detail/algorithms/diff_abs.hpp>
17 namespace boost { namespace geometry { namespace index { namespace detail {
19 struct comparable_distance_centroid_tag {};
23 typename PointIndexable,
25 struct sum_for_indexable<Point, PointIndexable, point_tag, comparable_distance_centroid_tag, N>
27 typedef typename geometry::default_comparable_distance_result<Point, PointIndexable>::type result_type;
29 inline static result_type apply(Point const& pt, PointIndexable const& i)
31 return geometry::comparable_distance(pt, i);
37 typename BoxIndexable,
38 size_t DimensionIndex>
39 struct sum_for_indexable_dimension<Point, BoxIndexable, box_tag, comparable_distance_centroid_tag, DimensionIndex>
41 typedef typename geometry::default_comparable_distance_result<Point, BoxIndexable>::type result_type;
43 inline static result_type apply(Point const& pt, BoxIndexable const& i)
45 typedef typename coordinate_type<Point>::type point_coord_t;
46 typedef typename coordinate_type<BoxIndexable>::type indexable_coord_t;
48 point_coord_t pt_c = geometry::get<DimensionIndex>(pt);
49 indexable_coord_t ind_c_min = geometry::get<geometry::min_corner, DimensionIndex>(i);
50 indexable_coord_t ind_c_max = geometry::get<geometry::max_corner, DimensionIndex>(i);
52 indexable_coord_t ind_c_avg = ind_c_min + (ind_c_max - ind_c_min) / 2;
53 // TODO: awulkiew - is (ind_c_min + ind_c_max) / 2 safe?
55 result_type diff = detail::diff_abs(ind_c_avg, pt_c);
61 template <typename Point, typename Indexable>
62 typename geometry::default_comparable_distance_result<Point, Indexable>::type
63 comparable_distance_centroid(Point const& pt, Indexable const& i)
65 return detail::sum_for_indexable<
68 typename tag<Indexable>::type,
69 detail::comparable_distance_centroid_tag,
70 dimension<Indexable>::value
74 }}}} // namespace boost::geometry::index::detail
76 #endif // #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_CENTROID_HPP
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams