Note that there are some explanatory texts on larger screens.

plurals
  1. POboost::geometry: How to do for_each_segment?
    text
    copied!<p>I try to figure out <code>how boost::geometry</code>'s <code>for_each_segment</code> ist working. The documentation tells me, that <code>for_each_segment</code> expects a geometry and a Functor. This functor is called <code>polylength_helper</code> in my example, as long as this snippet is not compiling I just increment a number there to keep things simple until it compiles.</p> <pre><code>// foo.h typedef boost::geometry::model::point&lt;double, 2, bg::cs::cartesian&gt; GeographicPoint; typedef boost::geometry::model::linestring&lt;GeographicPoint&gt; GeographicPolyLine; typedef boost::geometry::model::segment&lt;GeographicPoint&gt; GeographicSegment; double poly_length(const GeographicPolyLine&amp;); template&lt;typename Segment&gt; struct polylength_helper{ polylength_helper() : length(0){}; inline void operator()(Segment s){ length += 1; }; double length; }; // foo.cpp double poly_length(GeographicPolyLine &amp;poly){ polylength_helper&lt;GeographicSegment&gt; helper; bg::for_each_segment(poly, helper); return helper.length; } </code></pre> <p>Well, this does not compile. I used <code>clang</code> for a more understandable output, it says:</p> <pre><code>note: candidate function not viable: no known conversion from 'model::referring_segment&lt;point_type&gt;' to 'boost::geometry::model::segment&lt;boost::geometry::model::point&lt;double, 2, boost::geometry::cs::cartesian&gt; &gt;' for 1st argument inline void operator()(Segment s){ ^ </code></pre> <p>Can anyone help me out? Especially I have no idea where the <code>referring_segment</code> in the message comes from.</p> <p>Here is an example from the docs:</p> <p><a href="http://www.boost.org/doc/libs/1_48_0/libs/geometry/doc/html/geometry/reference/algorithms/for_each/for_each_segment_2_const_version.html" rel="nofollow">http://www.boost.org/doc/libs/1_48_0/libs/geometry/doc/html/geometry/reference/algorithms/for_each/for_each_segment_2_const_version.html</a></p> <p>But I cannot figure out how this differs from my version, except for the <code>typedef</code>s.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload