C++ 使用Boost:Polygon:get_矩形

C++ 使用Boost:Polygon:get_矩形,c++,visual-c++,boost,boost-polygon,C++,Visual C++,Boost,Boost Polygon,我在使用boost get_rectangles函数时遇到了问题,我在stackoverflow上看到了一个使用该函数的示例,但是我无法让它工作 下面是我正在使用的代码,我正在使用visual studio 2013和boost library 1.57 int main() { std::vector< boost::polygon::rectangle_data<int> > rects; typedef boost::polygon::polygon

我在使用boost get_rectangles函数时遇到了问题,我在stackoverflow上看到了一个使用该函数的示例,但是我无法让它工作

下面是我正在使用的代码,我正在使用visual studio 2013和boost library 1.57

int main()
{
    std::vector< boost::polygon::rectangle_data<int> > rects;
    typedef boost::polygon::polygon_90_with_holes_data<int> Polygon90;
    Polygon90 poly;
    typedef boost::polygon::polygon_traits<Polygon90>::point_type MyPoint;

    MyPoint pts[] = { boost::polygon::construct<MyPoint>(0, 0),
      boost::polygon::construct<MyPoint>(0, 10),
      boost::polygon::construct<MyPoint>(30, 10),
      boost::polygon::construct<MyPoint>(30, 20),
      boost::polygon::construct<MyPoint>(10, 20),
      boost::polygon::construct<MyPoint>(10, 0) };

    boost::polygon::set_points(poly, pts, pts + 6);

    boost::polygon::get_rectangles(rects, poly );
}
intmain()
{
std::vectorrects;
typedef boost::polygon::polygon_90_带孔_数据Polygon90;
Polygon90-poly;
typedef boost::polygon::polygon_traits::point_type MyPoint;
MyPoint pts[]={boost::polygon::construct(0,0),
boost::polygon::construct(0,10),
boost::polygon::construct(30,10),
boost::polygon::construct(30,20),
boost::polygon::construct(10,20),
boost::polygon::construct(10,0)};
boost::polygon::set_points(多边形、pts、pts+6);
polygon::get_矩形(矩形,多边形);
}
我得到的错误是

>c:\lib\boost\1.57.0\boost\polygon\detail/rectangle_formation.hpp(261): error C2784: 'boost::rational<IntType> boost::abs(const boost::rational<IntType> &)' : could not deduce template argument for 'const boost::rational<IntType> &' from 'int'
1>          C:\lib\boost\1.57.0\boost/rational.hpp(104) : see declaration of 'boost::abs'
1>          c:\lib\boost\1.57.0\boost\polygon\polygon_90_set_data.hpp(180) : see reference to function template instantiation 'void boost::polygon::form_rectangles<output_container,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<std::pair<int,std::pair<int,int>>>>>,boost::polygon::rectangle_concept>(output_container &,iterator_type,iterator_type,boost::polygon::orientation_2d,rectangle_concept)' being compiled
1>          with
1>          [
1>              output_container=std::vector<boost::polygon::rectangle_data<int>,std::allocator<boost::polygon::rectangle_data<int>>>
1>  ,            iterator_type=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<std::pair<int,std::pair<int,int>>>>>
1>  ,            rectangle_concept=boost::polygon::rectangle_concept
1>          ]
1>          c:\lib\boost\1.57.0\boost\polygon\polygon_90_set_concept.hpp(86) : see reference to function template instantiation 'void boost::polygon::polygon_90_set_data<int>::get_rectangles<output_container_type>(output_container &) const' being compiled
1>          with
1>          [
1>              output_container_type=std::vector<boost::polygon::rectangle_data<int>,std::allocator<boost::polygon::rectangle_data<int>>>
1>  ,            output_container=std::vector<boost::polygon::rectangle_data<int>,std::allocator<boost::polygon::rectangle_data<int>>>
1>          ]
1>          c:\lib\boost\1.57.0\boost\polygon\polygon_90_set_concept.hpp(86) : see reference to function template instantiation 'void boost::polygon::polygon_90_set_data<int>::get_rectangles<output_container_type>(output_container &) const' being compiled
1>          with
1>          [
1>              output_container_type=std::vector<boost::polygon::rectangle_data<int>,std::allocator<boost::polygon::rectangle_data<int>>>
1>  ,            output_container=std::vector<boost::polygon::rectangle_data<int>,std::allocator<boost::polygon::rectangle_data<int>>>
1>          ]
1>          TerrainDispatcher.cpp(173) : see reference to function template instantiation 'void boost::polygon::get_rectangles<std::vector<boost::polygon::rectangle_data<int>,std::allocator<_Ty>>,Polygon90>(output_container_type &,const polygon_set_type &)' being compiled
1>          with
1>          [
1>              _Ty=boost::polygon::rectangle_data<int>
1>  ,            output_container_type=std::vector<boost::polygon::rectangle_data<int>,std::allocator<boost::polygon::rectangle_data<int>>>
1>  ,            polygon_set_type=Polygon90
1>          ]
>c:\lib\boost\1.57.0\boost\polygon\detail/rectangle\u formation.hpp(261):错误C2784:'boost::rational boost::abs(const boost::rational&'):无法从'int'推断'const boost::rational&'的模板参数
1> C:\lib\boost\1.57.0\boost/rational.hpp(104):参见“boost::abs”的声明
1> c:\lib\boost\1.57.0\boost\polygon\polygon\u 90\u set\u data.hpp(180):请参阅正在编译的函数模板实例化“void boost::polygon::form\u矩形(输出容器和迭代器类型、迭代器类型、boost::polygon::orientation\u 2d、矩形概念)”
1> 与
1>          [
1> 输出容器=标准::向量
1> ,迭代器_type=std::_向量_迭代器
1> ,矩形概念=增强::多边形::矩形概念
1>          ]
1> c:\lib\boost\1.57.0\boost\polygon\polygon\u 90\u set\u concept.hpp(86):请参阅正在编译的函数模板实例化“void boost::polygon::polygon\u 90\u set\u data::get_矩形(输出容器&)const”
1> 与
1>          [
1> 输出容器类型=标准::向量
1> ,输出容器=std::vector
1>          ]
1> c:\lib\boost\1.57.0\boost\polygon\polygon\u 90\u set\u concept.hpp(86):请参阅正在编译的函数模板实例化“void boost::polygon::polygon\u 90\u set\u data::get_矩形(输出容器&)const”
1> 与
1>          [
1> 输出容器类型=标准::向量
1> ,输出容器=std::vector
1>          ]
1> cpp(173):请参阅正在编译的函数模板实例化“void boost::polygon::get_矩形(output_container_type&,const polygon_set_type&)”的参考
1> 与
1>          [
1> _Ty=boost::polygon::rectangle\u数据
1> ,输出容器类型=std::vector
1> ,多边形集合类型=多边形90
1>          ]

