]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/include/boost/geometry/index/detail/algorithms/comparable_distance_far.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / index / detail / algorithms / comparable_distance_far.hpp
1 // Boost.Geometry Index
2 //
3 // squared distance between point and furthest point of the box or point
4 //
5 // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
6 //
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)
10
11 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP
13
14 #include <boost/geometry/index/detail/algorithms/diff_abs.hpp>
15 #include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
16
17 namespace boost { namespace geometry { namespace index { namespace detail {
18
19 // minmaxdist component
20
21 struct comparable_distance_far_tag {};
22
23 template <
24 typename Point,
25 typename BoxIndexable,
26 size_t DimensionIndex>
27 struct sum_for_indexable_dimension<Point, BoxIndexable, box_tag, comparable_distance_far_tag, DimensionIndex>
28 {
29 typedef typename geometry::default_comparable_distance_result<Point, BoxIndexable>::type result_type;
30
31 inline static result_type apply(Point const& pt, BoxIndexable const& i)
32 {
33 typedef typename coordinate_type<Point>::type point_coord_t;
34 typedef typename coordinate_type<BoxIndexable>::type indexable_coord_t;
35
36 point_coord_t pt_c = geometry::get<DimensionIndex>(pt);
37 indexable_coord_t ind_c_min = geometry::get<geometry::min_corner, DimensionIndex>(i);
38 indexable_coord_t ind_c_max = geometry::get<geometry::max_corner, DimensionIndex>(i);
39
40 result_type further_diff = 0;
41
42 if ( (ind_c_min + ind_c_max) / 2 <= pt_c )
43 further_diff = pt_c - ind_c_min;
44 else
45 further_diff = detail::diff_abs(pt_c, ind_c_max); // unsigned values protection
46
47 return further_diff * further_diff;
48 }
49 };
50
51 template <typename Point, typename Indexable>
52 typename geometry::default_comparable_distance_result<Point, Indexable>::type
53 comparable_distance_far(Point const& pt, Indexable const& i)
54 {
55 return detail::sum_for_indexable<
56 Point,
57 Indexable,
58 typename tag<Indexable>::type,
59 detail::comparable_distance_far_tag,
60 dimension<Indexable>::value
61 >::apply(pt, i);
62 }
63
64 }}}} // namespace boost::geometry::index::detail
65
66 #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP