c++boostboost-polygon

Add polygons with boost::polygon does not compile?


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!


Solution

  • 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;
    }