Skip to content

Commit

Permalink
Fix InteriorPoint for MultiLineString with EMPTY (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts authored Nov 29, 2023
1 parent 5b1bb50 commit dab54e3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public Coordinate getInteriorPoint()
*/
private void addInterior(Geometry geom)
{
if (geom.isEmpty())
return;

if (geom instanceof LineString) {
addInterior(geom.getCoordinates());
}
Expand All @@ -93,6 +96,9 @@ private void addInterior(Coordinate[] pts)
*/
private void addEndpoints(Geometry geom)
{
if (geom.isEmpty())
return;

if (geom instanceof LineString) {
addEndpoints(geom.getCoordinates());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public void testPolygonZeroArea() {
checkInteriorPoint(read("POLYGON ((10 10, 10 10, 10 10, 10 10))"), new Coordinate(10, 10));
}

public void testMultiLineWithEmpty() {
checkInteriorPoint(read("MULTILINESTRING ((0 0, 1 1), EMPTY)"), new Coordinate(0, 0));
}

public void testAll() throws Exception
{
checkInteriorPointFile(TestFiles.getResourceFilePath("world.wkt"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<run>
<precisionModel scale="1.0" offsetx="0.0" offsety="0.0"/>

<case>
<desc>P - empty</desc>
Expand Down Expand Up @@ -38,7 +37,7 @@
<desc>L - linestring with single segment</desc>
<a> LINESTRING (0 0, 7 14)
</a>
<test><op name="getInteriorPoint" arg1="A" > POINT (7 14) </op></test>
<test><op name="getInteriorPoint" arg1="A" > POINT (0 0) </op></test>
</case>

<case>
Expand Down Expand Up @@ -68,6 +67,13 @@
<test><op name="getInteriorPoint" arg1="A" > POINT (180 200) </op></test>
</case>

<case>
<desc>mL - multilinestring with empty</desc>
<a> MULTILINESTRING ((0 0, 1 1), EMPTY)
</a>
<test><op name="getInteriorPoint" arg1="A" > POINT (0 0) </op></test>
</case>

<case>
<desc>A - box</desc>
<a> POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))
Expand All @@ -93,7 +99,7 @@
<desc>A - polygon with horizontal segment at centre (narrower L shape)</desc>
<a> POLYGON ((0 2, 0 4, 3 4, 3 0, 2 0, 2 2, 0 2))
</a>
<test><op name="getInteriorPoint" arg1="A" > POINT (2 3) </op></test>
<test><op name="getInteriorPoint" arg1="A" > POINT (1.5 3) </op></test>
</case>

<case>
Expand All @@ -103,6 +109,14 @@
<test><op name="getInteriorPoint" arg1="A" > POINT (115 200) </op></test>
</case>


<case>
<desc>mA - multipolygon with empty</desc>
<a> MULTIPOLYGON (((0 2, 0 4, 3 4, 3 0, 2 0, 2 2, 0 2)), EMPTY)
</a>
<test><op name="getInteriorPoint" arg1="A" > POINT (1.5 3) </op></test>
</case>

<case>
<desc>GC - collection of polygons, lines, points</desc>
<a> GEOMETRYCOLLECTION (POLYGON ((0 40, 40 40, 40 0, 0 0, 0 40)),
Expand Down

0 comments on commit dab54e3

Please sign in to comment.