Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67413 - in sandbox/geometry/boost/geometry: algorithms core extensions/algorithms
From: barend.gehrels_at_[hidden]
Date: 2010-12-22 12:43:15


Author: barendgehrels
Date: 2010-12-22 12:43:14 EST (Wed, 22 Dec 2010)
New Revision: 67413
URL: http://svn.boost.org/trac/boost/changeset/67413

Log:
Fixed minimum_ring_size for open rings
Text files modified:
   sandbox/geometry/boost/geometry/algorithms/area.hpp | 3 ++-
   sandbox/geometry/boost/geometry/algorithms/simplify.hpp | 19 ++++++++++++++-----
   sandbox/geometry/boost/geometry/algorithms/within.hpp | 3 ++-
   sandbox/geometry/boost/geometry/core/closure.hpp | 13 +++++++++++++
   sandbox/geometry/boost/geometry/extensions/algorithms/remove_holes_if.hpp | 8 ++++++--
   5 files changed, 37 insertions(+), 9 deletions(-)

Modified: sandbox/geometry/boost/geometry/algorithms/area.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/algorithms/area.hpp (original)
+++ sandbox/geometry/boost/geometry/algorithms/area.hpp 2010-12-22 12:43:14 EST (Wed, 22 Dec 2010)
@@ -87,7 +87,8 @@
         // An open linear_ring has at least three points,
         // A closed linear_ring has at least four points,
         // if not, there is no (zero) area
- if (boost::size(ring) < (Closure == open ? 3 : 4))
+ if (boost::size(ring)
+ < core_detail::closure::minimum_ring_size<Closure>::value)
         {
             return type();
         }

Modified: sandbox/geometry/boost/geometry/algorithms/simplify.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/algorithms/simplify.hpp (original)
+++ sandbox/geometry/boost/geometry/algorithms/simplify.hpp 2010-12-22 12:43:14 EST (Wed, 22 Dec 2010)
@@ -16,6 +16,7 @@
 #include <boost/typeof/typeof.hpp>
 
 #include <boost/geometry/core/cs.hpp>
+#include <boost/geometry/core/closure.hpp>
 #include <boost/geometry/core/ring_type.hpp>
 #include <boost/geometry/core/exterior_ring.hpp>
 #include <boost/geometry/core/interior_rings.hpp>
@@ -86,8 +87,8 @@
             the output ring might be self intersecting while the input ring is
             not, although chances are low in normal polygons
 
- Finally the inputring might have 4 points (=correct),
- the output < 4(=wrong)
+ Finally the inputring might have 3 (open) or 4 (closed) points (=correct),
+ the output < 3 or 4(=wrong)
         */
 
         if (boost::size(range) <= int(Minimum) || max_distance < 0.0)
@@ -116,10 +117,15 @@
     {
         typedef typename ring_type<Polygon>::type ring_type;
 
+ int const Minimum = core_detail::closure::minimum_ring_size
+ <
+ geometry::closure<Polygon>::value
+ >::value;
+
         // Note that if there are inner rings, and distance is too large,
         // they might intersect with the outer ring in the output,
         // while it didn't in the input.
- simplify_range<ring_type, Strategy, 4>::apply(exterior_ring(poly_in),
+ simplify_range<ring_type, Strategy, Minimum>::apply(exterior_ring(poly_in),
                         exterior_ring(poly_out),
                         max_distance, strategy);
 
@@ -136,7 +142,7 @@
             it_in != boost::end(rings_in);
             ++it_in, ++it_out)
         {
- simplify_range<ring_type, Strategy, 4>::apply(*it_in,
+ simplify_range<ring_type, Strategy, Minimum>::apply(*it_in,
                         *it_out, max_distance, strategy);
         }
     }
@@ -184,7 +190,10 @@
             <
                 Ring,
                 Strategy,
- 4
+ core_detail::closure::minimum_ring_size
+ <
+ geometry::closure<Ring>::value
+ >::value
>
 {};
 

Modified: sandbox/geometry/boost/geometry/algorithms/within.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/algorithms/within.hpp (original)
+++ sandbox/geometry/boost/geometry/algorithms/within.hpp 2010-12-22 12:43:14 EST (Wed, 22 Dec 2010)
@@ -155,7 +155,8 @@
     static inline int apply(Point const& point, Ring const& ring,
             Strategy const& strategy)
     {
- if (boost::size(ring) < 4)
+ if (boost::size(ring)
+ < core_detail::closure::minimum_ring_size<Closure>::value)
         {
             return -1;
         }

Modified: sandbox/geometry/boost/geometry/core/closure.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/core/closure.hpp (original)
+++ sandbox/geometry/boost/geometry/core/closure.hpp 2010-12-22 12:43:14 EST (Wed, 22 Dec 2010)
@@ -10,6 +10,7 @@
 
 
 #include <boost/mpl/assert.hpp>
+#include <boost/mpl/int.hpp>
 #include <boost/range.hpp>
 #include <boost/type_traits/remove_const.hpp>
 
@@ -55,6 +56,18 @@
 };
 
 
+/// Metafunction to define the minimum size of a ring:
+/// 3 for open rings, 4 for closed rings
+template <closure_selector Closure>
+struct minimum_ring_size {};
+
+template <>
+struct minimum_ring_size<geometry::closed> : boost::mpl::int_<4> {};
+
+template <>
+struct minimum_ring_size<geometry::open> : boost::mpl::int_<3> {};
+
+
 }} // namespace detail::point_order
 #endif // DOXYGEN_NO_DETAIL
 

Modified: sandbox/geometry/boost/geometry/extensions/algorithms/remove_holes_if.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/extensions/algorithms/remove_holes_if.hpp (original)
+++ sandbox/geometry/boost/geometry/extensions/algorithms/remove_holes_if.hpp 2010-12-22 12:43:14 EST (Wed, 22 Dec 2010)
@@ -14,11 +14,13 @@
 #include <boost/geometry/algorithms/area.hpp>
 #include <boost/geometry/algorithms/perimeter.hpp>
 
+#include <boost/geometry/core/closure.hpp>
 #include <boost/geometry/core/interior_rings.hpp>
 #include <boost/geometry/util/math.hpp>
 
 #include <boost/geometry/geometries/concepts/check.hpp>
 
+#include <boost/geometry/multi/core/closure.hpp>
 #include <boost/geometry/multi/core/tags.hpp>
 #include <boost/geometry/multi/algorithms/detail/modify_with_predicate.hpp>
 
@@ -122,7 +124,8 @@
 
     inline bool operator()(Ring const& ring) const
     {
- if (ring.size() >= 4)
+ if (ring.size() >=
+ core_detail::closure::minimum_ring_size<Closure>::value)
         {
             double a = area(ring);
             double p = perimeter(ring);
@@ -142,7 +145,8 @@
 {
     inline bool operator()(Ring const& ring) const
     {
- return ring.size() < 4;
+ return ring.size()
+ < core_detail::closure::minimum_ring_size<Closure>::value;
     }
 };
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk