[is_simple] Add support for strategies.

This commit is contained in:
Adam Wulkiewicz
2017-02-17 05:02:57 +01:00
parent 6f7beaf01a
commit 6bd28d96e6
5 changed files with 112 additions and 26 deletions

View File

@@ -1,8 +1,9 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, Oracle and/or its affiliates.
// Copyright (c) 2014-2017, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -27,7 +28,8 @@ namespace detail { namespace is_simple
template <typename Geometry>
struct always_simple
{
static inline bool apply(Geometry const&)
template <typename Strategy>
static inline bool apply(Geometry const&, Strategy const&)
{
return true;
}

View File

@@ -1,8 +1,9 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014-2015, Oracle and/or its affiliates.
// Copyright (c) 2014-2017, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -37,6 +38,12 @@ namespace detail { namespace is_simple
template <typename Ring>
struct is_simple_ring
{
template <typename Strategy>
static inline bool apply(Ring const& ring, Strategy const&)
{
return apply(ring);
}
static inline bool apply(Ring const& ring)
{
simplicity_failure_policy policy;
@@ -69,6 +76,12 @@ private:
}
public:
template <typename Strategy>
static inline bool apply(Polygon const& polygon, Strategy const&)
{
return apply(polygon);
}
static inline bool apply(Polygon const& polygon)
{
return
@@ -119,7 +132,8 @@ struct is_simple<Polygon, polygon_tag>
template <typename MultiPolygon>
struct is_simple<MultiPolygon, multi_polygon_tag>
{
static inline bool apply(MultiPolygon const& multipolygon)
template <typename Strategy>
static inline bool apply(MultiPolygon const& multipolygon, Strategy const&)
{
return
detail::check_iterator_range

View File

@@ -1,8 +1,9 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, Oracle and/or its affiliates.
// Copyright (c) 2014-2017, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -17,46 +18,105 @@
#include <boost/geometry/geometries/concepts/check.hpp>
#include <boost/geometry/algorithms/dispatch/is_simple.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/strategies/default_strategy.hpp>
#include <boost/geometry/strategies/intersection.hpp>
namespace boost { namespace geometry
{
namespace resolve_strategy
{
namespace resolve_variant {
struct is_simple
{
template <typename Geometry, typename Strategy>
static inline bool apply(Geometry const& geometry,
Strategy const& strategy)
{
return dispatch::is_simple<Geometry>::apply(geometry, strategy);
}
template <typename Geometry>
static inline bool apply(Geometry const& geometry,
default_strategy)
{
// NOTE: Currently the strategy is only used for Linear geometries
typedef typename strategy::intersection::services::default_strategy
<
typename cs_tag<Geometry>::type
>::type strategy_type;
return dispatch::is_simple<Geometry>::apply(geometry, strategy_type());
}
};
} // namespace resolve_strategy
namespace resolve_variant
{
template <typename Geometry>
struct is_simple
{
static inline bool apply(Geometry const& geometry)
template <typename Strategy>
static inline bool apply(Geometry const& geometry, Strategy const& strategy)
{
concepts::check<Geometry const>();
return dispatch::is_simple<Geometry>::apply(geometry);
return resolve_strategy::is_simple::apply(geometry, strategy);
}
};
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct is_simple<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
template <typename Strategy>
struct visitor : boost::static_visitor<bool>
{
Strategy const& m_strategy;
visitor(Strategy const& strategy)
: m_strategy(strategy)
{}
template <typename Geometry>
bool operator()(Geometry const& geometry) const
{
return is_simple<Geometry>::apply(geometry);
return is_simple<Geometry>::apply(geometry, m_strategy);
}
};
template <typename Strategy>
static inline bool
apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry)
apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
Strategy const& strategy)
{
return boost::apply_visitor(visitor(), geometry);
return boost::apply_visitor(visitor<Strategy>(strategy), geometry);
}
};
} // namespace resolve_variant
/*!
\brief \brief_check{is simple}
\ingroup is_simple
\tparam Geometry \tparam_geometry
\tparam Strategy \tparam_strategy{Is_simple}
\param geometry \param_geometry
\param strategy \param_strategy{is_simple}
\return \return_check{is simple}
\qbk{[include reference/algorithms/is_simple.qbk]}
*/
template <typename Geometry, typename Strategy>
inline bool is_simple(Geometry const& geometry, Strategy const& strategy)
{
return resolve_variant::is_simple<Geometry>::apply(geometry, strategy);
}
/*!
\brief \brief_check{is simple}
@@ -70,7 +130,7 @@ struct is_simple<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
template <typename Geometry>
inline bool is_simple(Geometry const& geometry)
{
return resolve_variant::is_simple<Geometry>::apply(geometry);
return resolve_variant::is_simple<Geometry>::apply(geometry, default_strategy());
}

View File

@@ -189,8 +189,8 @@ private:
};
template <typename Linear>
inline bool has_self_intersections(Linear const& linear)
template <typename Linear, typename Strategy>
inline bool has_self_intersections(Linear const& linear, Strategy const& strategy)
{
typedef typename point_type<Linear>::type point_type;
@@ -217,16 +217,11 @@ inline bool has_self_intersections(Linear const& linear)
is_acceptable_turn<Linear>
> interrupt_policy(predicate);
typedef typename strategy::intersection::services::default_strategy
<
typename cs_tag<Linear>::type
>::type strategy_type;
detail::self_get_turn_points::get_turns
<
turn_policy
>::apply(linear,
strategy_type(),
strategy,
detail::no_rescale_policy(),
turns,
interrupt_policy);
@@ -252,8 +247,19 @@ struct is_simple_linestring
&& ! detail::is_valid::has_spikes
<
Linestring, closed
>::apply(linestring, policy)
&& ! (CheckSelfIntersections && has_self_intersections(linestring));
>::apply(linestring, policy);
}
};
template <typename Linestring>
struct is_simple_linestring<Linestring, true>
{
template <typename Strategy>
static inline bool apply(Linestring const& linestring,
Strategy const& strategy)
{
return is_simple_linestring<Linestring, false>::apply(linestring)
&& ! has_self_intersections(linestring, strategy);
}
};
@@ -261,7 +267,9 @@ struct is_simple_linestring
template <typename MultiLinestring>
struct is_simple_multilinestring
{
static inline bool apply(MultiLinestring const& multilinestring)
template <typename Strategy>
static inline bool apply(MultiLinestring const& multilinestring,
Strategy const& strategy)
{
// check each of the linestrings for simplicity
// but do not compute self-intersections yet; these will be
@@ -281,7 +289,7 @@ struct is_simple_multilinestring
return false;
}
return ! has_self_intersections(multilinestring);
return ! has_self_intersections(multilinestring, strategy);
}
};

View File

@@ -1,8 +1,9 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014-2015, Oracle and/or its affiliates.
// Copyright (c) 2014-2017, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
@@ -38,7 +39,8 @@ namespace detail { namespace is_simple
template <typename MultiPoint>
struct is_simple_multipoint
{
static inline bool apply(MultiPoint const& multipoint)
template <typename Strategy>
static inline bool apply(MultiPoint const& multipoint, Strategy const&)
{
if (boost::empty(multipoint))
{