// Boost.Geometry Index // // squared distance between point and furthest point of the box or point // // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland. // // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP #include #include namespace boost { namespace geometry { namespace index { namespace detail { // minmaxdist component struct comparable_distance_far_tag {}; template < typename Point, typename BoxIndexable, size_t DimensionIndex> struct sum_for_indexable_dimension { typedef typename geometry::default_comparable_distance_result::type result_type; inline static result_type apply(Point const& pt, BoxIndexable const& i) { typedef typename coordinate_type::type point_coord_t; typedef typename coordinate_type::type indexable_coord_t; point_coord_t pt_c = geometry::get(pt); indexable_coord_t ind_c_min = geometry::get(i); indexable_coord_t ind_c_max = geometry::get(i); result_type further_diff = 0; if ( (ind_c_min + ind_c_max) / 2 <= pt_c ) further_diff = pt_c - ind_c_min; else further_diff = detail::diff_abs(pt_c, ind_c_max); // unsigned values protection return further_diff * further_diff; } }; template typename geometry::default_comparable_distance_result::type comparable_distance_far(Point const& pt, Indexable const& i) { return detail::sum_for_indexable< Point, Indexable, typename tag::type, detail::comparable_distance_far_tag, dimension::value >::apply(pt, i); } }}}} // namespace boost::geometry::index::detail #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP