DaxDeveloper
DaxDeveloper

Reputation: 138

Using Boost:Polygon:get_rectangles

I am having problems in using the boost get_rectangles function I have seen an example of using this on stackoverflow however I can not get it to work.

Here is the code I'm using and I'm using visual studio 2013 with 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 );
}

and the error I get is

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

Upvotes: 1

Views: 1105

Answers (1)

Nemo
Nemo

Reputation: 71525

The Intel Compiler version 16.0 gives a similar error:

/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)

The trouble seems to stem from this template function in Boost.Rational:

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

If you modify boost/polygon/detail/rectangle_formation.hpp:261 to change this:

if(abs((*itr).second.second) > 1) itr = tmp_itr; //next edge begins from this vertex

... to this:

using std::abs;
if(abs((*itr).second.second) > 1) itr = tmp_itr; //next edge begins from this vertex

...then the error goes away.

For some reason, it appears both VS2013 and IC16.0 do not find abs from stdlib.h as a candidate, even though the argument is int. This looks like a compiler bug (in two different compilers?), but the fix is simple enough that perhaps someone could suggest it to the Boost.Polygon maintainers.

Upvotes: 0

Related Questions