Added boost header
This commit is contained in:
426
test/external/boost/geometry/strategies/agnostic/hull_graham_andrew.hpp
vendored
Normal file
426
test/external/boost/geometry/strategies/agnostic/hull_graham_andrew.hpp
vendored
Normal file
@@ -0,0 +1,426 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
|
||||
// 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_STRATEGIES_AGNOSTIC_CONVEX_GRAHAM_ANDREW_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_CONVEX_GRAHAM_ANDREW_HPP
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/range.hpp>
|
||||
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
#include <boost/geometry/core/point_type.hpp>
|
||||
#include <boost/geometry/strategies/convex_hull.hpp>
|
||||
|
||||
#include <boost/geometry/views/detail/range_type.hpp>
|
||||
|
||||
#include <boost/geometry/policies/compare.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/detail/for_each_range.hpp>
|
||||
#include <boost/geometry/views/reversible_view.hpp>
|
||||
|
||||
|
||||
// Temporary, comparing sorting, this can be removed in the end
|
||||
//#define BOOST_GEOMETRY_USE_FLEX_SORT
|
||||
//#define BOOST_GEOMETRY_USE_FLEX_SORT2
|
||||
#if defined(BOOST_GEOMETRY_USE_FLEX_SORT)
|
||||
# include <boost/algorithm/sorting/flex_sort.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace convex_hull
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename InputRange,
|
||||
typename RangeIterator,
|
||||
typename StrategyLess,
|
||||
typename StrategyGreater
|
||||
>
|
||||
struct get_extremes
|
||||
{
|
||||
typedef typename point_type<InputRange>::type point_type;
|
||||
|
||||
point_type left, right;
|
||||
|
||||
bool first;
|
||||
|
||||
StrategyLess less;
|
||||
StrategyGreater greater;
|
||||
|
||||
get_extremes()
|
||||
: first(true)
|
||||
{}
|
||||
|
||||
inline void apply(InputRange const& range)
|
||||
{
|
||||
// First iterate through this range
|
||||
// (this two-stage approach avoids many point copies,
|
||||
// because iterators are kept in memory. Because iterators are
|
||||
// not persistent (in MSVC) this approach is not applicable
|
||||
// for more ranges together)
|
||||
|
||||
RangeIterator left_it = boost::begin(range);
|
||||
RangeIterator right_it = boost::begin(range);
|
||||
|
||||
for (RangeIterator it = boost::begin(range) + 1;
|
||||
it != boost::end(range);
|
||||
++it)
|
||||
{
|
||||
if (less(*it, *left_it))
|
||||
{
|
||||
left_it = it;
|
||||
}
|
||||
|
||||
if (greater(*it, *right_it))
|
||||
{
|
||||
right_it = it;
|
||||
}
|
||||
}
|
||||
|
||||
// Then compare with earlier
|
||||
if (first && boost::size(range) > 0)
|
||||
{
|
||||
// First time, assign left/right
|
||||
left = *left_it;
|
||||
right = *right_it;
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Next time, check if this range was left/right from
|
||||
// the extremes already collected
|
||||
if (less(*left_it, left))
|
||||
{
|
||||
left = *left_it;
|
||||
}
|
||||
|
||||
if (greater(*right_it, right))
|
||||
{
|
||||
right = *right_it;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template
|
||||
<
|
||||
typename InputRange,
|
||||
typename RangeIterator,
|
||||
typename Container,
|
||||
typename SideStrategy
|
||||
>
|
||||
struct assign_range
|
||||
{
|
||||
Container lower_points, upper_points;
|
||||
|
||||
typedef typename point_type<InputRange>::type point_type;
|
||||
|
||||
point_type const& most_left;
|
||||
point_type const& most_right;
|
||||
|
||||
inline assign_range(point_type const& left, point_type const& right)
|
||||
: most_left(left)
|
||||
, most_right(right)
|
||||
{}
|
||||
|
||||
inline void apply(InputRange const& range)
|
||||
{
|
||||
typedef SideStrategy side;
|
||||
|
||||
// Put points in one of the two output sequences
|
||||
for (RangeIterator it = boost::begin(range);
|
||||
it != boost::end(range);
|
||||
++it)
|
||||
{
|
||||
// check if it is lying most_left or most_right from the line
|
||||
|
||||
int dir = side::apply(most_left, most_right, *it);
|
||||
switch(dir)
|
||||
{
|
||||
case 1 : // left side
|
||||
upper_points.push_back(*it);
|
||||
break;
|
||||
case -1 : // right side
|
||||
lower_points.push_back(*it);
|
||||
break;
|
||||
|
||||
// 0: on line most_left-most_right,
|
||||
// or most_left, or most_right,
|
||||
// -> all never part of hull
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename Range>
|
||||
static inline void sort(Range& range)
|
||||
{
|
||||
typedef typename boost::range_value<Range>::type point_type;
|
||||
typedef geometry::less<point_type> comparator;
|
||||
|
||||
#if defined(GGL_USE_FLEX_SORT)
|
||||
|
||||
#if defined(GGL_USE_FLEX_SORT1)
|
||||
typedef boost::detail::default_predicate
|
||||
<
|
||||
boost::sort_filter_cutoff
|
||||
<
|
||||
18,
|
||||
boost::detail::insert_sort_core,
|
||||
boost::sort_filter_ground
|
||||
<
|
||||
30,
|
||||
boost::detail::heap_sort_core,
|
||||
boost::detail::quick_sort_core
|
||||
<
|
||||
boost::pivot_median_of_three,
|
||||
boost::default_partitionner
|
||||
>
|
||||
>
|
||||
>,
|
||||
comparator> my_sort;
|
||||
my_sort sort;
|
||||
#elif defined(GGL_USE_FLEX_SORT2)
|
||||
|
||||
// 1, 5, 9, 18, 25: 0.75
|
||||
// 50: 0.81
|
||||
|
||||
typedef boost::detail::default_predicate<boost::sort_filter_cutoff
|
||||
<
|
||||
35,
|
||||
boost::detail::insert_sort_core,
|
||||
boost::detail::quick_sort_core<boost::pivot_middle, boost::default_partitionner>
|
||||
>, comparator
|
||||
> barend_sort;
|
||||
|
||||
barend_sort sort;
|
||||
#else
|
||||
#error Define sub-flex-sort
|
||||
#endif
|
||||
|
||||
sort(boost::begin(range), boost::end(range));
|
||||
|
||||
#else
|
||||
std::sort
|
||||
(boost::begin(range), boost::end(range), comparator());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} // namespace detail
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
/*!
|
||||
\brief Graham scan strategy to calculate convex hull
|
||||
\ingroup strategies
|
||||
\note Completely reworked version inspired on the sources listed below
|
||||
\see http://www.ddj.com/architect/201806315
|
||||
\see http://marknelson.us/2007/08/22/convex
|
||||
*/
|
||||
template <typename InputGeometry, typename OutputPoint>
|
||||
class graham_andrew
|
||||
{
|
||||
public :
|
||||
typedef OutputPoint point_type;
|
||||
typedef InputGeometry geometry_type;
|
||||
|
||||
private:
|
||||
|
||||
typedef typename cs_tag<point_type>::type cs_tag;
|
||||
|
||||
typedef typename std::vector<point_type> container_type;
|
||||
typedef typename std::vector<point_type>::const_iterator iterator;
|
||||
typedef typename std::vector<point_type>::const_reverse_iterator rev_iterator;
|
||||
|
||||
|
||||
class partitions
|
||||
{
|
||||
friend class graham_andrew;
|
||||
|
||||
container_type m_lower_hull;
|
||||
container_type m_upper_hull;
|
||||
container_type m_copied_input;
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
typedef partitions state_type;
|
||||
|
||||
|
||||
inline void apply(InputGeometry const& geometry, partitions& state) const
|
||||
{
|
||||
// First pass.
|
||||
// Get min/max (in most cases left / right) points
|
||||
// This makes use of the geometry::less/greater predicates with the optional
|
||||
// direction template parameter to indicate x direction
|
||||
|
||||
typedef typename geometry::detail::range_type<InputGeometry>::type range_type;
|
||||
|
||||
typedef typename boost::range_iterator
|
||||
<
|
||||
range_type const
|
||||
>::type range_iterator;
|
||||
|
||||
detail::get_extremes
|
||||
<
|
||||
range_type,
|
||||
range_iterator,
|
||||
geometry::less<point_type, 0>,
|
||||
geometry::greater<point_type, 0>
|
||||
> extremes;
|
||||
geometry::detail::for_each_range(geometry, extremes);
|
||||
|
||||
// Bounding left/right points
|
||||
// Second pass, now that extremes are found, assign all points
|
||||
// in either lower, either upper
|
||||
detail::assign_range
|
||||
<
|
||||
range_type,
|
||||
range_iterator,
|
||||
container_type,
|
||||
typename strategy::side::services::default_strategy<cs_tag>::type
|
||||
> assigner(extremes.left, extremes.right);
|
||||
|
||||
geometry::detail::for_each_range(geometry, assigner);
|
||||
|
||||
|
||||
// Sort both collections, first on x(, then on y)
|
||||
detail::sort(assigner.lower_points);
|
||||
detail::sort(assigner.upper_points);
|
||||
|
||||
//std::cout << boost::size(assigner.lower_points) << std::endl;
|
||||
//std::cout << boost::size(assigner.upper_points) << std::endl;
|
||||
|
||||
// And decide which point should be in the final hull
|
||||
build_half_hull<-1>(assigner.lower_points, state.m_lower_hull,
|
||||
extremes.left, extremes.right);
|
||||
build_half_hull<1>(assigner.upper_points, state.m_upper_hull,
|
||||
extremes.left, extremes.right);
|
||||
}
|
||||
|
||||
|
||||
template <typename OutputIterator>
|
||||
inline void result(partitions const& state,
|
||||
OutputIterator out, bool clockwise) const
|
||||
{
|
||||
if (clockwise)
|
||||
{
|
||||
output_range<iterate_forward>(state.m_upper_hull, out, false);
|
||||
output_range<iterate_reverse>(state.m_lower_hull, out, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
output_range<iterate_forward>(state.m_lower_hull, out, false);
|
||||
output_range<iterate_reverse>(state.m_upper_hull, out, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
template <int Factor>
|
||||
static inline void build_half_hull(container_type const& input,
|
||||
container_type& output,
|
||||
point_type const& left, point_type const& right)
|
||||
{
|
||||
output.push_back(left);
|
||||
for(iterator it = input.begin(); it != input.end(); ++it)
|
||||
{
|
||||
add_to_hull<Factor>(*it, output);
|
||||
}
|
||||
add_to_hull<Factor>(right, output);
|
||||
}
|
||||
|
||||
|
||||
template <int Factor>
|
||||
static inline void add_to_hull(point_type const& p, container_type& output)
|
||||
{
|
||||
typedef typename strategy::side::services::default_strategy<cs_tag>::type side;
|
||||
|
||||
output.push_back(p);
|
||||
register std::size_t output_size = output.size();
|
||||
while (output_size >= 3)
|
||||
{
|
||||
rev_iterator rit = output.rbegin();
|
||||
point_type const& last = *rit++;
|
||||
point_type const& last2 = *rit++;
|
||||
|
||||
if (Factor * side::apply(*rit, last, last2) <= 0)
|
||||
{
|
||||
// Remove last two points from stack, and add last again
|
||||
// This is much faster then erasing the one but last.
|
||||
output.pop_back();
|
||||
output.pop_back();
|
||||
output.push_back(last);
|
||||
output_size--;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <iterate_direction Direction, typename OutputIterator>
|
||||
static inline void output_range(container_type const& range,
|
||||
OutputIterator out, bool skip_first)
|
||||
{
|
||||
typedef typename reversible_view<container_type const, Direction>::type view_type;
|
||||
view_type view(range);
|
||||
bool first = true;
|
||||
for (typename boost::range_iterator<view_type const>::type it = boost::begin(view);
|
||||
it != boost::end(view); ++it)
|
||||
{
|
||||
if (first && skip_first)
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
*out = *it;
|
||||
++out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}} // namespace strategy::convex_hull
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
template <typename InputGeometry, typename OutputPoint>
|
||||
struct strategy_convex_hull<cartesian_tag, InputGeometry, OutputPoint>
|
||||
{
|
||||
typedef strategy::convex_hull::graham_andrew<InputGeometry, OutputPoint> type;
|
||||
};
|
||||
#endif
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_CONVEX_GRAHAM_ANDREW_HPP
|
||||
151
test/external/boost/geometry/strategies/agnostic/point_in_box_by_side.hpp
vendored
Normal file
151
test/external/boost/geometry/strategies/agnostic/point_in_box_by_side.hpp
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
|
||||
// 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_STRATEGIES_AGNOSTIC_POINT_IN_BOX_BY_SIDE_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_POINT_IN_BOX_BY_SIDE_HPP
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/coordinate_dimension.hpp>
|
||||
#include <boost/geometry/algorithms/assign.hpp>
|
||||
#include <boost/geometry/strategies/covered_by.hpp>
|
||||
#include <boost/geometry/strategies/within.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry { namespace strategy
|
||||
{
|
||||
|
||||
namespace within
|
||||
{
|
||||
|
||||
struct decide_within
|
||||
{
|
||||
static inline bool apply(int side, bool& result)
|
||||
{
|
||||
if (side != 1)
|
||||
{
|
||||
result = false;
|
||||
return false;
|
||||
}
|
||||
return true; // continue
|
||||
}
|
||||
};
|
||||
|
||||
struct decide_covered_by
|
||||
{
|
||||
static inline bool apply(int side, bool& result)
|
||||
{
|
||||
if (side != 1)
|
||||
{
|
||||
result = side >= 0;
|
||||
return false;
|
||||
}
|
||||
return true; // continue
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename Point, typename Box, typename Decide = decide_within>
|
||||
struct point_in_box_by_side
|
||||
{
|
||||
typedef typename strategy::side::services::default_strategy
|
||||
<
|
||||
typename cs_tag<Box>::type
|
||||
>::type side_strategy_type;
|
||||
|
||||
static inline bool apply(Point const& point, Box const& box)
|
||||
{
|
||||
// Create (counterclockwise) array of points, the fifth one closes it
|
||||
// Every point should be on the LEFT side (=1), or ON the border (=0),
|
||||
// So >= 1 or >= 0
|
||||
boost::array<typename point_type<Box>::type, 5> bp;
|
||||
geometry::detail::assign_box_corners_oriented<true>(box, bp);
|
||||
bp[4] = bp[0];
|
||||
|
||||
bool result = true;
|
||||
side_strategy_type strategy;
|
||||
boost::ignore_unused_variable_warning(strategy);
|
||||
|
||||
for (int i = 1; i < 5; i++)
|
||||
{
|
||||
int const side = strategy.apply(point, bp[i - 1], bp[i]);
|
||||
if (! Decide::apply(side, result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace within
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
namespace within { namespace services
|
||||
{
|
||||
|
||||
template <typename Point, typename Box>
|
||||
struct default_strategy
|
||||
<
|
||||
point_tag, box_tag,
|
||||
point_tag, areal_tag,
|
||||
spherical_tag, spherical_tag,
|
||||
Point, Box
|
||||
>
|
||||
{
|
||||
typedef within::point_in_box_by_side
|
||||
<
|
||||
Point, Box, within::decide_within
|
||||
> type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}} // namespace within::services
|
||||
|
||||
|
||||
namespace covered_by { namespace services
|
||||
{
|
||||
|
||||
|
||||
template <typename Point, typename Box>
|
||||
struct default_strategy
|
||||
<
|
||||
point_tag, box_tag,
|
||||
point_tag, areal_tag,
|
||||
spherical_tag, spherical_tag,
|
||||
Point, Box
|
||||
>
|
||||
{
|
||||
typedef within::point_in_box_by_side
|
||||
<
|
||||
Point, Box, within::decide_covered_by
|
||||
> type;
|
||||
};
|
||||
|
||||
|
||||
}} // namespace covered_by::services
|
||||
|
||||
|
||||
#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
|
||||
}}} // namespace boost::geometry::strategy
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGIES_AGNOSTIC_POINT_IN_BOX_BY_SIDE_HPP
|
||||
208
test/external/boost/geometry/strategies/agnostic/point_in_poly_oriented_winding.hpp
vendored
Normal file
208
test/external/boost/geometry/strategies/agnostic/point_in_poly_oriented_winding.hpp
vendored
Normal file
@@ -0,0 +1,208 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2011 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
|
||||
// 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_STRATEGY_AGNOSTIC_POINT_IN_POLY_ORIENTED_WINDING_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGY_AGNOSTIC_POINT_IN_POLY_ORIENTED_WINDING_HPP
|
||||
|
||||
|
||||
#include <boost/geometry/core/point_order.hpp>
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/select_calculation_type.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/side.hpp>
|
||||
#include <boost/geometry/strategies/within.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace within
|
||||
{
|
||||
|
||||
/*!
|
||||
\brief Within detection using winding rule, but checking if enclosing ring is
|
||||
counter clockwise and, if so, reverses the result
|
||||
\ingroup strategies
|
||||
\tparam Point \tparam_point
|
||||
\tparam Reverse True if parameter should be reversed
|
||||
\tparam PointOfSegment \tparam_segment_point
|
||||
\tparam CalculationType \tparam_calculation
|
||||
\author Barend Gehrels
|
||||
\note The implementation is inspired by terralib http://www.terralib.org (LGPL)
|
||||
\note but totally revised afterwards, especially for cases on segments
|
||||
\note Only dependant on "side", -> agnostic, suitable for spherical/latlong
|
||||
|
||||
\qbk{
|
||||
[heading See also]
|
||||
[link geometry.reference.algorithms.within.within_3_with_strategy within (with strategy)]
|
||||
}
|
||||
*/
|
||||
template
|
||||
<
|
||||
bool Reverse,
|
||||
typename Point,
|
||||
typename PointOfSegment = Point,
|
||||
typename CalculationType = void
|
||||
>
|
||||
class oriented_winding
|
||||
{
|
||||
typedef typename select_calculation_type
|
||||
<
|
||||
Point,
|
||||
PointOfSegment,
|
||||
CalculationType
|
||||
>::type calculation_type;
|
||||
|
||||
|
||||
typedef typename strategy::side::services::default_strategy
|
||||
<
|
||||
typename cs_tag<Point>::type
|
||||
>::type strategy_side_type;
|
||||
|
||||
|
||||
/*! subclass to keep state */
|
||||
class counter
|
||||
{
|
||||
int m_count;
|
||||
bool m_touches;
|
||||
calculation_type m_sum_area;
|
||||
|
||||
inline int code() const
|
||||
{
|
||||
return m_touches ? 0 : m_count == 0 ? -1 : 1;
|
||||
}
|
||||
inline int clockwise_oriented_code() const
|
||||
{
|
||||
return (m_sum_area > 0) ? code() : -code();
|
||||
}
|
||||
inline int oriented_code() const
|
||||
{
|
||||
return Reverse
|
||||
? -clockwise_oriented_code()
|
||||
: clockwise_oriented_code();
|
||||
}
|
||||
|
||||
public :
|
||||
friend class oriented_winding;
|
||||
|
||||
inline counter()
|
||||
: m_count(0)
|
||||
, m_touches(false)
|
||||
, m_sum_area(0)
|
||||
{}
|
||||
|
||||
inline void add_to_area(calculation_type triangle)
|
||||
{
|
||||
m_sum_area += triangle;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <size_t D>
|
||||
static inline int check_touch(Point const& point,
|
||||
PointOfSegment const& seg1, PointOfSegment const& seg2,
|
||||
counter& state)
|
||||
{
|
||||
calculation_type const p = get<D>(point);
|
||||
calculation_type const s1 = get<D>(seg1);
|
||||
calculation_type const s2 = get<D>(seg2);
|
||||
if ((s1 <= p && s2 >= p) || (s2 <= p && s1 >= p))
|
||||
{
|
||||
state.m_touches = true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
template <size_t D>
|
||||
static inline int check_segment(Point const& point,
|
||||
PointOfSegment const& seg1, PointOfSegment const& seg2,
|
||||
counter& state)
|
||||
{
|
||||
calculation_type const p = get<D>(point);
|
||||
calculation_type const s1 = get<D>(seg1);
|
||||
calculation_type const s2 = get<D>(seg2);
|
||||
|
||||
|
||||
// Check if one of segment endpoints is at same level of point
|
||||
bool eq1 = math::equals(s1, p);
|
||||
bool eq2 = math::equals(s2, p);
|
||||
|
||||
if (eq1 && eq2)
|
||||
{
|
||||
// Both equal p -> segment is horizontal (or vertical for D=0)
|
||||
// The only thing which has to be done is check if point is ON segment
|
||||
return check_touch<1 - D>(point, seg1, seg2, state);
|
||||
}
|
||||
|
||||
return
|
||||
eq1 ? (s2 > p ? 1 : -1) // Point on level s1, UP/DOWN depending on s2
|
||||
: eq2 ? (s1 > p ? -1 : 1) // idem
|
||||
: s1 < p && s2 > p ? 2 // Point between s1 -> s2 --> UP
|
||||
: s2 < p && s1 > p ? -2 // Point between s2 -> s1 --> DOWN
|
||||
: 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public :
|
||||
|
||||
// Typedefs and static methods to fulfill the concept
|
||||
typedef Point point_type;
|
||||
typedef PointOfSegment segment_point_type;
|
||||
typedef counter state_type;
|
||||
|
||||
static inline bool apply(Point const& point,
|
||||
PointOfSegment const& s1, PointOfSegment const& s2,
|
||||
counter& state)
|
||||
{
|
||||
state.add_to_area(get<0>(s2) * get<1>(s1) - get<0>(s1) * get<1>(s2));
|
||||
|
||||
int count = check_segment<1>(point, s1, s2, state);
|
||||
if (count != 0)
|
||||
{
|
||||
int side = strategy_side_type::apply(s1, s2, point);
|
||||
if (side == 0)
|
||||
{
|
||||
// Point is lying on segment
|
||||
state.m_touches = true;
|
||||
state.m_count = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Side is NEG for right, POS for left.
|
||||
// The count is -2 for down, 2 for up (or -1/1)
|
||||
// Side positive thus means UP and LEFTSIDE or DOWN and RIGHTSIDE
|
||||
// See accompagnying figure (TODO)
|
||||
if (side * count > 0)
|
||||
{
|
||||
state.m_count += count;
|
||||
}
|
||||
}
|
||||
return ! state.m_touches;
|
||||
}
|
||||
|
||||
static inline int result(counter const& state)
|
||||
{
|
||||
return state.oriented_code();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}} // namespace strategy::within
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGY_AGNOSTIC_POINT_IN_POLY_ORIENTED_WINDING_HPP
|
||||
232
test/external/boost/geometry/strategies/agnostic/point_in_poly_winding.hpp
vendored
Normal file
232
test/external/boost/geometry/strategies/agnostic/point_in_poly_winding.hpp
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
|
||||
// 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_STRATEGY_AGNOSTIC_POINT_IN_POLY_WINDING_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGY_AGNOSTIC_POINT_IN_POLY_WINDING_HPP
|
||||
|
||||
|
||||
#include <boost/geometry/util/math.hpp>
|
||||
#include <boost/geometry/util/select_calculation_type.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/side.hpp>
|
||||
#include <boost/geometry/strategies/covered_by.hpp>
|
||||
#include <boost/geometry/strategies/within.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace within
|
||||
{
|
||||
|
||||
/*!
|
||||
\brief Within detection using winding rule
|
||||
\ingroup strategies
|
||||
\tparam Point \tparam_point
|
||||
\tparam PointOfSegment \tparam_segment_point
|
||||
\tparam CalculationType \tparam_calculation
|
||||
\author Barend Gehrels
|
||||
\note The implementation is inspired by terralib http://www.terralib.org (LGPL)
|
||||
\note but totally revised afterwards, especially for cases on segments
|
||||
\note Only dependant on "side", -> agnostic, suitable for spherical/latlong
|
||||
|
||||
\qbk{
|
||||
[heading See also]
|
||||
[link geometry.reference.algorithms.within.within_3_with_strategy within (with strategy)]
|
||||
}
|
||||
*/
|
||||
template
|
||||
<
|
||||
typename Point,
|
||||
typename PointOfSegment = Point,
|
||||
typename CalculationType = void
|
||||
>
|
||||
class winding
|
||||
{
|
||||
typedef typename select_calculation_type
|
||||
<
|
||||
Point,
|
||||
PointOfSegment,
|
||||
CalculationType
|
||||
>::type calculation_type;
|
||||
|
||||
|
||||
typedef typename strategy::side::services::default_strategy
|
||||
<
|
||||
typename cs_tag<Point>::type
|
||||
>::type strategy_side_type;
|
||||
|
||||
|
||||
/*! subclass to keep state */
|
||||
class counter
|
||||
{
|
||||
int m_count;
|
||||
bool m_touches;
|
||||
|
||||
inline int code() const
|
||||
{
|
||||
return m_touches ? 0 : m_count == 0 ? -1 : 1;
|
||||
}
|
||||
|
||||
public :
|
||||
friend class winding;
|
||||
|
||||
inline counter()
|
||||
: m_count(0)
|
||||
, m_touches(false)
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <size_t D>
|
||||
static inline int check_touch(Point const& point,
|
||||
PointOfSegment const& seg1, PointOfSegment const& seg2,
|
||||
counter& state)
|
||||
{
|
||||
calculation_type const p = get<D>(point);
|
||||
calculation_type const s1 = get<D>(seg1);
|
||||
calculation_type const s2 = get<D>(seg2);
|
||||
if ((s1 <= p && s2 >= p) || (s2 <= p && s1 >= p))
|
||||
{
|
||||
state.m_touches = true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
template <size_t D>
|
||||
static inline int check_segment(Point const& point,
|
||||
PointOfSegment const& seg1, PointOfSegment const& seg2,
|
||||
counter& state)
|
||||
{
|
||||
calculation_type const p = get<D>(point);
|
||||
calculation_type const s1 = get<D>(seg1);
|
||||
calculation_type const s2 = get<D>(seg2);
|
||||
|
||||
// Check if one of segment endpoints is at same level of point
|
||||
bool eq1 = math::equals(s1, p);
|
||||
bool eq2 = math::equals(s2, p);
|
||||
|
||||
if (eq1 && eq2)
|
||||
{
|
||||
// Both equal p -> segment is horizontal (or vertical for D=0)
|
||||
// The only thing which has to be done is check if point is ON segment
|
||||
return check_touch<1 - D>(point, seg1, seg2,state);
|
||||
}
|
||||
|
||||
return
|
||||
eq1 ? (s2 > p ? 1 : -1) // Point on level s1, UP/DOWN depending on s2
|
||||
: eq2 ? (s1 > p ? -1 : 1) // idem
|
||||
: s1 < p && s2 > p ? 2 // Point between s1 -> s2 --> UP
|
||||
: s2 < p && s1 > p ? -2 // Point between s2 -> s1 --> DOWN
|
||||
: 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public :
|
||||
|
||||
// Typedefs and static methods to fulfill the concept
|
||||
typedef Point point_type;
|
||||
typedef PointOfSegment segment_point_type;
|
||||
typedef counter state_type;
|
||||
|
||||
static inline bool apply(Point const& point,
|
||||
PointOfSegment const& s1, PointOfSegment const& s2,
|
||||
counter& state)
|
||||
{
|
||||
int count = check_segment<1>(point, s1, s2, state);
|
||||
if (count != 0)
|
||||
{
|
||||
int side = strategy_side_type::apply(s1, s2, point);
|
||||
if (side == 0)
|
||||
{
|
||||
// Point is lying on segment
|
||||
state.m_touches = true;
|
||||
state.m_count = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Side is NEG for right, POS for left.
|
||||
// The count is -2 for down, 2 for up (or -1/1)
|
||||
// Side positive thus means UP and LEFTSIDE or DOWN and RIGHTSIDE
|
||||
// See accompagnying figure (TODO)
|
||||
if (side * count > 0)
|
||||
{
|
||||
state.m_count += count;
|
||||
}
|
||||
}
|
||||
return ! state.m_touches;
|
||||
}
|
||||
|
||||
static inline int result(counter const& state)
|
||||
{
|
||||
return state.code();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
|
||||
namespace services
|
||||
{
|
||||
|
||||
// Register using "areal_tag" for ring, polygon, multi-polygon
|
||||
template <typename AnyTag, typename Point, typename Geometry>
|
||||
struct default_strategy<point_tag, AnyTag, point_tag, areal_tag, cartesian_tag, cartesian_tag, Point, Geometry>
|
||||
{
|
||||
typedef winding<Point, typename geometry::point_type<Geometry>::type> type;
|
||||
};
|
||||
|
||||
template <typename AnyTag, typename Point, typename Geometry>
|
||||
struct default_strategy<point_tag, AnyTag, point_tag, areal_tag, spherical_tag, spherical_tag, Point, Geometry>
|
||||
{
|
||||
typedef winding<Point, typename geometry::point_type<Geometry>::type> type;
|
||||
};
|
||||
|
||||
|
||||
} // namespace services
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
}} // namespace strategy::within
|
||||
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
||||
namespace strategy { namespace covered_by { namespace services
|
||||
{
|
||||
|
||||
// Register using "areal_tag" for ring, polygon, multi-polygon
|
||||
template <typename AnyTag, typename Point, typename Geometry>
|
||||
struct default_strategy<point_tag, AnyTag, point_tag, areal_tag, cartesian_tag, cartesian_tag, Point, Geometry>
|
||||
{
|
||||
typedef strategy::within::winding<Point, typename geometry::point_type<Geometry>::type> type;
|
||||
};
|
||||
|
||||
template <typename AnyTag, typename Point, typename Geometry>
|
||||
struct default_strategy<point_tag, AnyTag, point_tag, areal_tag, spherical_tag, spherical_tag, Point, Geometry>
|
||||
{
|
||||
typedef strategy::within::winding<Point, typename geometry::point_type<Geometry>::type> type;
|
||||
};
|
||||
|
||||
|
||||
}}} // namespace strategy::covered_by::services
|
||||
#endif
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGY_AGNOSTIC_POINT_IN_POLY_WINDING_HPP
|
||||
230
test/external/boost/geometry/strategies/agnostic/simplify_douglas_peucker.hpp
vendored
Normal file
230
test/external/boost/geometry/strategies/agnostic/simplify_douglas_peucker.hpp
vendored
Normal file
@@ -0,0 +1,230 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 1995, 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 1995 Maarten Hilferink, Amsterdam, the Netherlands
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
|
||||
// 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_STRATEGY_AGNOSTIC_SIMPLIFY_DOUGLAS_PEUCKER_HPP
|
||||
#define BOOST_GEOMETRY_STRATEGY_AGNOSTIC_SIMPLIFY_DOUGLAS_PEUCKER_HPP
|
||||
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/range.hpp>
|
||||
|
||||
#include <boost/geometry/core/cs.hpp>
|
||||
#include <boost/geometry/strategies/distance.hpp>
|
||||
|
||||
|
||||
|
||||
//#define GL_DEBUG_DOUGLAS_PEUCKER
|
||||
|
||||
#ifdef GL_DEBUG_DOUGLAS_PEUCKER
|
||||
#include <boost/geometry/util/write_dsv.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
namespace strategy { namespace simplify
|
||||
{
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/*!
|
||||
\brief Small wrapper around a point, with an extra member "included"
|
||||
\details
|
||||
It has a const-reference to the original point (so no copy here)
|
||||
\tparam the enclosed point type
|
||||
*/
|
||||
template<typename Point>
|
||||
struct douglas_peucker_point
|
||||
{
|
||||
Point const& p;
|
||||
bool included;
|
||||
|
||||
inline douglas_peucker_point(Point const& ap)
|
||||
: p(ap)
|
||||
, included(false)
|
||||
{}
|
||||
|
||||
// Necessary for proper compilation
|
||||
inline douglas_peucker_point<Point> operator=(
|
||||
douglas_peucker_point<Point> const& other)
|
||||
{
|
||||
return douglas_peucker_point<Point>(*this);
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
/*!
|
||||
\brief Implements the simplify algorithm.
|
||||
\ingroup strategies
|
||||
\details The douglas_peucker strategy simplifies a linestring, ring or
|
||||
vector of points using the well-known Douglas-Peucker algorithm.
|
||||
For the algorithm, see for example:
|
||||
\see http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
|
||||
\see http://www2.dcs.hull.ac.uk/CISRG/projects/Royal-Inst/demos/dp.html
|
||||
\tparam Point the point type
|
||||
\tparam PointDistanceStrategy point-segment distance strategy to be used
|
||||
\note This strategy uses itself a point-segment-distance strategy which
|
||||
can be specified
|
||||
\author Barend and Maarten, 1995/1996
|
||||
\author Barend, revised for Generic Geometry Library, 2008
|
||||
*/
|
||||
template
|
||||
<
|
||||
typename Point,
|
||||
typename PointDistanceStrategy
|
||||
>
|
||||
class douglas_peucker
|
||||
{
|
||||
public :
|
||||
|
||||
// See also ticket 5954 https://svn.boost.org/trac/boost/ticket/5954
|
||||
// Comparable is currently not possible here because it has to be compared to the squared of max_distance, and more.
|
||||
// For now we have to take the real distance.
|
||||
typedef PointDistanceStrategy distance_strategy_type;
|
||||
// typedef typename strategy::distance::services::comparable_type<PointDistanceStrategy>::type distance_strategy_type;
|
||||
|
||||
typedef typename strategy::distance::services::return_type<distance_strategy_type>::type return_type;
|
||||
|
||||
private :
|
||||
typedef detail::douglas_peucker_point<Point> dp_point_type;
|
||||
typedef typename std::vector<dp_point_type>::iterator iterator_type;
|
||||
|
||||
|
||||
static inline void consider(iterator_type begin,
|
||||
iterator_type end,
|
||||
return_type const& max_dist, int& n,
|
||||
distance_strategy_type const& ps_distance_strategy)
|
||||
{
|
||||
std::size_t size = end - begin;
|
||||
|
||||
// size must be at least 3
|
||||
// because we want to consider a candidate point in between
|
||||
if (size <= 2)
|
||||
{
|
||||
#ifdef GL_DEBUG_DOUGLAS_PEUCKER
|
||||
if (begin != end)
|
||||
{
|
||||
std::cout << "ignore between " << dsv(begin->p)
|
||||
<< " and " << dsv((end - 1)->p)
|
||||
<< " size=" << size << std::endl;
|
||||
}
|
||||
std::cout << "return because size=" << size << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
iterator_type last = end - 1;
|
||||
|
||||
#ifdef GL_DEBUG_DOUGLAS_PEUCKER
|
||||
std::cout << "find between " << dsv(begin->p)
|
||||
<< " and " << dsv(last->p)
|
||||
<< " size=" << size << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
// Find most far point, compare to the current segment
|
||||
//geometry::segment<Point const> s(begin->p, last->p);
|
||||
return_type md(-1.0); // any value < 0
|
||||
iterator_type candidate;
|
||||
for(iterator_type it = begin + 1; it != last; ++it)
|
||||
{
|
||||
return_type dist = ps_distance_strategy.apply(it->p, begin->p, last->p);
|
||||
|
||||
#ifdef GL_DEBUG_DOUGLAS_PEUCKER
|
||||
std::cout << "consider " << dsv(it->p)
|
||||
<< " at " << double(dist)
|
||||
<< ((dist > max_dist) ? " maybe" : " no")
|
||||
<< std::endl;
|
||||
|
||||
#endif
|
||||
if (dist > md)
|
||||
{
|
||||
md = dist;
|
||||
candidate = it;
|
||||
}
|
||||
}
|
||||
|
||||
// If a point is found, set the include flag
|
||||
// and handle segments in between recursively
|
||||
if (md > max_dist)
|
||||
{
|
||||
#ifdef GL_DEBUG_DOUGLAS_PEUCKER
|
||||
std::cout << "use " << dsv(candidate->p) << std::endl;
|
||||
#endif
|
||||
|
||||
candidate->included = true;
|
||||
n++;
|
||||
|
||||
consider(begin, candidate + 1, max_dist, n, ps_distance_strategy);
|
||||
consider(candidate, end, max_dist, n, ps_distance_strategy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public :
|
||||
|
||||
template <typename Range, typename OutputIterator>
|
||||
static inline OutputIterator apply(Range const& range,
|
||||
OutputIterator out, double max_distance)
|
||||
{
|
||||
distance_strategy_type strategy;
|
||||
|
||||
// Copy coordinates, a vector of references to all points
|
||||
std::vector<dp_point_type> ref_candidates(boost::begin(range),
|
||||
boost::end(range));
|
||||
|
||||
// Include first and last point of line,
|
||||
// they are always part of the line
|
||||
int n = 2;
|
||||
ref_candidates.front().included = true;
|
||||
ref_candidates.back().included = true;
|
||||
|
||||
// Get points, recursively, including them if they are further away
|
||||
// than the specified distance
|
||||
typedef typename strategy::distance::services::return_type<distance_strategy_type>::type return_type;
|
||||
|
||||
consider(boost::begin(ref_candidates), boost::end(ref_candidates), max_distance, n, strategy);
|
||||
|
||||
// Copy included elements to the output
|
||||
for(typename std::vector<dp_point_type>::const_iterator it
|
||||
= boost::begin(ref_candidates);
|
||||
it != boost::end(ref_candidates);
|
||||
++it)
|
||||
{
|
||||
if (it->included)
|
||||
{
|
||||
// copy-coordinates does not work because OutputIterator
|
||||
// does not model Point (??)
|
||||
//geometry::convert(it->p, *out);
|
||||
*out = it->p;
|
||||
out++;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}} // namespace strategy::simplify
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
#endif // BOOST_GEOMETRY_STRATEGY_AGNOSTIC_SIMPLIFY_DOUGLAS_PEUCKER_HPP
|
||||
Reference in New Issue
Block a user