Commit bcf347af authored by Dan Baston's avatar Dan Baston

Fix infinite loop in GEOSClipByRect

Fixes #865
Closes https://github.com/libgeos/geos/pull/110
parent d3adb9f0
Pipeline #26828160 failed with stage
in 3 minutes and 13 seconds
......@@ -60,6 +60,11 @@ bool different(double x1, double y1, double x2, double y2)
inline
void clip_one_edge(double & x1, double & y1, double x2, double y2, double limit)
{
if (x2 == limit) {
y1 = y2;
x1 = x2;
}
if(x1 != x2)
{
y1 += (y2-y1)*(limit-x1)/(x2-x1);
......
......@@ -22,6 +22,7 @@
#include <geos/geom/LineString.h>
#include <geos/geom/LinearRing.h>
#include <geos/algorithm/CGAlgorithms.h>
#include <geos/util/IllegalArgumentException.h>
#include <cmath> // for fabs()
......@@ -184,6 +185,13 @@ double distance(const Rectangle & rect,
Rectangle::Position pos = rect.position(x1,y1);
Rectangle::Position endpos = rect.position(x2,y2);
if (pos & Rectangle::Position::Outside ||
endpos & Rectangle::Position::Outside ||
pos & Rectangle::Position::Inside ||
endpos & Rectangle::Position::Inside) {
throw geos::util::IllegalArgumentException("Can't compute distance to non-boundary position.");
}
while(true)
{
// Close up when we have the same edge and the
......
......@@ -101,7 +101,6 @@ namespace tut
typedef group::object object;
group test_rectangleintersectiontest_group("geos::operation::intersection::RectangleIntersection");
// inside
template<> template<> void object::test<1>()
{
......@@ -1514,4 +1513,19 @@ namespace tut
"POLYGON((0 0,0 10,10 10,10 0,0 0))";
doClipTest(inp, exp, r);
}
// PostGIS hanging unit test
template<> template<> void object::test<208>()
{
Rectangle r(3.0481343214686657e-14, -20000000.000000, 20000000.000000, -1.000000);
const char *clip =
"POLYGON((3.0481343214686657e-14 -20000000, 200000000 -20000000, 200000000 -1, 3.0481343214686657e-14 -1, 3.0481343214686657e-14 -20000000))";
const char *inp =
"POLYGON((3.0481343214686657e-14 -20000000, 3.0481343214686657e-14 -1, 1.570795680861262382313481289e-3 -0.999998766299703523152686557296, 3.141587485909849188081555127e-3 -0.999995065201858102099663483386, 3.0481343214686657e-14 -20000000))";
GeomPtr isect{readWKT(clip)->intersection(readWKT(inp).get())};
std::string exp = wktwriter.write(isect.get());
doClipTest(inp, exp, r, 1e-20);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment