Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,11 @@ public int locateWithDim(Coordinate pt) {
* <p>
* Generally self-noding is required for geometries containing
* edges (i.e. polygons or lines).
* However, polygonal geometries which do not contain holes
* However, a single polygon which does not contain holes
* do not need to be self-noded.
* This is a relatively common case, so is worth checking for efficiency.
* Self-noding is not required
* because while MultiPolygon elements may self-touch at a vertex and an edge,
* that vertex is noded against the other predicate input geometry.
* The situation where this doesn't hold is when
* a hole vertex touches the shell,
* and the other geometry has an identical shell.
* Thus the presence of holes indicates self-noding is required.
* Self-noding is not required because the shell of a valid Polygon cannot self-touch
* (whereas valid MultiPolygons and holes can self-touch.)
* This is a relatively common case, so is worth checking for efficiency.
*
* @return true if self-noding is required for this geometry
*/
Expand All @@ -275,23 +270,22 @@ public boolean isSelfNodingRequired() {
return false;

// See https://github.com/libgeos/geos/issues/1558
if (isPolygonalNoHoles(geom))
if (isSinglePolygonNoHoles(geom))
return false;
//TODO: could avoid self-noding GC with single polygon with no holes
return true;
}

private static boolean isPolygonalNoHoles(Geometry geom) {
private static boolean isSinglePolygonNoHoles(Geometry geom) {
if (! (geom instanceof Polygonal)) {
return false;
}
//-- test if any polygon element has a hole
for (int i = 0; i < geom.getNumGeometries(); i++) {
Polygon poly = (Polygon) geom.getGeometryN(i);
if (poly.getNumInteriorRing() > 0)
return false;
}
return true;
if (geom.getNumGeometries() > 1)
return false;

Polygon poly = (Polygon) geom.getGeometryN(0);
boolean hasHole = poly.getNumInteriorRing() > 0;
return ! hasHole;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,19 @@ public boolean isAreaArea() {
* Self-noding is required for geometries which may
* have self-crossing or non-noded self-touching linework,
* or may have lines lying in the boundary of an area.
* This causes the coordinates of nodes created by
* crossing segments to be computed explicitly.
* This ensures that node locations match in situations
* where a self-crossing and mutual crossing occur at the same logical location.
* The canonical example is a self-crossing line tested against a single segment
* identical to one of the crossed segments.
* Self-noding causes nodes created by
* at crosses and touches to be computed explicitly,
* which is required for correct topology building at the node.
* Canonical examples include a self-crossing line tested against a single segment
* identical to one of the crossed segments;
* and two elements of a MultiPolygon touching at a vertex and and edge.
*
* Currently, requiring self-noding prevents noder caching.
* So it is more efficient to limit the cases which require self-noding.
* However, avoiding self-noding needs to be conservative, to ensure
* correct predicate evaluation.
* Currently self-noding is required for most geometry containing
* edges, except for the (common) case of polygonal geometries with no holes.
* edges, except for the (common) case of a polygon with no holes.
*
* @return true if self-noding is required
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,19 @@ public void testSelfNodingBOverlappingPolygons() {
checkTouches(a, b, false);
}

public void testSelfNodingMultiPolygonTouch() {
String a = "MULTIPOLYGON (((1 5, 5 5, 5 1, 1 1, 1 5)), ((1 8, 5 8, 3 5, 1 8)))";
String b = "POLYGON ((1 5, 5 5, 5 1, 1 1, 1 5))";
//checkRelate(a, b, "2FF11F212");
checkIntersectsDisjoint(a, b, true);
checkContainsWithin(a, b, true);
checkContainsWithin(b, a, false);
checkCoversCoveredBy(a, b, true);
checkCoversCoveredBy(b, a, false);
checkOverlaps(b, a, false);
checkTouches(a, b, false);
}

// see https://github.com/libgeos/geos/issues/1595
public void testSelfNodingBLines() {
String a = "POLYGON((0 0,10 0,0 10,0 0))";
Expand Down
21 changes: 21 additions & 0 deletions modules/tests/src/test/resources/testxml/general/TestRelateAA.xml
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,25 @@
<test> <op name="intersects" arg1="A" arg2="B"> true </op></test>
</case>

<case>
<desc>A/mA - A equal to one eleent of mA, touching at vertex and edge</desc>
<a>
POLYGON ((1 5, 5 5, 5 1, 1 1, 1 5))
</a>
<b>
MULTIPOLYGON (((1 5, 5 5, 5 1, 1 1, 1 5)), ((1 8, 5 8, 3 5, 1 8)))
</b>
<test><op name="relate" arg3="2FFF1F212" arg1="A" arg2="B"> true </op></test>
<test><op name="contains" arg1="A" arg2="B"> false </op></test>
<test><op name="coveredBy" arg1="A" arg2="B"> true </op></test>
<test><op name="covers" arg1="A" arg2="B"> false </op></test>
<test><op name="crosses" arg1="A" arg2="B"> false </op></test>
<test><op name="disjoint" arg1="A" arg2="B"> false </op></test>
<test><op name="equalsTopo" arg1="A" arg2="B"> false </op></test>
<test><op name="intersects" arg1="A" arg2="B"> true </op></test>
<test><op name="overlaps" arg1="A" arg2="B"> false </op></test>
<test><op name="touches" arg1="A" arg2="B"> false </op></test>
<test><op name="within" arg1="A" arg2="B"> true </op></test>
</case>

</run>
Loading