我有一个简单的 DLL,它使用 Boost Geometry 多边形进行一些计算。(主要是交叉点和差异。)由于 DLL 很可能从 C# 代码中调用,并且从 Delphi 以及谁知道从其他地方调用,所以我应该将结果转换为所有东西都可以处理的数组。
更新:
我已经简化并稍微纠正了我的代码。新代码看起来完全不同,使用了完全不同的方法 ( for_each_point
),并且不知何故仍然无法编译。
我的新代码:
#include <vector>
#include <boost/range.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
using namespace boost::geometry;
typedef boost::geometry::model::point
<
double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
> spherical_point;
class PointAggregator {
private :
double *x, *y;
int count;
public :
PointAggregator(int size) {
x = (double*) malloc(sizeof(double) * size);
y = (double*) malloc(sizeof(double) * size);
count = 0;
}
~PointAggregator() {
free(x);
free(y);
}
inline void operator()(spherical_point& p) {
x[count] = get<0>(p);
y[count] = get<1>(p);
count++;
}
void GetResult(double *resultX, double *resultY) {
resultX = x;
resultY = y;
}
};
void VectorToArray(std::vector<model::polygon<spherical_point>> resultVector, double x[], double y[], int *count) {
int i = 0;
for (std::vector<model::polygon<spherical_point>>::iterator it = resultVector.begin(); it != resultVector.end(); ++it) {
if (boost::size(*it) >= 2) {
*count = boost::size(*it);
PointAggregator* pa = new PointAggregator(*count);
boost::geometry::for_each_point(*it, *pa);
pa->GetResult(x, y);
delete(pa);
break;
}
}
}
当前的编译错误是:
- 错误 C2039: 'type' : 不是 'boost::mpl::eval_if_c' iterator.hpp 63 的成员
- 错误 C3203: 'type' : unspecialized class template can't be used as a template argument for template parameter 'Iterator', 应为真实类型differ_type.hpp 25
- 错误 C2955:'boost::type':使用类模板需要模板参数列表differ_type.hpp 25
- 错误 C2955:“boost::iterator_difference”:使用类模板需要模板参数列表differ_type.hpp 26
哪些看起来与这部分代码没有任何关系(我的文件名是geometry.cpp),但是使用Boost Geometry的所有其他内容都被注释掉了,我仍然得到这些错误,所以......
(我是 C++ 和 Boost 的新手,所以在将来自互联网的代码放在一起时,我可能错过了一些基本概念。)我假设我不能轻易地遍历多边形,我错过了非平凡的部分,或者多边形不能用作环,或者迭代不是我想象的那样,或者我不知道还有什么问题。我做错什么了?