// 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_DETAIL_IS_VALID_RING_HPP #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_RING_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace geometry { #ifndef DOXYGEN_NO_DETAIL namespace detail { namespace is_valid { // struct to check whether a ring is topologically closed template struct is_topologically_closed { static inline bool apply(Ring const&) { return true; } }; template struct is_topologically_closed { static inline bool apply(Ring const& ring) { return geometry::equals(range::front(ring), range::back(ring)); } }; template struct ring_area_predicate { typedef std::greater type; }; template struct ring_area_predicate { typedef std::less type; }; template struct is_properly_oriented { typedef typename point_type::type point_type; typedef typename strategy::area::services::default_strategy < typename cs_tag::type, point_type >::type strategy_type; typedef detail::area::ring_area < order_as_direction::value>::value, geometry::closure::value > ring_area_type; typedef typename default_area_result::type area_result_type; static inline bool apply(Ring const& ring) { typename ring_area_predicate < area_result_type, IsInteriorRing >::type predicate; // Check area area_result_type const zero = area_result_type(); return predicate(ring_area_type::apply(ring, strategy_type()), zero); } }; template < typename Ring, bool AllowDuplicates, bool CheckSelfIntersections = true, bool IsInteriorRing = false > struct is_valid_ring { static inline bool apply(Ring const& ring) { // return invalid if any of the following condition holds: // (a) the ring's size is below the minimal one // (b) the ring is not topologically closed // (c) the ring has spikes // (d) the ring has duplicate points (if AllowDuplicates is false) // (e) the boundary of the ring has self-intersections // (f) the order of the points is inconsistent with the defined order // // Note: no need to check if the area is zero. If this is the // case, then the ring must have at least two spikes, which is // checked by condition (c). closure_selector const closure = geometry::closure::value; return ( boost::size(ring) >= core_detail::closure::minimum_ring_size::value ) && is_topologically_closed::apply(ring) && (AllowDuplicates || !has_duplicates::apply(ring)) && !has_spikes::apply(ring) && !(CheckSelfIntersections && geometry::intersects(ring)) && is_properly_oriented::apply(ring); } }; }} // namespace dispatch #endif // DOXYGEN_NO_DETAIL #ifndef DOXYGEN_NO_DISPATCH namespace dispatch { // A Ring is a Polygon with exterior boundary only. // The Ring's boundary must be a LinearRing (see OGC 06-103-r4, // 6.1.7.1, for the definition of LinearRing) // // Reference (for polygon validity): OGC 06-103r4 (6.1.11.1) template struct is_valid : detail::is_valid::is_valid_ring {}; } // namespace dispatch #endif // DOXYGEN_NO_DISPATCH }} // namespace boost::geometry #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_RING_HPP