1

May be this is a stupid question and only a simple issue, but I fail compiling a relative simple code. What I try to do is to add/concatenate two polygons using boost::polygon (some pseudocode showing the relevant parts):

#include <boost/polygon/polygon.hpp>

boost::polygon::polygon_with_holes_data<int>     baseData; // base data to work with
boost::polygon::polygon_with_holes_data<int>     opData;   // operational data to be applied to base 

fill both baseData and opData via set() and set_holes() here...

boost::polygon::polygon_set_data<int> result=baseData + opData;

The last line is where I stumble upon: the compiler says the operator "+" is not known for polygon_with_holes_data:

error C2678: binary '+' : no operator found which takes a left-hand operand of type 'boost::polygon::polygon_with_holes_data<T>' (or there is no acceptable conversion)

When I use polygon_data instead of polygon_with_holes_data the same error appears. Any idea what I'm doing wrong?

Thanks!

jwdonahue
  • 6,199
  • 2
  • 21
  • 43
Elmi
  • 5,899
  • 15
  • 72
  • 143
  • Why did you tag this as "C"? – Ulrich Eckhardt Jun 23 '20 at 05:46
  • @UlrichEckhardt sorry, done accidentally! – Elmi Jun 23 '20 at 06:12
  • Try calling `append()` instead. If the operator wasn't defined, it's not defined. – jwdonahue Jun 23 '20 at 06:14
  • @jwdonahue the + operator does not perform an append-operation, it is intended to concatenate the polygons on geometry level. There also exists a - operator which is intended to cut one polygon out of the other, so it is completely different what has to be done here. According to the boost-description there should be such operators defined and to be used for that – Elmi Jun 23 '20 at 06:25
  • Is there a Concatenate function? Your compiler says there's no plus operator. Perhaps there's a separate header file that declares that operator? It's possible there's no `T operator+(T, T)`, but a there might be `T::operator+(T)`, in which case you want `result += baseData + opData`. I tried looking up the members for that class and didn't find any. I've got a slow and unreliable internet here, so you might have better luck at it than I did. – jwdonahue Jun 23 '20 at 14:49

1 Answers1

1

The only operators I see mentioned in the documentation are on polygon sets

Also, note:

Operators are declared inside the namespace boost::polygon::operators.

So, making sure to actually use them:

Live On Coliru

#include <boost/polygon/polygon.hpp>
#include <boost/polygon/polygon_set_data.hpp>
#include <boost/polygon/polygon_with_holes_data.hpp>

namespace bp = boost::polygon;
using poly = bp::polygon_with_holes_data<int>;
using pset = bp::polygon_set_data<int>;

int main() {
    poly baseData; // base data to work with
    poly opData;   // operational data to be applied to base

    // fill both baseData and opData via set() and set_holes() here...

    using namespace bp::operators;
    pset x = baseData + opData;
}
sehe
  • 374,641
  • 47
  • 450
  • 633