From e68f3b512c479e494512e39d387ef2679f1c111e Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Tue, 29 Apr 2014 20:05:16 +0300 Subject: [PATCH] [is_simple] update code; fix includes; --- .../geometry/algorithms/ogc/is_simple.hpp | 309 +++--------------- 1 file changed, 37 insertions(+), 272 deletions(-) diff --git a/include/boost/geometry/algorithms/ogc/is_simple.hpp b/include/boost/geometry/algorithms/ogc/is_simple.hpp index 4b8660e49..5817f0856 100644 --- a/include/boost/geometry/algorithms/ogc/is_simple.hpp +++ b/include/boost/geometry/algorithms/ogc/is_simple.hpp @@ -1,8 +1,37 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2014, Oracle and/or its affiliates. + +// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle + +// Licensed under the Boost Software License version 1.0. +// http://www.boost.org/users/license.html + #ifndef BOOST_GEOMETRY_ALGORITHMS_OGC_IS_SIMPLE_HPP #define BOOST_GEOMETRY_ALGORITHMS_OGC_IS_SIMPLE_HPP -#include +#include + +#include + +#include +#include +#include + #include + +#include + +#include + +#include + +#include +#include + + + +// check includes below #include #include #include @@ -11,73 +40,19 @@ #include #include #include -#include + + + namespace boost { namespace geometry { namespace ogc { -#ifndef DOXYGEN_NO_DISPATCH -namespace dispatch -{ - -template ::type> -struct is_simple - : not_implemented -{}; - -} // namespace dispatch -#endif // DOXYGEN_NO_DISPATCH #ifndef DOXYGEN_NO_DETAIL namespace detail { namespace is_simple { - -template -struct has_spikes; - -template -struct has_spikes -{ - static inline bool apply(Range const& range) - { - if ( boost::size(range) < 3 ) - { - return false; - } - - BOOST_AUTO_TPL(it1, boost::begin(range)); - BOOST_AUTO_TPL(it2, ++boost::begin(range)); - BOOST_AUTO_TPL(it3, ++(++boost::begin(range))); - - for (; it3 != boost::end(range); ++it1, ++it2, ++it3) - { - if ( geometry::detail::point_is_spike_or_equal(*it3, *it1, *it2) ) - { - return true; - } - } - - return false; - } -}; - - -template -struct has_spikes -{ - static inline bool apply(Range const& range) - { - typedef typename closeable_view::type ClosedRange; - - ClosedRange crange(const_cast(range)); - return has_spikes::apply(crange); - } - -}; - - template < typename Geometry, @@ -106,35 +81,6 @@ struct is_below_minimal_size -template -struct is_simple_range -{ - static inline bool apply(Range const& range) - { - if ( is_below_minimal_size::apply(range) ) - { - return false; - } - - Range other(range); - geometry::unique(other); - - if ( boost::size(other) == 1 ) - { - return true; - } - - if ( has_spikes::value>::apply(other) ) - { - return false; - } - - return !geometry::intersects(other); - } -}; - - - template struct is_simple_polygon { @@ -156,147 +102,7 @@ struct is_simple_polygon }; -template -struct is_simple_multipoint -{ - static inline bool apply(MultiPoint const& multipoint) - { - if ( boost::size(multipoint) <= 1 ) - { - return true; - } - MultiPoint mp(multipoint); - - typedef typename point_type::type Point; - - std::sort(boost::begin(mp), boost::end(mp), geometry::less()); - - geometry::equal_to equal; - - BOOST_AUTO_TPL(it_next, ++boost::begin(mp)); - BOOST_AUTO_TPL(it, boost::begin(mp)); - for (; it_next != boost::end(mp); ++it, ++it_next) - { - if ( equal(*it, *it_next) ) - { - return false; - } - } - return true; - } -}; - - -template -struct is_simple_multilinestring -{ - static inline bool apply(MultiLinestring const& multilinestring) - { - typedef typename boost::range_value::type Linestring; - typedef typename point_type::type Point; - - BOOST_AUTO_TPL(it, boost::begin(multilinestring)); - for (; it != boost::end(multilinestring); ++it) - { - if ( !dispatch::is_simple::apply(*it) ) - { - return false; - } - } - - - typedef geometry::detail::overlay::turn_info - < - Point - > turn_info; - - std::deque turns; - - typedef typename strategy_intersection - < - typename cs_tag::type, - MultiLinestring, - MultiLinestring, - Point - >::segment_intersection_strategy_type segment_intersection_strategy_type; - - typedef geometry::detail::overlay::get_turn_info - < - geometry::detail::disjoint::assign_disjoint_policy - > TurnPolicy; - - geometry::detail::self_get_turn_points::no_interrupt_policy - interrupt_policy; - - geometry::detail::self_get_turn_points::get_turns - < - TurnPolicy - >::apply(multilinestring, - geometry::detail::no_rescale_policy(), - turns, - interrupt_policy); - - std::cout << "turns:"; - for (typename std::deque::const_iterator tit = turns.begin(); - tit != turns.end(); ++tit) - { - std::cout << " " << geometry::dsv(tit->point); - } - std::cout << std::endl << std::endl; - - if ( turns.size() == 0 ) - { - return true; - } - - std::vector endpoints; - for (it = boost::begin(multilinestring); - it != boost::end(multilinestring); ++it) - { - BOOST_ASSERT ( boost::size(*it) != 1 ); - if ( boost::size(*it) != 0 ) - { - endpoints.push_back( *boost::begin(*it) ); - endpoints.push_back( *(--boost::end(*it)) ); - } - } - - - std::sort(endpoints.begin(), endpoints.end(), geometry::less()); - - std::cout << "endpoints: "; - for (typename std::vector::iterator pit = endpoints.begin(); - pit != endpoints.end(); ++pit) - { - std::cout << " " << geometry::dsv(*pit); - } - std::cout << std::endl << std::endl; - - for (typename std::deque::const_iterator tit = turns.begin(); - tit != turns.end(); ++tit) - { - Linestring const& ls1 = - *(boost::begin(multilinestring) - + tit->operations[0].seg_id.multi_index); - Linestring const& ls2 = - *(boost::begin(multilinestring) - + tit->operations[0].other_id.multi_index); - - if ( ( !geometry::equals(*boost::begin(ls1), tit->point) - && !geometry::equals(*--boost::end(ls1), tit->point) ) - || - ( !geometry::equals(*boost::begin(ls2), tit->point) - && !geometry::equals(*--boost::end(ls2), tit->point) ) - ) - { - return false; - } - } - return true; - } - -}; template @@ -348,16 +154,6 @@ namespace dispatch { -// A point is always simple -template -struct is_simple -{ - static inline bool apply(Point const&) - { - return true; - } -}; - // A segment is always simple. // A segment is a curve. @@ -368,9 +164,9 @@ struct is_simple template struct is_simple { - static inline bool apply(Segment const&) + static inline bool apply(Segment const& segment) { - return true; + return dispatch::is_valid::apply(segment); } }; @@ -382,23 +178,13 @@ struct is_simple template struct is_simple { - static inline bool apply(Box const&) + static inline bool apply(Box const& box) { - return true; + return dispatch::is_valid::apply(box); } }; -// A linestring is a curve. -// A curve is simple if it does not pass through the same point twice, -// with the possible exception of its two endpoints -// -// Reference: OGC 06-103r4 (§6.1.6.1) -template -struct is_simple - : detail::is_simple::is_simple_range -{}; - // A Ring is a Polygon. // A Polygon is always a simple geometric object provided that it is valid. @@ -419,27 +205,6 @@ struct is_simple {}; -// A MultiPoint is simple if no two Points in the MultiPoint are equal -// (have identical coordinate values in X and Y) -// -// Reference: OGC 06-103r4 (§6.1.5) -template -struct is_simple - : detail::is_simple::is_simple_multipoint -{}; - - -// A MultiLinestring is a MultiCurve -// A MultiCurve is simple if all of its elements are simple and the -// only intersections between any two elements occur at Points that -// are on the boundaries of both elements. -// -// Reference: OGC 06-103r4 (§6.1.8.1; Fig. 9) -template -struct is_simple - : detail::is_simple::is_simple_multilinestring -{}; - // Not clear what the definition is. // Right now we check that each element is simple (in fact valid), and