|
Geometry : |
Subject: [ggl] combine
From: Barend Gehrels (barend)
Date: 2011-03-31 05:02:26
On 30-3-2011 17:44, Adam Wulkiewicz wrote:
> Bruno Lalande wrote:
>> Hi,
>>
>> inline OutputIterator intersection_inserter(
>> Geometry1 const& geometry1,
>> Geometry2 const& geometry2,
>> OutputIterator out);
>>
>> is a function.
>>
>>
>> Yes but my point was to focus on how it's used (as a functor) rather
>> than on what it is (a function). But I'm not totally sure how it's used,
>> precisely. Can you give the most simple example of use?
>
> From http://geometrylibrary.geodan.nl/group__intersection.html:
>
> Example showing clipping of polygon with box
>
> {
> typedef boost::geometry::point_xy<double> P;
> typedef std::vector<boost::geometry::polygon<P> > PV;
>
> boost::geometry::box<P> cb(P(1.5, 1.5), P(4.5, 2.5));
> boost::geometry::polygon<P> poly;
> boost::geometry::read_wkt(
> "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,"
> "4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"
> ",(4 2,4.2 1.4,4.8 1.9,4.4 2.2,4 2))", poly);
>
> PV v;
>
> boost::geometry::intersection_inserter<
> boost::geometry::polygon<P>
> >(cb, poly, std::back_inserter(v));
>
> std::cout << "Clipped polygon(s) " << std::endl;
> for (PV::const_iterator it = v.begin(); it != v.end(); it++)
> {
> std::cout << boost::geometry::dsv(*it) << std::endl;
> }
> }
>
> It all depends on what this function/functor does. Berend, what is the
> difference between intersection inserter and copying of the result of
> geometry::intersection by hand? Is it another level of abstraction? I
> saw it can handle std::vectors<Geometry>.
There is no big difference. The _inserter versions might be chained like
described here:
http://bit.ly/ihdbMw
so here the difference is turned into a symmetric difference.
In that sense, yes it is an inserter because it can be placed on the
same level as the std::back_inserter.
These functions were there from the beginning, when we didn't have the
multi-polygons so tightly integrated. But the call to (e.g.)
intersection can handle a std::vector<Polygon> as well. I've no big
problem moving them to e.g namespace detail, but they should stay
because they are called from the functions without the _inserter suffix.
Regards, Barend
Geometry list run by mateusz at loskot.net