Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#10646 closed Bugs (fixed)

polygon::iterator_compact_to_points returns wrong equality for the (last & penultimate) iterators

Reported by: Vadim Sukhorukov <vadim.sukhorukov@…> Owned by: Andrii Sydorchuk
Milestone: To Be Determined Component: polygon
Version: Boost 1.58.0 Severity: Problem
Keywords: Cc:

Description

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<int> Polygon90;
typedef gtl::polygon_traits_90<Polygon90>::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 <boost/polygon/polygon.hpp>
namespace gtl = boost::polygon;

#include <vector>

typedef gtl::polygon_90_data<int> Polygon90;
typedef gtl::polygon_traits_90<Polygon90>::point_type Point;
typedef Polygon90::iterator_type Polygon90Iterator;

  std::vector<Point> 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);

Change History (4)

comment:1 by Andrii Sydorchuk, 8 years ago

Owner: changed from Lucanus Simonson to Andrii Sydorchuk

comment:2 by Andrii Sydorchuk, 8 years ago

Hi Vadim,

Thank you for your report! The fix and tests were merged into develop and master branches. The fix will be merged into 1.58 release.

comment:3 by Andrii Sydorchuk, 8 years ago

Resolution: fixed
Status: newclosed
Version: Boost 1.49.0Boost 1.58.0

comment:4 by vadim.sukhorukov@…, 7 years ago

It is nit fixed in Boost 1.58.0 and even in Boost 1.60.0. The reported problem code is not changed. If you have a fix, please commit it to the repository.

Note: See TracTickets for help on using tickets.