id summary reporter owner description type status milestone component version severity resolution keywords cc
10646 polygon::iterator_compact_to_points returns wrong equality for the (last & penultimate) iterators Vadim Sukhorukov Andrii Sydorchuk "''iterator_compact_to_points'' is the part of ''polygon_90'' concept.
''polygon_90_data'' class exposes 2 iterators: ''compact_iterator_type'' and ''iterator_type''. ''iterator_type'' extracts the complete point on-the-fly. And for the penultimate iterator it makes the wromg comparison with the last iterator.
The reason of this bug is the specific implementation of operator++(). This is the same in boost versions 1.49 .. 1.56.
At the moment I can propose the following workaround:
{{{
typedef gtl::polygon_90_data Polygon90;
typedef gtl::polygon_traits_90::point_type Point;
typedef Polygon90::iterator_type Polygon90Iterator;
bool equalIterators(const Polygon90Iterator& left, const Polygon90Iterator& right)
{
if (left == right)
{
return ((*left) == (*right));
}
else
{
return false;
}
}
}}}
The implementation of operator++() [taken from boost sources]:
{{{
inline iterator_compact_to_points& operator++() {
iterator_type prev_iter = iter_;
++iter_;
if(iter_ == iter_end_) {
if(x(pt_) != firstX_) {
iter_ = prev_iter; // this line produces the issue
x(pt_, firstX_);
} // it changes the cached point, but rolls back the iterator
} else {
set(pt_, orient_, *iter_);
orient_.turn_90();
}
return *this;
}
}}}
The testing code:
{{{
#include
namespace gtl = boost::polygon;
#include
typedef gtl::polygon_90_data Polygon90;
typedef gtl::polygon_traits_90::point_type Point;
typedef Polygon90::iterator_type Polygon90Iterator;
std::vector polygonData;
polygonData.push_back(Point(15, 07)); // 1
polygonData.push_back(Point(20, 07)); // 2
polygonData.push_back(Point(20, 05)); // 3
polygonData.push_back(Point(16, 05)); // 4
polygonData.push_back(Point(16, 01)); // 5
polygonData.push_back(Point(01, 01)); // 6
polygonData.push_back(Point(01, 06)); // 7
polygonData.push_back(Point(03, 06)); // 8
polygonData.push_back(Point(03, 10)); // 9
polygonData.push_back(Point(05, 10)); // 10
Polygon90 polygon90;
polygon90.set(polygonData.begin(), polygonData.end());
Polygon90Iterator it = polygon90.begin();
for (int i = 0; i < 8; i++)
{
it++;
}
Polygon90Iterator it_9th = it;
it++; // this one points to 10th element
bool bug = (it == it_9th);
}}}" Bugs closed To Be Determined polygon Boost 1.58.0 Problem fixed