1
// Boost.Geometry Index
3
// squared distance between point and furthest point of the box or point
5
// Copyright (c) 2011-2013 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_FAR_HPP
12
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP
14
#include <boost/geometry/index/detail/algorithms/diff_abs.hpp>
15
#include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
17
namespace boost { namespace geometry { namespace index { namespace detail {
19
// minmaxdist component
21
struct comparable_distance_far_tag {};
25
typename BoxIndexable,
26
size_t DimensionIndex>
27
struct sum_for_indexable_dimension<Point, BoxIndexable, box_tag, comparable_distance_far_tag, DimensionIndex>
29
typedef typename geometry::default_distance_result<Point, BoxIndexable>::type result_type;
31
inline static result_type apply(Point const& pt, BoxIndexable const& i)
33
typedef typename coordinate_type<Point>::type point_coord_t;
34
typedef typename coordinate_type<BoxIndexable>::type indexable_coord_t;
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);
40
result_type further_diff = 0;
42
if ( (ind_c_min + ind_c_max) / 2 <= pt_c )
43
further_diff = pt_c - ind_c_min;
45
further_diff = detail::diff_abs(pt_c, ind_c_max); // unsigned values protection
47
return further_diff * further_diff;
51
template <typename Point, typename Indexable>
52
typename geometry::default_distance_result<Point, Indexable>::type
53
comparable_distance_far(Point const& pt, Indexable const& i)
55
return detail::sum_for_indexable<
58
typename tag<Indexable>::type,
59
detail::comparable_distance_far_tag,
60
dimension<Indexable>::value
64
}}}} // namespace boost::geometry::index::detail
66
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP