Hi all,

I wonder if the result from geometry::difference have a specific order?

A test shows that the result comes along the linestring from start point to end point as below[1][2].
( Two difference lines returned. The order of result is alwasy AC the first, DB the second. )

My work depends on the order of result. I am afraid of:
1. Under other circumstances, that order varies.
2. That order of result will change in the future version of boost library. ( I use 1.58.0 for now).

But I can't find a explicit description about this in boost::geometry documentation.
Can you help me?

[1]
image.png
[2] https://pastebin.com/xNj1W41i

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

#include <boost/foreach.hpp>

int main()
{
    typedef boost::geometry::model::d2::point_xy<double> POINT;
    typedef boost::geometry::model::linestring<POINT> LINE;
    typedef boost::geometry::model::polygon<POINT> POLYGON;

    LINE line;
    POLYGON polygon;

    //                     Y
    //                     |
    //               -------------
    //               |     |     |
    //               |     |     |
    //   ------A>>>>>C>>>>>>>>>>>D>>>>>B-----> X
    //       start   |     |     |    end
    //       point   |     |     |   point
    //               ------|------
    //                     |
    //

    // Create line from A to B.
    boost::geometry::read_wkt("linestring(-2 0, 2 0)", line);
    boost::geometry::correct(line);

    boost::geometry::read_wkt("POLYGON((1 1, -1 1, -1 -1, 1 -1))", polygon);
    boost::geometry::correct(polygon);

    std::vector<LINE> output;
    boost::geometry::difference(line, polygon, output);

    // Result will be 2 lines.
    // A to C : LINESTRING(-2 0,-1 0)
    // D to B : LINESTRING(1 0,2 0)
    BOOST_FOREACH(LINE const& l, output)
    {
        std::cout << boost::geometry::wkt(l) << std::endl;
    }

    return 0;
}

-------------------
Thanks!
You Li