英特尔编译器16.0版出现类似错误:

/rapid/rapid_Workspace/patl/github/modular boost/boost/polygon/detail/rectangle_formation.hpp(261): 错误:没有函数模板“boost::abs”的实例与 参数表

参数类型为:(int)

问题似乎源于:

。。。为此:

using std::abs;
if(abs((*itr).second.second) > 1) itr = tmp_itr; //next edge begins from this vertex
…然后错误就消失了


出于某种原因,VS2013和IC16.0似乎都没有从
stdlib.h
中找到
abs
作为候选,即使参数是
int
。这看起来像是一个编译器错误(在两个不同的编译器中?),但修复非常简单,也许有人可以向Boost.Polygon维护人员推荐它。

我认为这是一个需要向Boost开发者报告的问题。WorksForMe:(使用一些c++11样式)我仍然调查并发现问题在于是否还必须使用geometry类。尝试包含此库:#包含并编译。非常感谢。我应该把它作为一个答案贴出来,还是你想自己回答?再看一眼,我的答案根本无法解释这一点。我看不出助推几何是如何涉及的。老实说,我会先找出哪个Boost Polygon/common头解决了这个问题,然后再认定它“已解决”
if(abs((*itr).second.second) > 1) itr = tmp_itr; //next edge begins from this vertex
using std::abs;
if(abs((*itr).second.second) > 1) itr = tmp_itr; //next edge begins from this vertex