Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86233 - trunk/boost/geometry/io/wkt
From: mateusz_at_[hidden]
Date: 2013-10-10 19:07:03


Author: mloskot
Date: 2013-10-10 19:07:03 EDT (Thu, 10 Oct 2013)
New Revision: 86233
URL: http://svn.boost.org/trac/boost/changeset/86233

Log:
[geometry] Impose closed rings of any polygon output in WKT (ticket #9217)

Text files modified:
   trunk/boost/geometry/io/wkt/write.hpp | 37 +++++++++++++++++++++++++++----------
   1 files changed, 27 insertions(+), 10 deletions(-)

Modified: trunk/boost/geometry/io/wkt/write.hpp
==============================================================================
--- trunk/boost/geometry/io/wkt/write.hpp Thu Oct 10 11:56:41 2013 (r86232)
+++ trunk/boost/geometry/io/wkt/write.hpp 2013-10-10 19:07:03 EDT (Thu, 10 Oct 2013) (r86233)
@@ -119,31 +119,47 @@
 {
     template <typename Char, typename Traits>
     static inline void apply(std::basic_ostream<Char, Traits>& os,
- Range const& range)
+ Range const& range, bool force_closed)
     {
         typedef typename boost::range_iterator<Range const>::type iterator_type;
 
+ typedef stream_coordinate
+ <
+ point_type, 0, dimension<point_type>::type::value
+ > stream_type;
+
         bool first = true;
 
         os << PrefixPolicy::apply();
 
         // TODO: check EMPTY here
 
- for (iterator_type it = boost::begin(range);
- it != boost::end(range);
- ++it)
+ iterator_type begin = boost::begin(range);
+ iterator_type end = boost::end(range);
+ for (iterator_type it = begin; it != end; ++it)
         {
             os << (first ? "" : ",");
- stream_coordinate
- <
- point_type, 0, dimension<point_type>::type::value
- >::apply(os, *it);
+ stream_type::apply(os, *it);
             first = false;
         }
 
+ // optionally, close range to ring by repeating the first point
+ if (force_closed && geometry::disjoint(*begin, *(end - 1)))
+ {
+ os << ",";
+ stream_type::apply(os, *begin);
+ }
+
         os << SuffixPolicy::apply();
     }
 
+ template <typename Char, typename Traits>
+ static inline void apply(std::basic_ostream<Char, Traits>& os,
+ Range const& range)
+ {
+ apply(os, range, false);
+ }
+
 private:
     typedef typename boost::range_value<Range>::type point_type;
 };
@@ -170,18 +186,19 @@
                 Polygon const& poly)
     {
         typedef typename ring_type<Polygon const>::type ring;
+ bool const force_closed = true;
 
         os << PrefixPolicy::apply();
         // TODO: check EMPTY here
         os << "(";
- wkt_sequence<ring>::apply(os, exterior_ring(poly));
+ wkt_sequence<ring>::apply(os, exterior_ring(poly), force_closed);
 
         typename interior_return_type<Polygon const>::type rings
                     = interior_rings(poly);
         for (BOOST_AUTO_TPL(it, boost::begin(rings)); it != boost::end(rings); ++it)
         {
             os << ",";
- wkt_sequence<ring>::apply(os, *it);
+ wkt_sequence<ring>::apply(os, *it, force_closed);
         }
         os << ")";
     }


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