From f646ee786cc05f2416b246cd9c82771300941f06 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Tue, 24 Feb 2015 15:28:03 +0200 Subject: [PATCH] [algorithms][is_valid] add the following free functions: * bool is_valid(geometry, string) * bool is_valid(geometry, visitor) * bool is_valid(geometry, failure value) --- .../algorithms/detail/is_valid/interface.hpp | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/is_valid/interface.hpp b/include/boost/geometry/algorithms/detail/is_valid/interface.hpp index 49e78181f..1c1972856 100644 --- a/include/boost/geometry/algorithms/detail/is_valid/interface.hpp +++ b/include/boost/geometry/algorithms/detail/is_valid/interface.hpp @@ -10,6 +10,9 @@ #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_INTERFACE_HPP #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_INTERFACE_HPP +#include +#include + #include #include #include @@ -18,6 +21,8 @@ #include #include +#include +#include namespace boost { namespace geometry @@ -67,6 +72,14 @@ struct is_valid > } // namespace resolve_variant +// Undocumented for now +template +inline bool is_valid(Geometry const& geometry, VisitPolicy& visitor) +{ + return resolve_variant::is_valid::apply(geometry, visitor); +} + + /*! \brief \brief_check{is valid (in the OGC sense)} \ingroup is_valid @@ -81,10 +94,42 @@ template inline bool is_valid(Geometry const& geometry) { is_valid_default_policy<> policy_visitor; - return resolve_variant::is_valid - < - Geometry - >::apply(geometry, policy_visitor); + return is_valid(geometry, policy_visitor); +} + + +// Undocumented for now +template +inline bool is_valid(Geometry const& geometry, validity_failure_type& failure) +{ + failure_type_policy<> policy_visitor; + bool result = is_valid(geometry, policy_visitor); + failure = policy_visitor.failure(); + return result; +} + + +/*! +\brief \brief_check{is valid (in the OGC sense)} +\ingroup is_valid +\tparam Geometry \tparam_geometry +\param geometry \param_geometry +\param message A string containing a message stating if the geometry +is valid or not, and if not valid a reason why +\return \return_check{is valid (in the OGC sense), with one exception: +multi-geometries with no elements are considered valid} + +\qbk{distinguish,with message} +\qbk{[include reference/algorithms/is_valid_with_message.qbk]} +*/ +template +inline bool is_valid(Geometry const& geometry, std::string& message) +{ + std::ostringstream stream; + failing_reason_policy<> policy_visitor(stream); + bool result = is_valid(geometry, policy_visitor); + message = stream.str(); + return result; }