within and distance_sqr removed from index/algorithms. geometry::covered_by used in remove visitor.

[SVN r73370]
This commit is contained in:
Adam Wulkiewicz
2011-07-26 02:21:17 +00:00
parent 40a9cd095f
commit b65c697cad
3 changed files with 2 additions and 211 deletions

View File

@@ -1,78 +0,0 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
//
// Boost.SpatialIndex - n-dimensional distance_sqr between points
//
// Copyright 2011 Adam Wulkiewicz.
// 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_EXTENSIONS_INDEX_ALGORITHMS_DISTANCE_SQR_HPP
#define BOOST_GEOMETRY_EXTENSIONS_INDEX_ALGORITHMS_DISTANCE_SQR_HPP
namespace boost { namespace geometry { namespace index {
template <typename Point1, typename Point2>
class default_distance_sqr_result
{
typedef typename select_most_precise<
typename traits::coordinate_type<Point1>::type,
long double
>::type intermediate_type;
public:
typedef typename select_most_precise<
typename traits::coordinate_type<Point2>::type,
intermediate_type
>::type type;
};
namespace detail {
template <typename Point1, typename Point2, size_t CurrentDimension>
struct distance_sqr_for_each_dimension
{
BOOST_STATIC_ASSERT(0 < CurrentDimension);
BOOST_STATIC_ASSERT(CurrentDimension <= traits::dimension<Point1>::value);
typedef typename default_distance_sqr_result<Point1, Point2>::type result_type;
static inline result_type apply(Point1 const& p1, Point2 const& p2)
{
result_type temp = geometry::get<CurrentDimension - 1>(p1) - geometry::get<CurrentDimension - 1>(p2);
return distance_sqr_for_each_dimension<Point1, Point2, CurrentDimension - 1>::apply(p1, p2) +
temp * temp;
}
};
template <typename Point1, typename Point2>
struct distance_sqr_for_each_dimension<Point1, Point2, 1>
{
BOOST_STATIC_ASSERT(1 <= traits::dimension<Point1>::value);
typedef typename default_distance_sqr_result<Point1, Point2>::type result_type;
static inline result_type apply(Point1 const& p1, Point2 const& p2)
{
result_type temp = geometry::get<0>(p1) - geometry::get<0>(p2);
return temp * temp;
}
};
} // namespace detail
template <typename Point1, typename Point2>
typename default_distance_sqr_result<Point1, Point2>::type distance_sqr(Point1 const& p1, Point2 const& p2)
{
BOOST_STATIC_ASSERT(traits::dimension<Point1>::value == traits::dimension<Point2>::value);
return detail::distance_sqr_for_each_dimension<
Point1,
Point2,
index::traits::dimension<Point1>::value
>::apply(p1, p2);
}
}}} // namespace boost::geometry::index
#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_ALGORITHMS_DISTANCE_SQR_HPP

View File

@@ -1,131 +0,0 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
//
// Boost.SpatialIndex - n-dimensional within box
//
// Copyright 2011 Adam Wulkiewicz.
// 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_EXTENSIONS_INDEX_ALGORITHMS_WITHIN_HPP
#define BOOST_GEOMETRY_EXTENSIONS_INDEX_ALGORITHMS_WITHIN_HPP
namespace boost { namespace geometry { namespace index {
namespace dispatch {
template <size_t Corner, size_t DimensionIndex, typename Indexable, typename IndexableTag>
struct within_compare
{
// TODO: awulkiew - static assert?
};
template <size_t DimensionIndex, typename Indexable>
struct within_compare<min_corner, DimensionIndex, Indexable, box_tag>
{
template <typename Box>
static inline bool apply(Indexable const& b1, Box const& b2)
{
return index::get<min_corner, DimensionIndex>(b2) <= index::get<min_corner, DimensionIndex>(b1);
}
};
template <size_t DimensionIndex, typename Indexable>
struct within_compare<max_corner, DimensionIndex, Indexable, box_tag>
{
template <typename Box>
static inline bool apply(Indexable const& b1, Box const& b2)
{
return index::get<max_corner, DimensionIndex>(b1) <= index::get<max_corner, DimensionIndex>(b2);
}
};
template <size_t DimensionIndex, typename Indexable>
struct within_compare<min_corner, DimensionIndex, Indexable, point_tag>
{
template <typename Box>
static inline bool apply(Indexable const& p, Box const& b)
{
return index::get<min_corner, DimensionIndex>(b) <= geometry::get<DimensionIndex>(p);
}
};
template <size_t DimensionIndex, typename Indexable>
struct within_compare<max_corner, DimensionIndex, Indexable, point_tag>
{
template <typename Box>
static inline bool apply(Indexable const& p, Box const& b)
{
return geometry::get<DimensionIndex>(p) <= index::get<max_corner, DimensionIndex>(b);
}
};
} // namespace dispatch
namespace detail {
template <typename Box, typename Indexable, size_t CurrentDimension>
struct within_for_each_dimension
{
BOOST_STATIC_ASSERT(0 < CurrentDimension);
BOOST_STATIC_ASSERT(CurrentDimension <= traits::dimension<Box>::value);
BOOST_STATIC_ASSERT(traits::dimension<Indexable>::value == traits::dimension<Box>::value);
static inline bool apply(Indexable const& i, Box const& b)
{
return
within_for_each_dimension<
Box,
Indexable,
CurrentDimension - 1
>::apply(i, b) &&
dispatch::within_compare<
min_corner,
CurrentDimension - 1,
Indexable,
typename traits::tag<Indexable>::type
>::apply(i, b) &&
dispatch::within_compare<
max_corner,
CurrentDimension - 1,
Indexable,
typename traits::tag<Indexable>::type
>::apply(i, b);
}
};
template <typename Box, typename Indexable>
struct within_for_each_dimension<Box, Indexable, 1>
{
BOOST_STATIC_ASSERT(1 <= traits::dimension<Box>::value);
BOOST_STATIC_ASSERT(traits::dimension<Indexable>::value == traits::dimension<Box>::value);
static inline bool apply(Indexable const& i, Box const& b)
{
return
dispatch::within_compare<
min_corner,
0,
Indexable,
typename traits::tag<Indexable>::type
>::apply(i, b) &&
dispatch::within_compare<
max_corner,
0,
Indexable,
typename traits::tag<Indexable>::type
>::apply(i, b);
}
};
} // namespace detail
template <typename Box, typename Indexable>
bool within(Indexable const& i, Box const& box)
{
return detail::within_for_each_dimension<Box, Indexable, traits::dimension<Box>::value>::apply(i, box);
}
}}} // namespace boost::geometry::index
#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_ALGORITHMS_WITHIN_HPP

View File

@@ -14,7 +14,7 @@
#include <boost/geometry/extensions/index/rtree/visitors/is_leaf.hpp>
#include <boost/geometry/extensions/index/algorithms/within.hpp>
#include <boost/geometry/algorithms/covered_by.hpp>
namespace boost { namespace geometry { namespace index {
@@ -60,7 +60,7 @@ public:
size_t child_node_index = 0;
for ( ; child_node_index < children.size() ; ++child_node_index )
{
if ( index::within(m_tr(m_value), children[child_node_index].first) )
if ( geometry::covered_by(m_tr(m_value), children[child_node_index].first) )
{
// next traversing step
traverse_apply_visitor(n, child_node_index);