使用增强:多边形:get_rectangles
Using Boost:Polygon:get_rectangles
我在使用boost get_rectangles函数时遇到问题。我在stackoverflow上看到了一个使用此函数的示例,但我无法使其工作。
这是我正在使用的代码,我正在使用visual studio 2013和boost库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 );
}
我得到的错误是
>c:libboost1.57.0boostpolygondetail/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:libboost1.57.0boost/rational.hpp(104) : see declaration of 'boost::abs'
1> c:libboost1.57.0boostpolygonpolygon_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:libboost1.57.0boostpolygonpolygon_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:libboost1.57.0boostpolygonpolygon_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> ]
"英特尔编译器"16.0版也出现类似错误:
/rapid/rrapid_workspaces/patl/github/modular boost/boost/polygon/detail/rerectangle_formation.hpp(261):错误:没有函数模板"boost::abs"的实例与参数列表
参数类型为:(int)
问题似乎源于Boost中的这个模板函数
template <typename IntType>
inline rational<IntType> abs(const rational<IntType>& r)
{
return r.numerator() >= IntType(0)? r: -r;
}
如果您修改boost/polgon/detail/rerectangle_formation.hp:261以更改此:
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
那么错误就消失了。
出于某种原因,VS2013和IC16.0似乎都没有从stdlib.h
中找到abs
作为候选,即使自变量是int
。这看起来像是一个编译器错误(在两个不同的编译器中?),但修复方法很简单,也许有人可以向Boost.Polgon维护人员建议。
相关文章:
- Cpp-Tuple使用带有变量的get
- 通过 get-Method 访问变量在类外不起作用
- 为什么无论你输入什么,这"while(cin.get(str,3))"只运行一次?
- Boost.Asio/OpenSSL HTTPS GET certificate trouble
- C++中是否有任何函数等同于python中字典的get函数?
- 使用istringstearm和get行缓慢读取文件
- 如何将 c++ get 函数代码转换为 opencv 算法中使用的 python
- 使用 cin.get() 初始化字符数组
- std::variant<>::get() 不能使用 Apple LLVM 10.0 编译
- 编写 cin.get() 以接收字符数组时出现问题
- 作用域枚举和标准::get
- Visual Studio 2017 中的 cpprestapi 问题找不到 POST/GET 常量
- 在 C++/C 中使用 CURL 发出带有数据文件的 GET HTTP 请求
- 使用"push_back"作为带有"get"函数C++的向量
- 使用 cin.get 读取字符数组
- 如何使用 fstream 的 .get 字符串?
- std::get like (partial) template specialization
- 从 unique_ptr::get 发送指针作为指针引用进入函数
- addr2line get 行号始终返回 0
- unique_ptr<T>::get() 返回的指针在原始unique_ptr被销毁后不是 nullptr