123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_MINMAXDIST_HPP
- #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_MINMAXDIST_HPP
- #include <boost/geometry/algorithms/distance.hpp>
- #include <boost/geometry/algorithms/comparable_distance.hpp>
- #include <boost/geometry/core/static_assert.hpp>
- #include <boost/geometry/index/detail/algorithms/diff_abs.hpp>
- #include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
- #include <boost/geometry/index/detail/algorithms/smallest_for_indexable.hpp>
- namespace boost { namespace geometry { namespace index { namespace detail {
- struct minmaxdist_tag {};
- template <
- typename Point,
- typename BoxIndexable,
- size_t DimensionIndex>
- struct smallest_for_indexable_dimension<Point, BoxIndexable, box_tag, minmaxdist_tag, DimensionIndex>
- {
- typedef typename geometry::default_comparable_distance_result<Point, BoxIndexable>::type result_type;
- inline static result_type apply(Point const& pt, BoxIndexable const& i, result_type const& maxd)
- {
- typedef typename coordinate_type<Point>::type point_coord_t;
- typedef typename coordinate_type<BoxIndexable>::type indexable_coord_t;
- point_coord_t pt_c = geometry::get<DimensionIndex>(pt);
- indexable_coord_t ind_c_min = geometry::get<geometry::min_corner, DimensionIndex>(i);
- indexable_coord_t ind_c_max = geometry::get<geometry::max_corner, DimensionIndex>(i);
- indexable_coord_t ind_c_avg = ind_c_min + (ind_c_max - ind_c_min) / 2;
-
-
-
- result_type closer_comp = 0;
- if ( pt_c <= ind_c_avg )
- closer_comp = detail::diff_abs(pt_c, ind_c_min);
- else
- closer_comp = ind_c_max - pt_c;
- result_type further_comp = 0;
- if ( ind_c_avg <= pt_c )
- further_comp = pt_c - ind_c_min;
- else
- further_comp = detail::diff_abs(pt_c, ind_c_max);
- return (maxd + closer_comp * closer_comp) - further_comp * further_comp;
- }
- };
- template <typename Point, typename Indexable, typename IndexableTag>
- struct minmaxdist_impl
- {
- BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
- "Not implemented for this Indexable type.",
- Point, Indexable, IndexableTag);
- };
- template <typename Point, typename Indexable>
- struct minmaxdist_impl<Point, Indexable, point_tag>
- {
- typedef typename geometry::default_comparable_distance_result<Point, Indexable>::type result_type;
- inline static result_type apply(Point const& pt, Indexable const& i)
- {
- return geometry::comparable_distance(pt, i);
- }
- };
- template <typename Point, typename Indexable>
- struct minmaxdist_impl<Point, Indexable, box_tag>
- {
- typedef typename geometry::default_comparable_distance_result<Point, Indexable>::type result_type;
- inline static result_type apply(Point const& pt, Indexable const& i)
- {
- result_type maxd = geometry::comparable_distance(pt, i);
- return smallest_for_indexable<
- Point,
- Indexable,
- box_tag,
- minmaxdist_tag,
- dimension<Indexable>::value
- >::apply(pt, i, maxd);
- }
- };
- template <typename Point, typename Indexable>
- typename geometry::default_comparable_distance_result<Point, Indexable>::type
- minmaxdist(Point const& pt, Indexable const& i)
- {
- return detail::minmaxdist_impl<
- Point,
- Indexable,
- typename tag<Indexable>::type
- >::apply(pt, i);
- }
- }}}}
- #endif
|