Opened 7 years ago
#11242 new Bugs
Accuray issue with geometry::difference() in version Boost 1.57 (and 1.58)
| Reported by: | Owned by: | Barend Gehrels | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | geometry |
| Version: | Boost 1.57.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
I'm having an accuracy issue with geometry::difference() in Boost v1.57 (and v1.58) that I didn't see with v1.55. The test program is listed below. I compiled using g++ 4.4.7 on Ubuntu 12.04.
Result using Boost v1.55:
249.232 761.09
249.232 760.98
265.89 760.98
265.89 729.219
94.021 729.219
94.021 761.09
249.232 761.09
Result using Boost v1.57 (and v1.58):
249.232003466816 761.09
249.232 760.98
265.89 760.979984987659
265.89 729.219
94.021 729.219
94.021 761.09
249.232003466816 761.09
Apparently, it is related to the rescaling policy introduced in v1.56. I can mitigate the issue by defining the BOOST_GEOMETRY_NO_ROBUSTNESS.
Best regards,
Mikkel B. Stegmann
#include <boost/foreach.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry.hpp>
#include <cstdio>
#include <assert.h>
int main() {
// 2D point with double precision
typedef boost::geometry::model::d2::point_xy<double> BoostPoint;
// 2D polygon, ring type: clockwise, closed ("the first point must be spatially equal to the last point")
typedef boost::geometry::model::polygon<BoostPoint> BoostPolygon;
BoostPolygon rectangleA;
rectangleA.outer().push_back(BoostPoint( 94.021, 729.219)); // clock-wise points
rectangleA.outer().push_back(BoostPoint( 94.021, 761.090));
rectangleA.outer().push_back(BoostPoint(265.890, 761.090));
rectangleA.outer().push_back(BoostPoint(265.890, 729.219));
rectangleA.outer().push_back(BoostPoint( 94.021, 729.219)); // close
BoostPolygon rectangleB;
rectangleB.outer().push_back(BoostPoint(249.232, 760.980)); // clock-wise points
rectangleB.outer().push_back(BoostPoint(249.232, 780.980));
rectangleB.outer().push_back(BoostPoint(319.232, 780.980));
rectangleB.outer().push_back(BoostPoint(319.232, 760.980));
rectangleB.outer().push_back(BoostPoint(249.232, 760.980)); // close
std::list<BoostPolygon> differencePolygons;
boost::geometry::difference(rectangleA, rectangleB, differencePolygons);
assert(differencePolygons.size()==1);
BOOST_FOREACH(const BoostPoint &point, differencePolygons.front().outer()) {
printf("%16.15g %16.15g\n", point.x(), point.y());
}
return 0;
}
Note:
See TracTickets
for help on using tickets.
