Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:28

0001 // Boost.Geometry Index
0002 //
0003 // squared distance between point and nearest point of the box or point
0004 //
0005 // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
0006 //
0007 // This file was modified by Oracle on 2021.
0008 // Modifications copyright (c) 2021 Oracle and/or its affiliates.
0009 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0010 //
0011 // Use, modification and distribution is subject to the Boost Software License,
0012 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0013 // http://www.boost.org/LICENSE_1_0.txt)
0014 
0015 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_NEAR_HPP
0016 #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_NEAR_HPP
0017 
0018 #include <boost/geometry/algorithms/detail/comparable_distance/interface.hpp>
0019 #include <boost/geometry/core/access.hpp>
0020 
0021 #include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
0022 
0023 namespace boost { namespace geometry { namespace index { namespace detail {
0024 
0025 struct comparable_distance_near_tag {};
0026 
0027 template <
0028     typename Point,
0029     typename PointIndexable,
0030     size_t N>
0031 struct sum_for_indexable<Point, PointIndexable, point_tag, comparable_distance_near_tag, N>
0032 {
0033     typedef typename geometry::default_comparable_distance_result<Point, PointIndexable>::type result_type;
0034 
0035     inline static result_type apply(Point const& pt, PointIndexable const& i)
0036     {
0037         return geometry::comparable_distance(pt, i);
0038     }
0039 };
0040 
0041 template <
0042     typename Point,
0043     typename BoxIndexable,
0044     size_t DimensionIndex>
0045 struct sum_for_indexable_dimension<Point, BoxIndexable, box_tag, comparable_distance_near_tag, DimensionIndex>
0046 {
0047     typedef typename geometry::default_comparable_distance_result<Point, BoxIndexable>::type result_type;
0048 
0049     inline static result_type apply(Point const& pt, BoxIndexable const& i)
0050     {
0051         typedef typename coordinate_type<Point>::type point_coord_t;
0052         typedef typename coordinate_type<BoxIndexable>::type indexable_coord_t;
0053 
0054         point_coord_t pt_c = geometry::get<DimensionIndex>(pt);
0055         indexable_coord_t ind_c_min = geometry::get<geometry::min_corner, DimensionIndex>(i);
0056         indexable_coord_t ind_c_max = geometry::get<geometry::max_corner, DimensionIndex>(i);
0057 
0058         result_type diff = 0;
0059 
0060         if ( pt_c < ind_c_min )
0061             diff = ind_c_min - pt_c;
0062         else if ( ind_c_max < pt_c )
0063             diff = pt_c - ind_c_max;
0064 
0065         return diff * diff;
0066     }
0067 };
0068 
0069 template <typename Point, typename Indexable>
0070 typename geometry::default_comparable_distance_result<Point, Indexable>::type
0071 comparable_distance_near(Point const& pt, Indexable const& i)
0072 {
0073     return detail::sum_for_indexable<
0074         Point,
0075         Indexable,
0076         typename tag<Indexable>::type,
0077         detail::comparable_distance_near_tag,
0078         dimension<Indexable>::value
0079     >::apply(pt, i);
0080 }
0081 
0082 }}}} // namespace boost::geometry::index::detail
0083 
0084 #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_NEAR_HPP