add boost on mac
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// n-dimensional bounds
|
||||
//
|
||||
// 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_BOUNDS_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_BOUNDS_HPP
|
||||
|
||||
#include <boost/geometry/index/detail/bounded_view.hpp>
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
namespace dispatch {
|
||||
|
||||
template <typename Geometry,
|
||||
typename Bounds,
|
||||
typename TagGeometry = typename geometry::tag<Geometry>::type,
|
||||
typename TagBounds = typename geometry::tag<Bounds>::type>
|
||||
struct bounds
|
||||
{
|
||||
static inline void apply(Geometry const& g, Bounds & b)
|
||||
{
|
||||
geometry::convert(g, b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Geometry, typename Bounds>
|
||||
struct bounds<Geometry, Bounds, segment_tag, box_tag>
|
||||
{
|
||||
static inline void apply(Geometry const& g, Bounds & b)
|
||||
{
|
||||
index::detail::bounded_view<Geometry, Bounds> v(g);
|
||||
geometry::convert(v, b);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dispatch
|
||||
|
||||
template <typename Geometry, typename Bounds>
|
||||
inline void bounds(Geometry const& g, Bounds & b)
|
||||
{
|
||||
concepts::check_concepts_and_equal_dimensions<Geometry const, Bounds>();
|
||||
dispatch::bounds<Geometry, Bounds>::apply(g, b);
|
||||
}
|
||||
|
||||
namespace dispatch {
|
||||
|
||||
template <typename Geometry,
|
||||
typename TagGeometry = typename geometry::tag<Geometry>::type>
|
||||
struct return_ref_or_bounds
|
||||
{
|
||||
typedef Geometry const& result_type;
|
||||
|
||||
static inline result_type apply(Geometry const& g)
|
||||
{
|
||||
return g;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Geometry>
|
||||
struct return_ref_or_bounds<Geometry, segment_tag>
|
||||
{
|
||||
typedef typename point_type<Geometry>::type point_type;
|
||||
typedef geometry::model::box<point_type> bounds_type;
|
||||
typedef index::detail::bounded_view<Geometry, bounds_type> result_type;
|
||||
|
||||
static inline result_type apply(Geometry const& g)
|
||||
{
|
||||
return result_type(g);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dispatch
|
||||
|
||||
template <typename Geometry>
|
||||
inline
|
||||
typename dispatch::return_ref_or_bounds<Geometry>::result_type
|
||||
return_ref_or_bounds(Geometry const& g)
|
||||
{
|
||||
return dispatch::return_ref_or_bounds<Geometry>::apply(g);
|
||||
}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_BOUNDS_HPP
|
||||
@@ -0,0 +1,77 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// squared distance between point and centroid 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_CENTROID_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_CENTROID_HPP
|
||||
|
||||
#include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
|
||||
#include <boost/geometry/index/detail/algorithms/diff_abs.hpp>
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
struct comparable_distance_centroid_tag {};
|
||||
|
||||
template <
|
||||
typename Point,
|
||||
typename PointIndexable,
|
||||
size_t N>
|
||||
struct sum_for_indexable<Point, PointIndexable, point_tag, comparable_distance_centroid_tag, N>
|
||||
{
|
||||
typedef typename geometry::default_comparable_distance_result<Point, PointIndexable>::type result_type;
|
||||
|
||||
inline static result_type apply(Point const& pt, PointIndexable const& i)
|
||||
{
|
||||
return geometry::comparable_distance(pt, i);
|
||||
}
|
||||
};
|
||||
|
||||
template <
|
||||
typename Point,
|
||||
typename BoxIndexable,
|
||||
size_t DimensionIndex>
|
||||
struct sum_for_indexable_dimension<Point, BoxIndexable, box_tag, comparable_distance_centroid_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)
|
||||
{
|
||||
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;
|
||||
// TODO: awulkiew - is (ind_c_min + ind_c_max) / 2 safe?
|
||||
|
||||
result_type diff = detail::diff_abs(ind_c_avg, pt_c);
|
||||
|
||||
return diff * diff;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Point, typename Indexable>
|
||||
typename geometry::default_comparable_distance_result<Point, Indexable>::type
|
||||
comparable_distance_centroid(Point const& pt, Indexable const& i)
|
||||
{
|
||||
return detail::sum_for_indexable<
|
||||
Point,
|
||||
Indexable,
|
||||
typename tag<Indexable>::type,
|
||||
detail::comparable_distance_centroid_tag,
|
||||
dimension<Indexable>::value
|
||||
>::apply(pt, i);
|
||||
}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_CENTROID_HPP
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
// 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 <boost/geometry/index/detail/algorithms/diff_abs.hpp>
|
||||
#include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
|
||||
|
||||
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<Point, BoxIndexable, box_tag, comparable_distance_far_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)
|
||||
{
|
||||
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);
|
||||
|
||||
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 Point, typename Indexable>
|
||||
typename geometry::default_comparable_distance_result<Point, Indexable>::type
|
||||
comparable_distance_far(Point const& pt, Indexable const& i)
|
||||
{
|
||||
return detail::sum_for_indexable<
|
||||
Point,
|
||||
Indexable,
|
||||
typename tag<Indexable>::type,
|
||||
detail::comparable_distance_far_tag,
|
||||
dimension<Indexable>::value
|
||||
>::apply(pt, i);
|
||||
}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP
|
||||
@@ -0,0 +1,77 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// squared distance between point and nearest 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_NEAR_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_NEAR_HPP
|
||||
|
||||
#include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
struct comparable_distance_near_tag {};
|
||||
|
||||
template <
|
||||
typename Point,
|
||||
typename PointIndexable,
|
||||
size_t N>
|
||||
struct sum_for_indexable<Point, PointIndexable, point_tag, comparable_distance_near_tag, N>
|
||||
{
|
||||
typedef typename geometry::default_comparable_distance_result<Point, PointIndexable>::type result_type;
|
||||
|
||||
inline static result_type apply(Point const& pt, PointIndexable const& i)
|
||||
{
|
||||
return geometry::comparable_distance(pt, i);
|
||||
}
|
||||
};
|
||||
|
||||
template <
|
||||
typename Point,
|
||||
typename BoxIndexable,
|
||||
size_t DimensionIndex>
|
||||
struct sum_for_indexable_dimension<Point, BoxIndexable, box_tag, comparable_distance_near_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)
|
||||
{
|
||||
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);
|
||||
|
||||
result_type diff = 0;
|
||||
|
||||
if ( pt_c < ind_c_min )
|
||||
diff = ind_c_min - pt_c;
|
||||
else if ( ind_c_max < pt_c )
|
||||
diff = pt_c - ind_c_max;
|
||||
|
||||
return diff * diff;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Point, typename Indexable>
|
||||
typename geometry::default_comparable_distance_result<Point, Indexable>::type
|
||||
comparable_distance_near(Point const& pt, Indexable const& i)
|
||||
{
|
||||
return detail::sum_for_indexable<
|
||||
Point,
|
||||
Indexable,
|
||||
typename tag<Indexable>::type,
|
||||
detail::comparable_distance_near_tag,
|
||||
dimension<Indexable>::value
|
||||
>::apply(pt, i);
|
||||
}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_NEAR_HPP
|
||||
@@ -0,0 +1,87 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// n-dimensional content (hypervolume) - 2d area, 3d volume, ...
|
||||
//
|
||||
// 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_CONTENT_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
template <typename Indexable>
|
||||
struct default_content_result
|
||||
{
|
||||
typedef typename select_most_precise<
|
||||
typename coordinate_type<Indexable>::type,
|
||||
long double
|
||||
>::type type;
|
||||
};
|
||||
|
||||
namespace dispatch {
|
||||
|
||||
template <typename Box,
|
||||
std::size_t CurrentDimension = dimension<Box>::value>
|
||||
struct content_box
|
||||
{
|
||||
BOOST_STATIC_ASSERT(0 < CurrentDimension);
|
||||
|
||||
static inline typename detail::default_content_result<Box>::type apply(Box const& b)
|
||||
{
|
||||
return content_box<Box, CurrentDimension - 1>::apply(b) *
|
||||
( get<max_corner, CurrentDimension - 1>(b) - get<min_corner, CurrentDimension - 1>(b) );
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Box>
|
||||
struct content_box<Box, 1>
|
||||
{
|
||||
static inline typename detail::default_content_result<Box>::type apply(Box const& b)
|
||||
{
|
||||
return get<max_corner, 0>(b) - get<min_corner, 0>(b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Indexable, typename Tag>
|
||||
struct content
|
||||
{
|
||||
BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THIS_INDEXABLE_AND_TAG, (Indexable, Tag));
|
||||
};
|
||||
|
||||
template <typename Indexable>
|
||||
struct content<Indexable, point_tag>
|
||||
{
|
||||
static typename detail::default_content_result<Indexable>::type apply(Indexable const&)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Indexable>
|
||||
struct content<Indexable, box_tag>
|
||||
{
|
||||
static typename default_content_result<Indexable>::type apply(Indexable const& b)
|
||||
{
|
||||
return dispatch::content_box<Indexable>::apply(b);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dispatch
|
||||
|
||||
template <typename Indexable>
|
||||
typename default_content_result<Indexable>::type content(Indexable const& b)
|
||||
{
|
||||
return dispatch::content
|
||||
<
|
||||
Indexable,
|
||||
typename tag<Indexable>::type
|
||||
>::apply(b);
|
||||
}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP
|
||||
@@ -0,0 +1,39 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// Abs of difference
|
||||
//
|
||||
// Copyright (c) 2011-2013 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_DIFF_ABS_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_DIFF_ABS_HPP
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
template <typename T>
|
||||
inline T diff_abs_dispatch(T const& v1, T const& v2, boost::mpl::bool_<true> const& /*is_integral*/)
|
||||
{
|
||||
return v1 < v2 ? v2 - v1 : v1 - v2;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T diff_abs_dispatch(T const& v1, T const& v2, boost::mpl::bool_<false> const& /*is_integral*/)
|
||||
{
|
||||
return ::fabs(v1 - v2);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T diff_abs(T const& v1, T const& v2)
|
||||
{
|
||||
typedef boost::mpl::bool_<
|
||||
boost::is_integral<T>::value
|
||||
> is_integral;
|
||||
return diff_abs_dispatch(v1, v2, is_integral());
|
||||
}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_DIFF_ABS_HPP
|
||||
@@ -0,0 +1,51 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// boxes union/intersection area/volume
|
||||
//
|
||||
// Copyright (c) 2011-2018 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_INTERSECTION_CONTENT_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP
|
||||
|
||||
#include <boost/geometry/algorithms/detail/disjoint/box_box.hpp>
|
||||
#include <boost/geometry/algorithms/detail/overlay/intersection_box_box.hpp>
|
||||
|
||||
#include <boost/geometry/index/detail/algorithms/content.hpp>
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
/**
|
||||
* \brief Compute the area of the intersection of b1 and b2
|
||||
*/
|
||||
template <typename Box>
|
||||
inline typename default_content_result<Box>::type intersection_content(Box const& box1, Box const& box2)
|
||||
{
|
||||
typedef typename strategy::disjoint::services::default_strategy
|
||||
<
|
||||
Box, Box
|
||||
>::type strategy_type;
|
||||
|
||||
bool const intersects = ! geometry::detail::disjoint::disjoint_box_box(box1, box2, strategy_type());
|
||||
|
||||
if ( intersects )
|
||||
{
|
||||
Box box_intersection;
|
||||
bool const ok = geometry::detail::intersection::intersection_box_box
|
||||
<
|
||||
0, geometry::dimension<Box>::value
|
||||
>::apply(box1, box2, 0, box_intersection, 0);
|
||||
if ( ok )
|
||||
{
|
||||
return index::detail::content(box_intersection);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP
|
||||
@@ -0,0 +1,91 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// n-dimensional Indexable validity check
|
||||
//
|
||||
// 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_IS_VALID_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_IS_VALID_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
namespace dispatch {
|
||||
|
||||
template <typename Box,
|
||||
std::size_t Dimension = geometry::dimension<Box>::value>
|
||||
struct is_valid_box
|
||||
{
|
||||
static inline bool apply(Box const& b)
|
||||
{
|
||||
return is_valid_box<Box, Dimension - 1>::apply(b) &&
|
||||
( get<min_corner, Dimension - 1>(b) <= get<max_corner, Dimension - 1>(b) );
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Box>
|
||||
struct is_valid_box<Box, 1>
|
||||
{
|
||||
static inline bool apply(Box const& b)
|
||||
{
|
||||
return get<min_corner, 0>(b) <= get<max_corner, 0>(b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Indexable,
|
||||
typename Tag = typename geometry::tag<Indexable>::type>
|
||||
struct is_valid
|
||||
{
|
||||
BOOST_MPL_ASSERT_MSG(
|
||||
(false),
|
||||
NOT_IMPLEMENTED_FOR_THIS_INDEXABLE,
|
||||
(is_valid));
|
||||
};
|
||||
|
||||
template <typename Indexable>
|
||||
struct is_valid<Indexable, point_tag>
|
||||
{
|
||||
static inline bool apply(Indexable const&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Indexable>
|
||||
struct is_valid<Indexable, box_tag>
|
||||
{
|
||||
static inline bool apply(Indexable const& b)
|
||||
{
|
||||
return dispatch::is_valid_box<Indexable>::apply(b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Indexable>
|
||||
struct is_valid<Indexable, segment_tag>
|
||||
{
|
||||
static inline bool apply(Indexable const&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dispatch
|
||||
|
||||
template <typename Indexable>
|
||||
inline bool is_valid(Indexable const& b)
|
||||
{
|
||||
// CONSIDER: detection of NaNs
|
||||
// e.g. by comparison of b with copy of b
|
||||
|
||||
return dispatch::is_valid<Indexable>::apply(b);
|
||||
}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_DETAIL_INDEX_ALGORITHMS_IS_VALID_HPP
|
||||
169
macx64/include/boost/geometry/index/detail/algorithms/margin.hpp
Normal file
169
macx64/include/boost/geometry/index/detail/algorithms/margin.hpp
Normal file
@@ -0,0 +1,169 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// n-dimensional box's margin value (hypersurface), 2d perimeter, 3d surface, etc...
|
||||
//
|
||||
// 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_MARGIN_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_MARGIN_HPP
|
||||
|
||||
// WARNING! comparable_margin() will work only if the same Geometries are compared
|
||||
// so it shouldn't be used in the case of Variants!
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
template <typename Box>
|
||||
struct default_margin_result
|
||||
{
|
||||
typedef typename select_most_precise<
|
||||
typename coordinate_type<Box>::type,
|
||||
long double
|
||||
>::type type;
|
||||
};
|
||||
|
||||
//template <typename Box,
|
||||
// std::size_t CurrentDimension,
|
||||
// std::size_t EdgeDimension = dimension<Box>::value>
|
||||
//struct margin_for_each_edge
|
||||
//{
|
||||
// BOOST_STATIC_ASSERT(0 < CurrentDimension);
|
||||
// BOOST_STATIC_ASSERT(0 < EdgeDimension);
|
||||
//
|
||||
// static inline typename default_margin_result<Box>::type apply(Box const& b)
|
||||
// {
|
||||
// return margin_for_each_edge<Box, CurrentDimension, EdgeDimension - 1>::apply(b) *
|
||||
// ( geometry::get<max_corner, EdgeDimension - 1>(b) - geometry::get<min_corner, EdgeDimension - 1>(b) );
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//template <typename Box, std::size_t CurrentDimension>
|
||||
//struct margin_for_each_edge<Box, CurrentDimension, CurrentDimension>
|
||||
//{
|
||||
// BOOST_STATIC_ASSERT(0 < CurrentDimension);
|
||||
//
|
||||
// static inline typename default_margin_result<Box>::type apply(Box const& b)
|
||||
// {
|
||||
// return margin_for_each_edge<Box, CurrentDimension, CurrentDimension - 1>::apply(b);
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//template <typename Box, std::size_t CurrentDimension>
|
||||
//struct margin_for_each_edge<Box, CurrentDimension, 1>
|
||||
//{
|
||||
// BOOST_STATIC_ASSERT(0 < CurrentDimension);
|
||||
//
|
||||
// static inline typename default_margin_result<Box>::type apply(Box const& b)
|
||||
// {
|
||||
// return geometry::get<max_corner, 0>(b) - geometry::get<min_corner, 0>(b);
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//template <typename Box>
|
||||
//struct margin_for_each_edge<Box, 1, 1>
|
||||
//{
|
||||
// static inline typename default_margin_result<Box>::type apply(Box const& /*b*/)
|
||||
// {
|
||||
// return 1;
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//template <typename Box,
|
||||
// std::size_t CurrentDimension = dimension<Box>::value>
|
||||
//struct margin_for_each_dimension
|
||||
//{
|
||||
// BOOST_STATIC_ASSERT(0 < CurrentDimension);
|
||||
//
|
||||
// static inline typename default_margin_result<Box>::type apply(Box const& b)
|
||||
// {
|
||||
// return margin_for_each_dimension<Box, CurrentDimension - 1>::apply(b) +
|
||||
// margin_for_each_edge<Box, CurrentDimension>::apply(b);
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//template <typename Box>
|
||||
//struct margin_for_each_dimension<Box, 1>
|
||||
//{
|
||||
// static inline typename default_margin_result<Box>::type apply(Box const& b)
|
||||
// {
|
||||
// return margin_for_each_edge<Box, 1>::apply(b);
|
||||
// }
|
||||
//};
|
||||
|
||||
// TODO - test if this definition of margin is ok for Dimension > 2
|
||||
// Now it's sum of edges lengths
|
||||
// maybe margin_for_each_dimension should be used to get more or less hypersurface?
|
||||
|
||||
template <typename Box,
|
||||
std::size_t CurrentDimension = dimension<Box>::value>
|
||||
struct simple_margin_for_each_dimension
|
||||
{
|
||||
BOOST_STATIC_ASSERT(0 < CurrentDimension);
|
||||
|
||||
static inline typename default_margin_result<Box>::type apply(Box const& b)
|
||||
{
|
||||
return simple_margin_for_each_dimension<Box, CurrentDimension - 1>::apply(b) +
|
||||
geometry::get<max_corner, CurrentDimension - 1>(b) - geometry::get<min_corner, CurrentDimension - 1>(b);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Box>
|
||||
struct simple_margin_for_each_dimension<Box, 1>
|
||||
{
|
||||
static inline typename default_margin_result<Box>::type apply(Box const& b)
|
||||
{
|
||||
return geometry::get<max_corner, 0>(b) - geometry::get<min_corner, 0>(b);
|
||||
}
|
||||
};
|
||||
|
||||
namespace dispatch {
|
||||
|
||||
template <typename Geometry, typename Tag>
|
||||
struct comparable_margin
|
||||
{
|
||||
BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THIS_GEOMETRY, (Geometry, Tag));
|
||||
};
|
||||
|
||||
template <typename Geometry>
|
||||
struct comparable_margin<Geometry, point_tag>
|
||||
{
|
||||
typedef typename default_margin_result<Geometry>::type result_type;
|
||||
|
||||
static inline result_type apply(Geometry const& ) { return 0; }
|
||||
};
|
||||
|
||||
template <typename Box>
|
||||
struct comparable_margin<Box, box_tag>
|
||||
{
|
||||
typedef typename default_margin_result<Box>::type result_type;
|
||||
|
||||
static inline result_type apply(Box const& g)
|
||||
{
|
||||
//return detail::margin_for_each_dimension<Box>::apply(g);
|
||||
return detail::simple_margin_for_each_dimension<Box>::apply(g);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dispatch
|
||||
|
||||
template <typename Geometry>
|
||||
typename default_margin_result<Geometry>::type comparable_margin(Geometry const& g)
|
||||
{
|
||||
return dispatch::comparable_margin<
|
||||
Geometry,
|
||||
typename tag<Geometry>::type
|
||||
>::apply(g);
|
||||
}
|
||||
|
||||
//template <typename Box>
|
||||
//typename default_margin_result<Box>::type margin(Box const& b)
|
||||
//{
|
||||
// return 2 * detail::margin_for_each_dimension<Box>::apply(b);
|
||||
//}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_MARGIN_HPP
|
||||
@@ -0,0 +1,119 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// minmaxdist used in R-tree k nearest neighbors query
|
||||
//
|
||||
// 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_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/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;
|
||||
// TODO: awulkiew - is (ind_c_min + ind_c_max) / 2 safe?
|
||||
|
||||
// TODO: awulkiew - optimize! don't calculate 2x pt_c <= ind_c_avg
|
||||
// take particular case pt_c == ind_c_avg into account
|
||||
|
||||
result_type closer_comp = 0;
|
||||
if ( pt_c <= ind_c_avg )
|
||||
closer_comp = detail::diff_abs(pt_c, ind_c_min); // unsigned values protection
|
||||
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); // unsigned values protection
|
||||
|
||||
return (maxd + closer_comp * closer_comp) - further_comp * further_comp;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Point, typename Indexable, typename IndexableTag>
|
||||
struct minmaxdist_impl
|
||||
{
|
||||
BOOST_MPL_ASSERT_MSG(
|
||||
(false),
|
||||
NOT_IMPLEMENTED_FOR_THIS_INDEXABLE_TAG_TYPE,
|
||||
(minmaxdist_impl));
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This is comparable distace.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_MINMAXDIST_HPP
|
||||
@@ -0,0 +1,62 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// Copyright (c) 2017 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_NTH_ELEMENT_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_NTH_ELEMENT_HPP
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
// See https://svn.boost.org/trac/boost/ticket/12861
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58800
|
||||
// https://gcc.gnu.org/develop.html#timeline
|
||||
// 20120920 4.7.2 - no bug
|
||||
// 20130322 4.8.0 - no bug
|
||||
// 20130411 4.7.3 - no bug
|
||||
// 20130531 4.8.1 - no bug
|
||||
// 20131016 4.8.2 - bug
|
||||
// 20140422 4.9.0 - fixed
|
||||
// 20140522 4.8.3 - fixed
|
||||
// 20140612 4.7.4 - fixed
|
||||
// 20140716 4.9.1 - fixed
|
||||
#if defined(__GLIBCXX__) && (__GLIBCXX__ == 20131016)
|
||||
|
||||
#warning "std::nth_element replaced with std::sort, libstdc++ bug workaround.";
|
||||
|
||||
template <typename RandomIt>
|
||||
void nth_element(RandomIt first, RandomIt , RandomIt last)
|
||||
{
|
||||
std::sort(first, last);
|
||||
}
|
||||
|
||||
template <typename RandomIt, typename Compare>
|
||||
void nth_element(RandomIt first, RandomIt , RandomIt last, Compare comp)
|
||||
{
|
||||
std::sort(first, last, comp);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template <typename RandomIt>
|
||||
void nth_element(RandomIt first, RandomIt nth, RandomIt last)
|
||||
{
|
||||
std::nth_element(first, nth, last);
|
||||
}
|
||||
|
||||
template <typename RandomIt, typename Compare>
|
||||
void nth_element(RandomIt first, RandomIt nth, RandomIt last, Compare comp)
|
||||
{
|
||||
std::nth_element(first, nth, last, comp);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_NTH_ELEMENT_HPP
|
||||
@@ -0,0 +1,123 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// n-dimensional box-linestring intersection
|
||||
//
|
||||
// Copyright (c) 2011-2017 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_PATH_INTERSECTION_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_PATH_INTERSECTION_HPP
|
||||
|
||||
|
||||
#include <boost/geometry/index/detail/algorithms/segment_intersection.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/default_length_result.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
namespace dispatch {
|
||||
|
||||
template <typename Indexable, typename Geometry, typename IndexableTag, typename GeometryTag>
|
||||
struct path_intersection
|
||||
{
|
||||
BOOST_MPL_ASSERT_MSG((false), NOT_IMPLEMENTED_FOR_THIS_GEOMETRY_OR_INDEXABLE, (path_intersection));
|
||||
};
|
||||
|
||||
// TODO: FP type must be used as a relative distance type!
|
||||
// and default_distance_result can be some user-defined int type
|
||||
// BUT! This code is experimental and probably won't be released at all
|
||||
// since more flexible user-defined-nearest predicate should be added instead
|
||||
|
||||
template <typename Indexable, typename Segment>
|
||||
struct path_intersection<Indexable, Segment, box_tag, segment_tag>
|
||||
{
|
||||
typedef typename default_distance_result<typename point_type<Segment>::type>::type comparable_distance_type;
|
||||
|
||||
static inline bool apply(Indexable const& b, Segment const& segment, comparable_distance_type & comparable_distance)
|
||||
{
|
||||
typedef typename point_type<Segment>::type point_type;
|
||||
point_type p1, p2;
|
||||
geometry::detail::assign_point_from_index<0>(segment, p1);
|
||||
geometry::detail::assign_point_from_index<1>(segment, p2);
|
||||
return index::detail::segment_intersection(b, p1, p2, comparable_distance);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Indexable, typename Linestring>
|
||||
struct path_intersection<Indexable, Linestring, box_tag, linestring_tag>
|
||||
{
|
||||
typedef typename default_length_result<Linestring>::type comparable_distance_type;
|
||||
|
||||
static inline bool apply(Indexable const& b, Linestring const& path, comparable_distance_type & comparable_distance)
|
||||
{
|
||||
typedef typename ::boost::range_value<Linestring>::type point_type;
|
||||
typedef typename ::boost::range_const_iterator<Linestring>::type const_iterator;
|
||||
typedef typename ::boost::range_size<Linestring>::type size_type;
|
||||
|
||||
const size_type count = ::boost::size(path);
|
||||
|
||||
if ( count == 2 )
|
||||
{
|
||||
return index::detail::segment_intersection(b, *::boost::begin(path), *(::boost::begin(path)+1), comparable_distance);
|
||||
}
|
||||
else if ( 2 < count )
|
||||
{
|
||||
const_iterator it0 = ::boost::begin(path);
|
||||
const_iterator it1 = ::boost::begin(path) + 1;
|
||||
const_iterator last = ::boost::end(path);
|
||||
|
||||
comparable_distance = 0;
|
||||
|
||||
for ( ; it1 != last ; ++it0, ++it1 )
|
||||
{
|
||||
typename default_distance_result<point_type, point_type>::type
|
||||
dist = geometry::distance(*it0, *it1);
|
||||
|
||||
comparable_distance_type rel_dist;
|
||||
if ( index::detail::segment_intersection(b, *it0, *it1, rel_dist) )
|
||||
{
|
||||
comparable_distance += dist * rel_dist;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
comparable_distance += dist;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dispatch
|
||||
|
||||
template <typename Indexable, typename SegmentOrLinestring>
|
||||
struct default_path_intersection_distance_type
|
||||
{
|
||||
typedef typename dispatch::path_intersection<
|
||||
Indexable, SegmentOrLinestring,
|
||||
typename tag<Indexable>::type,
|
||||
typename tag<SegmentOrLinestring>::type
|
||||
>::comparable_distance_type type;
|
||||
};
|
||||
|
||||
template <typename Indexable, typename SegmentOrLinestring> inline
|
||||
bool path_intersection(Indexable const& b,
|
||||
SegmentOrLinestring const& path,
|
||||
typename default_path_intersection_distance_type<Indexable, SegmentOrLinestring>::type & comparable_distance)
|
||||
{
|
||||
// TODO check Indexable and Linestring concepts
|
||||
|
||||
return dispatch::path_intersection<
|
||||
Indexable, SegmentOrLinestring,
|
||||
typename tag<Indexable>::type,
|
||||
typename tag<SegmentOrLinestring>::type
|
||||
>::apply(b, path, comparable_distance);
|
||||
}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_PATH_INTERSECTION_HPP
|
||||
@@ -0,0 +1,146 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// n-dimensional box-segment intersection
|
||||
//
|
||||
// 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_SEGMENT_INTERSECTION_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SEGMENT_INTERSECTION_HPP
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
//template <typename Indexable, typename Point>
|
||||
//struct default_relative_distance_type
|
||||
//{
|
||||
// typedef typename select_most_precise<
|
||||
// typename select_most_precise<
|
||||
// typename coordinate_type<Indexable>::type,
|
||||
// typename coordinate_type<Point>::type
|
||||
// >::type,
|
||||
// float // TODO - use bigger type, calculated from the size of coordinate types
|
||||
// >::type type;
|
||||
//
|
||||
//
|
||||
// BOOST_MPL_ASSERT_MSG((!::boost::is_unsigned<type>::value),
|
||||
// THIS_TYPE_SHOULDNT_BE_UNSIGNED, (type));
|
||||
//};
|
||||
|
||||
namespace dispatch {
|
||||
|
||||
template <typename Box, typename Point, size_t I>
|
||||
struct box_segment_intersection_dim
|
||||
{
|
||||
BOOST_STATIC_ASSERT(0 <= dimension<Box>::value);
|
||||
BOOST_STATIC_ASSERT(0 <= dimension<Point>::value);
|
||||
BOOST_STATIC_ASSERT(I < size_t(dimension<Box>::value));
|
||||
BOOST_STATIC_ASSERT(I < size_t(dimension<Point>::value));
|
||||
BOOST_STATIC_ASSERT(dimension<Point>::value == dimension<Box>::value);
|
||||
|
||||
// WARNING! - RelativeDistance must be IEEE float for this to work
|
||||
|
||||
template <typename RelativeDistance>
|
||||
static inline bool apply(Box const& b, Point const& p0, Point const& p1,
|
||||
RelativeDistance & t_near, RelativeDistance & t_far)
|
||||
{
|
||||
RelativeDistance ray_d = geometry::get<I>(p1) - geometry::get<I>(p0);
|
||||
RelativeDistance tn = ( geometry::get<min_corner, I>(b) - geometry::get<I>(p0) ) / ray_d;
|
||||
RelativeDistance tf = ( geometry::get<max_corner, I>(b) - geometry::get<I>(p0) ) / ray_d;
|
||||
if ( tf < tn )
|
||||
::std::swap(tn, tf);
|
||||
|
||||
if ( t_near < tn )
|
||||
t_near = tn;
|
||||
if ( tf < t_far )
|
||||
t_far = tf;
|
||||
|
||||
return 0 <= t_far && t_near <= t_far;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Box, typename Point, size_t CurrentDimension>
|
||||
struct box_segment_intersection
|
||||
{
|
||||
BOOST_STATIC_ASSERT(0 < CurrentDimension);
|
||||
|
||||
typedef box_segment_intersection_dim<Box, Point, CurrentDimension - 1> for_dim;
|
||||
|
||||
template <typename RelativeDistance>
|
||||
static inline bool apply(Box const& b, Point const& p0, Point const& p1,
|
||||
RelativeDistance & t_near, RelativeDistance & t_far)
|
||||
{
|
||||
return box_segment_intersection<Box, Point, CurrentDimension - 1>::apply(b, p0, p1, t_near, t_far)
|
||||
&& for_dim::apply(b, p0, p1, t_near, t_far);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Box, typename Point>
|
||||
struct box_segment_intersection<Box, Point, 1>
|
||||
{
|
||||
typedef box_segment_intersection_dim<Box, Point, 0> for_dim;
|
||||
|
||||
template <typename RelativeDistance>
|
||||
static inline bool apply(Box const& b, Point const& p0, Point const& p1,
|
||||
RelativeDistance & t_near, RelativeDistance & t_far)
|
||||
{
|
||||
return for_dim::apply(b, p0, p1, t_near, t_far);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Indexable, typename Point, typename Tag>
|
||||
struct segment_intersection
|
||||
{
|
||||
BOOST_MPL_ASSERT_MSG((false), NOT_IMPLEMENTED_FOR_THIS_GEOMETRY, (segment_intersection));
|
||||
};
|
||||
|
||||
template <typename Indexable, typename Point>
|
||||
struct segment_intersection<Indexable, Point, point_tag>
|
||||
{
|
||||
BOOST_MPL_ASSERT_MSG((false), SEGMENT_POINT_INTERSECTION_UNAVAILABLE, (segment_intersection));
|
||||
};
|
||||
|
||||
template <typename Indexable, typename Point>
|
||||
struct segment_intersection<Indexable, Point, box_tag>
|
||||
{
|
||||
typedef dispatch::box_segment_intersection<Indexable, Point, dimension<Indexable>::value> impl;
|
||||
|
||||
template <typename RelativeDistance>
|
||||
static inline bool apply(Indexable const& b, Point const& p0, Point const& p1, RelativeDistance & relative_distance)
|
||||
{
|
||||
|
||||
// TODO: this ASSERT CHECK is wrong for user-defined CoordinateTypes!
|
||||
|
||||
static const bool check = !::boost::is_integral<RelativeDistance>::value;
|
||||
BOOST_MPL_ASSERT_MSG(check, RELATIVE_DISTANCE_MUST_BE_FLOATING_POINT_TYPE, (RelativeDistance));
|
||||
|
||||
RelativeDistance t_near = -(::std::numeric_limits<RelativeDistance>::max)();
|
||||
RelativeDistance t_far = (::std::numeric_limits<RelativeDistance>::max)();
|
||||
|
||||
return impl::apply(b, p0, p1, t_near, t_far) &&
|
||||
(t_near <= 1) &&
|
||||
( relative_distance = 0 < t_near ? t_near : 0, true );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dispatch
|
||||
|
||||
template <typename Indexable, typename Point, typename RelativeDistance> inline
|
||||
bool segment_intersection(Indexable const& b,
|
||||
Point const& p0,
|
||||
Point const& p1,
|
||||
RelativeDistance & relative_distance)
|
||||
{
|
||||
// TODO check Indexable and Point concepts
|
||||
|
||||
return dispatch::segment_intersection<
|
||||
Indexable, Point,
|
||||
typename tag<Indexable>::type
|
||||
>::apply(b, p0, p1, relative_distance);
|
||||
}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SEGMENT_INTERSECTION_HPP
|
||||
@@ -0,0 +1,80 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// Get smallest value calculated for indexable's dimensions, used in R-tree k nearest neighbors query
|
||||
//
|
||||
// Copyright (c) 2011-2013 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_SMALLEST_FOR_INDEXABLE_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SMALLEST_FOR_INDEXABLE_HPP
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
template <
|
||||
typename Geometry,
|
||||
typename Indexable,
|
||||
typename IndexableTag,
|
||||
typename AlgoTag,
|
||||
size_t DimensionIndex>
|
||||
struct smallest_for_indexable_dimension
|
||||
{
|
||||
BOOST_MPL_ASSERT_MSG(
|
||||
(false),
|
||||
NOT_IMPLEMENTED_FOR_THIS_INDEXABLE_TAG_TYPE,
|
||||
(smallest_for_indexable_dimension));
|
||||
};
|
||||
|
||||
template <
|
||||
typename Geometry,
|
||||
typename Indexable,
|
||||
typename IndexableTag,
|
||||
typename AlgoTag,
|
||||
size_t N>
|
||||
struct smallest_for_indexable
|
||||
{
|
||||
typedef typename smallest_for_indexable_dimension<
|
||||
Geometry, Indexable, IndexableTag, AlgoTag, N - 1
|
||||
>::result_type result_type;
|
||||
|
||||
template <typename Data>
|
||||
inline static result_type apply(Geometry const& g, Indexable const& i, Data const& data)
|
||||
{
|
||||
result_type r1 = smallest_for_indexable<
|
||||
Geometry, Indexable, IndexableTag, AlgoTag, N - 1
|
||||
>::apply(g, i, data);
|
||||
|
||||
result_type r2 = smallest_for_indexable_dimension<
|
||||
Geometry, Indexable, IndexableTag, AlgoTag, N - 1
|
||||
>::apply(g, i, data);
|
||||
|
||||
return r1 < r2 ? r1 : r2;
|
||||
}
|
||||
};
|
||||
|
||||
template <
|
||||
typename Geometry,
|
||||
typename Indexable,
|
||||
typename IndexableTag,
|
||||
typename AlgoTag>
|
||||
struct smallest_for_indexable<Geometry, Indexable, IndexableTag, AlgoTag, 1>
|
||||
{
|
||||
typedef typename smallest_for_indexable_dimension<
|
||||
Geometry, Indexable, IndexableTag, AlgoTag, 0
|
||||
>::result_type result_type;
|
||||
|
||||
template <typename Data>
|
||||
inline static result_type apply(Geometry const& g, Indexable const& i, Data const& data)
|
||||
{
|
||||
return
|
||||
smallest_for_indexable_dimension<
|
||||
Geometry, Indexable, IndexableTag, AlgoTag, 0
|
||||
>::apply(g, i, data);
|
||||
}
|
||||
};
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SMALLEST_FOR_INDEXABLE_HPP
|
||||
@@ -0,0 +1,76 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// Sum values calculated for indexable's dimensions, used e.g. in R-tree k nearest neighbors query
|
||||
//
|
||||
// Copyright (c) 2011-2013 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_SUM_FOR_INDEXABLE_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SUM_FOR_INDEXABLE_HPP
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
template <
|
||||
typename Geometry,
|
||||
typename Indexable,
|
||||
typename IndexableTag,
|
||||
typename AlgoTag,
|
||||
size_t DimensionIndex>
|
||||
struct sum_for_indexable_dimension
|
||||
{
|
||||
BOOST_MPL_ASSERT_MSG(
|
||||
(false),
|
||||
NOT_IMPLEMENTED_FOR_THIS_INDEXABLE_TAG_TYPE,
|
||||
(sum_for_indexable_dimension));
|
||||
};
|
||||
|
||||
template <
|
||||
typename Geometry,
|
||||
typename Indexable,
|
||||
typename IndexableTag,
|
||||
typename AlgoTag,
|
||||
size_t N>
|
||||
struct sum_for_indexable
|
||||
{
|
||||
typedef typename sum_for_indexable_dimension<
|
||||
Geometry, Indexable, IndexableTag, AlgoTag, N - 1
|
||||
>::result_type result_type;
|
||||
|
||||
inline static result_type apply(Geometry const& g, Indexable const& i)
|
||||
{
|
||||
return
|
||||
sum_for_indexable<
|
||||
Geometry, Indexable, IndexableTag, AlgoTag, N - 1
|
||||
>::apply(g, i) +
|
||||
sum_for_indexable_dimension<
|
||||
Geometry, Indexable, IndexableTag, AlgoTag, N - 1
|
||||
>::apply(g, i);
|
||||
}
|
||||
};
|
||||
|
||||
template <
|
||||
typename Geometry,
|
||||
typename Indexable,
|
||||
typename IndexableTag,
|
||||
typename AlgoTag>
|
||||
struct sum_for_indexable<Geometry, Indexable, IndexableTag, AlgoTag, 1>
|
||||
{
|
||||
typedef typename sum_for_indexable_dimension<
|
||||
Geometry, Indexable, IndexableTag, AlgoTag, 0
|
||||
>::result_type result_type;
|
||||
|
||||
inline static result_type apply(Geometry const& g, Indexable const& i)
|
||||
{
|
||||
return
|
||||
sum_for_indexable_dimension<
|
||||
Geometry, Indexable, IndexableTag, AlgoTag, 0
|
||||
>::apply(g, i);
|
||||
}
|
||||
};
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_SUM_FOR_INDEXABLE_HPP
|
||||
@@ -0,0 +1,33 @@
|
||||
// Boost.Geometry Index
|
||||
//
|
||||
// boxes union/sum area/volume
|
||||
//
|
||||
// Copyright (c) 2008 Federico J. Fernandez.
|
||||
// Copyright (c) 2011-2013 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_UNION_CONTENT_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_UNION_CONTENT_HPP
|
||||
|
||||
#include <boost/geometry/algorithms/expand.hpp>
|
||||
#include <boost/geometry/index/detail/algorithms/content.hpp>
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
|
||||
/**
|
||||
* \brief Compute the area of the union of b1 and b2
|
||||
*/
|
||||
template <typename Box, typename Geometry>
|
||||
inline typename default_content_result<Box>::type union_content(Box const& b, Geometry const& g)
|
||||
{
|
||||
Box expanded_box(b);
|
||||
geometry::expand(expanded_box, g);
|
||||
return detail::content(expanded_box);
|
||||
}
|
||||
|
||||
}}}} // namespace boost::geometry::index::detail
|
||||
|
||||
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_UNION_CONTENT_HPP
|
||||
Reference in New Issue
Block a user