添加带有 boost::polygon 的多边形无法编译?
Add polygons with boost::polygon does not compile?
可能这是一个愚蠢的问题,只是一个简单的问题,但我未能编译出相对简单的代码。我尝试做的是 add/concatenate 使用 boost::polygon 的两个多边形(一些显示相关部分的伪代码):
#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;
最后一行是我偶然发现的地方:编译器说运算符“+”对于 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)
当我使用 polygon_data 而不是 polygon_with_holes_data 时,出现相同的错误。知道我做错了什么吗?
谢谢!
我在文档中看到的唯一运算符是 polygon sets
另外,注意:
Operators are declared inside the namespace boost::polygon::operators
.
因此,确保实际使用它们:
#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;
}
可能这是一个愚蠢的问题,只是一个简单的问题,但我未能编译出相对简单的代码。我尝试做的是 add/concatenate 使用 boost::polygon 的两个多边形(一些显示相关部分的伪代码):
#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;
最后一行是我偶然发现的地方:编译器说运算符“+”对于 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)
当我使用 polygon_data 而不是 polygon_with_holes_data 时,出现相同的错误。知道我做错了什么吗?
谢谢!
我在文档中看到的唯一运算符是 polygon sets
另外,注意:
Operators are declared inside the namespace
boost::polygon::operators
.
因此,确保实际使用它们:
#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;
}