Skip to content

Commit

Permalink
Fix OverlayNG handling of flat interior line
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Feb 9, 2021
1 parent df1d6c9 commit e309558
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/operation/overlayng/OverlayUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ OverlayUtil::safeExpandDistance(const Envelope* env, const PrecisionModel* pm)
if (isFloating(pm)) {
// if PM is FLOAT then there is no scale factor, so add 10%
double minSize = std::min(env->getHeight(), env->getWidth());
// heuristic to ensure zero-width envelopes don't cause total clipping
if (minSize <= 0.0) {
minSize = std::max(env->getHeight(), env->getWidth());
}
envExpandDist = SAFE_ENV_BUFFER_FACTOR * minSize;
}
else {
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/operation/overlayng/OverlayNGTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,33 @@ template<>
template<>
void object::test<43> ()
{
set_test_name("testPolygonLineIntersectionOrder");
std::string a = "POLYGON ((1 1, 1 9, 9 9, 9 7, 3 7, 3 3, 9 3, 9 1, 1 1))";
std::string b = "MULTILINESTRING ((2 10, 2 0), (4 10, 4 0))";
std::string exp = "MULTILINESTRING ((2 9, 2 1), (4 9, 4 7), (4 3, 4 1))";
testOverlay(a, b, exp, OverlayNG::INTERSECTION, 0);
}

template<>
template<>
void object::test<44> ()
{
set_test_name("testPolygonLineVerticalntersection");
std::string a = "POLYGON ((-200 -200, 200 -200, 200 200, -200 200, -200 -200))";
std::string b = "LINESTRING (-100 100, -100 -100)";
std::string exp = "LINESTRING (-100 100, -100 -100)";
testOverlay(a, b, exp, OverlayNG::INTERSECTION, 0);
}

template<>
template<>
void object::test<45> ()
{
set_test_name("testPolygonLineHorizontalIntersection");
std::string a = "POLYGON ((10 90, 90 90, 90 10, 10 10, 10 90))";
std::string b = "LINESTRING (20 50, 80 50)";
std::string exp = "LINESTRING (20 50, 80 50)";
testOverlay(a, b, exp, OverlayNG::INTERSECTION, 0);
}

} // namespace tut
25 changes: 25 additions & 0 deletions tests/xmltester/tests/general/TestNGOverlayL.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,31 @@ MULTILINESTRING ((150 150, 200 200, 300 300, 400 200), (100 100, 150 150), (190
</op></test>
</case>

<case>
<desc>LA - vertical Line</desc>
<a>
LINESTRING (50 50, 50 20)
</a>
<b>
POLYGON ((10 60, 90 60, 90 10, 10 10, 10 60))
</b>
<test> <op name="intersectionNG" arg1="A" arg2="B">
LINESTRING (50 50, 50 20)
</op></test>
<test> <op name="unionNG" arg1="A" arg2="B">
POLYGON ((90 60, 90 10, 10 10, 10 60, 90 60))
</op></test>
<test> <op name="differenceNG" arg1="A" arg2="B">
LINESTRING EMPTY
</op></test>
<test> <op name="differenceNG" arg1="B" arg2="A">
POLYGON ((90 60, 90 10, 10 10, 10 60, 90 60))
</op></test>
<test> <op name="symdifferenceNG" arg1="A" arg2="B">
POLYGON ((90 60, 90 10, 10 10, 10 60, 90 60))
</op></test>
</case>

<case>
<desc>mLmA - disjoint and overlaps in lines and points</desc>
<a>
Expand Down

0 comments on commit e309558

Please sign in to comment.