gpt4 book ai didi

c++ - 使用 boost :Polygon:get_rectangles

转载 作者:太空宇宙 更新时间:2023-11-04 13:36:44 29 4
gpt4 key购买 nike

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

这是我正在使用的代码,我正在使用带有 boost 库 1.57 的 visual studio 2013

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:\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> ]

最佳答案

英特尔编译器版本 16.0 给出了类似的错误:

/rapid/rapid_workspaces/patl/github/modular-boost/boost/polygon/detail/rectangle_formation.hpp(261): error: no instance of function template "boost::abs" matches the argument list

argument types are: (int)

问题似乎源于this template function in Boost.Rational :

template <typename IntType>
inline rational<IntType> abs(const rational<IntType>& r)
{
return r.numerator() >= IntType(0)? r: -r;
}

如果你修改 boost/polygon/detail/rectangle_formation.hpp: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.Polygon 维护者提出建议。

关于c++ - 使用 boost :Polygon:get_rectangles,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29300310/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com