1 // Boost.Geometry Index
3 // squared distance between point and nearest point 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_NEAR_HPP
12 #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_NEAR_HPP
14 #include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
16 namespace boost { namespace geometry { namespace index { namespace detail {
18 struct comparable_distance_near_tag {};
22 typename PointIndexable,
24 struct sum_for_indexable<Point, PointIndexable, point_tag, comparable_distance_near_tag, N>
26 typedef typename geometry::default_comparable_distance_result<Point, PointIndexable>::type result_type;
28 inline static result_type apply(Point const& pt, PointIndexable const& i)
30 return geometry::comparable_distance(pt, i);
36 typename BoxIndexable,
37 size_t DimensionIndex>
38 struct sum_for_indexable_dimension<Point, BoxIndexable, box_tag, comparable_distance_near_tag, DimensionIndex>
40 typedef typename geometry::default_comparable_distance_result<Point, BoxIndexable>::type result_type;
42 inline static result_type apply(Point const& pt, BoxIndexable const& i)
44 typedef typename coordinate_type<Point>::type point_coord_t;
45 typedef typename coordinate_type<BoxIndexable>::type indexable_coord_t;
47 point_coord_t pt_c = geometry::get<DimensionIndex>(pt);
48 indexable_coord_t ind_c_min = geometry::get<geometry::min_corner, DimensionIndex>(i);
49 indexable_coord_t ind_c_max = geometry::get<geometry::max_corner, DimensionIndex>(i);
53 if ( pt_c < ind_c_min )
54 diff = ind_c_min - pt_c;
55 else if ( ind_c_max < pt_c )
56 diff = pt_c - ind_c_max;
62 template <typename Point, typename Indexable>
63 typename geometry::default_comparable_distance_result<Point, Indexable>::type
64 comparable_distance_near(Point const& pt, Indexable const& i)
66 return detail::sum_for_indexable<
69 typename tag<Indexable>::type,
70 detail::comparable_distance_near_tag,
71 dimension<Indexable>::value
75 }}}} // namespace boost::geometry::index::detail
77 #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_NEAR_HPP