]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/index/detail/algorithms/comparable_distance_far.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / 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 // This file was modified by Oracle on 2021.
8 // Modifications copyright (c) 2021 Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 //
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14
15 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP
16 #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP
17
18 #include <boost/geometry/algorithms/detail/comparable_distance/interface.hpp>
19 #include <boost/geometry/core/access.hpp>
20
21 #include <boost/geometry/index/detail/algorithms/diff_abs.hpp>
22 #include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
23
24 namespace boost { namespace geometry { namespace index { namespace detail {
25
26 // minmaxdist component
27
28 struct comparable_distance_far_tag {};
29
30 template <
31 typename Point,
32 typename BoxIndexable,
33 size_t DimensionIndex>
34 struct sum_for_indexable_dimension<Point, BoxIndexable, box_tag, comparable_distance_far_tag, DimensionIndex>
35 {
36 typedef typename geometry::default_comparable_distance_result<Point, BoxIndexable>::type result_type;
37
38 inline static result_type apply(Point const& pt, BoxIndexable const& i)
39 {
40 typedef typename coordinate_type<Point>::type point_coord_t;
41 typedef typename coordinate_type<BoxIndexable>::type indexable_coord_t;
42
43 point_coord_t pt_c = geometry::get<DimensionIndex>(pt);
44 indexable_coord_t ind_c_min = geometry::get<geometry::min_corner, DimensionIndex>(i);
45 indexable_coord_t ind_c_max = geometry::get<geometry::max_corner, DimensionIndex>(i);
46
47 result_type further_diff = 0;
48
49 if ( (ind_c_min + ind_c_max) / 2 <= pt_c )
50 further_diff = pt_c - ind_c_min;
51 else
52 further_diff = detail::diff_abs(pt_c, ind_c_max); // unsigned values protection
53
54 return further_diff * further_diff;
55 }
56 };
57
58 template <typename Point, typename Indexable>
59 typename geometry::default_comparable_distance_result<Point, Indexable>::type
60 comparable_distance_far(Point const& pt, Indexable const& i)
61 {
62 return detail::sum_for_indexable<
63 Point,
64 Indexable,
65 typename tag<Indexable>::type,
66 detail::comparable_distance_far_tag,
67 dimension<Indexable>::value
68 >::apply(pt, i);
69 }
70
71 }}}} // namespace boost::geometry::index::detail
72
73 #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP