c++ - 最新版本的 boost 和 boost 几何库 (GGL) 之间的冲突

标签 c++ eclipse boost boost-geometry

过去,我使用GGL库来编写一些程序。例如,以下代码适用于 GGL 和旧版本的 gcc。现在我将gcc更新到gcc4.7.1。我的程序在编译过程中出现错误。因此,我更新到最新版本的boost 1.52.1。仍然存在与 point_2d、polygon_2d 等相关的错误。我发现在最新版本的 boost 中缺少一些文件,如“cartesian2d.hpp”、“c_array_cartesian.hpp”。

有人可以帮我分析一下下面的代码并告诉我问题出在哪里吗?非常感谢。

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/algorithms/distance.hpp>
#include <boost/geometry/geometry.hpp>

#include <algorithm> // for reverse, unique
#include <iostream>
#include <string>


typedef boost::geometry::model::d2::point_xy<double,        
boost::geometry::cs::cartesian> point_2d;
typedef boost::geometry::model::polygon<point_2d> polygon_2d;
using namespace boost::geometry;

int main() {
         std::cout << "!!!Hello World!!!" << std::endl; // prints !!!Hello World!!!
         model::d2::point_xy<int> p1(1.0, 1.0), p2(2.0, 2.0);
         point_2d x(3.0,3.0);
         std::cout << x.x();
         std::cout << "Distance p1-p2 is: " << distance(p1, p2) <<std::endl;

         float width = 100;
         float length = 100;


         polygon_2d poly;
         {
            const float coor[][2] = {
            {-350.0,-500.0}, {350,-500}, {350, 0}, {width/2.0, 0}, {width/2.0, length},
            {350, length}, {350, 1000}, {-350, 1000}, {-350, length}, {-1*width/2.0, length}, {-1*width/2.0,0},
            {-350, 0}, {-350.0,-500.0} // closing point is opening point
            };
            assign(poly, coor);
         }
            correct(poly);

         return 0;
}

错误如下:

c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/
../../../../include/boost/geometry/core/point_order.hpp:1
57:12:   required from 'const boost::geometry::order_selector  
boost::geometry::point_order<float [13][2]>::value'
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-
mingw32/4.7.1/../../../../include/boost/geometry/algorithms/
assign.hpp:148:70:   required from 'void  
boost::geometry::assign(Geometry1&, const Geometry2&) [with   
Geometry1 =boost::geometry::model::polygon<boost::geometry::model
::d2::point_xy<double, boost::geometry::cs::cartesian> >; 
Geometry2 = float [13][2]]'
..\src\test.cpp:47:44:   required from here
c:\program files\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/
../../../../include/boost/geometry/core/point_order.hpp:95:5:  
error: no matching function for call to   
'assertion_failed(mpl_::failed************   
(boost::geometry::core_dispatch::point_order<void, float [13]
[2]>::NOT_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE::************)
(mpl_::assert_::types<float [13][2], mpl_::na, mpl_::na, 
mpl_::na>))'

最佳答案

需要进行两项更改:

1) 包含 c_array.hpp,以使 2D float 组(在 const float[][2] 内部使用)适应 Boost.Geometry 点概念:

#include <boost/geometry/geometries/adapted/c_array.hpp>

2)使用分配点而不是分配。

assign_points(poly, coor);

然后你的代码就会编译。背景:您使用的是预发布版本(当然允许),在发布时对界面进行了一些小更改。分配(带有范围)现在称为分配点。

关于c++ - 最新版本的 boost 和 boost 几何库 (GGL) 之间的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13835967/

相关文章:

c++ - 在 vector 中的 vector 之间移动指针会导致 vector 迭代器不兼容

c++ - 如何专门化模板成员函数?

eclipse - GWT 编译错误、图像和延迟绑定(bind)

java - 使用 Maven 在 Eclipse 中运行单个 JUnit4 测试

c++ - 我的 SDL/C++ 程序是否占用了过多的 RAM 内存?

c++ - 将 SO_BROADCAST 设置为套接字失败,错误代码为 "Invalid argument"

java - 使用 ANT 构建时出现 "Build Failed: failed to create task or type classpath"

c++ - 使用单写入器增长 Boost.Interprocess 内存映射文件

c++ - 在 C++ 中使用 boost 进程库输出

c++ - Boost sub_match 抛出 std::length_error 异常