Skip to content

Commit

Permalink
Fix PointLocator with BoundaryNodeRule for lines (locationtech#1031)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Jan 19, 2024
1 parent 788082e commit fa4e05b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ private int locateOnLineString(Coordinate p, LineString l)
if (! l.getEnvelopeInternal().intersects(p)) return Location.EXTERIOR;

CoordinateSequence seq = l.getCoordinateSequence();
if (! l.isClosed()) {
if (p.equals(seq.getCoordinate(0))
if (p.equals(seq.getCoordinate(0))
|| p.equals(seq.getCoordinate(seq.size() - 1)) ) {
return Location.BOUNDARY;
}
int boundaryCount = l.isClosed() ? 2 : 1;
int loc = boundaryRule.isInBoundary(boundaryCount) ? Location.BOUNDARY : Location.INTERIOR;
return loc;
}
if (PointLocation.isOnLine(p, seq)) {
return Location.INTERIOR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@ public void testPolygon() throws Exception {
assertEquals(Location.INTERIOR, pointLocator.locate(new Coordinate(190, 150), polygon));
}

private void runPtLocator(int expected, Coordinate pt, String wkt)
public void testRingBoundaryNodeRule() throws Exception
{
String wkt = "LINEARRING(10 10, 10 20, 20 10, 10 10)";
Coordinate pt = new Coordinate(10, 10);
runPtLocator(Location.INTERIOR, pt, wkt, BoundaryNodeRule.MOD2_BOUNDARY_RULE);
runPtLocator(Location.BOUNDARY, pt, wkt, BoundaryNodeRule.ENDPOINT_BOUNDARY_RULE);
runPtLocator(Location.INTERIOR, pt, wkt, BoundaryNodeRule.MONOVALENT_ENDPOINT_BOUNDARY_RULE);
runPtLocator(Location.BOUNDARY, pt, wkt, BoundaryNodeRule.MULTIVALENT_ENDPOINT_BOUNDARY_RULE);
}

private void runPtLocator(int expected, Coordinate pt, String wkt)
throws Exception
{
Geometry geom = reader.read(wkt);
Expand All @@ -76,4 +86,14 @@ private void runPtLocator(int expected, Coordinate pt, String wkt)
assertEquals(expected, loc);
}

private void runPtLocator(int expected, Coordinate pt, String wkt,
BoundaryNodeRule bnr)
throws Exception
{
Geometry geom = reader.read(wkt);
PointLocator pointLocator = new PointLocator(bnr);
int loc = pointLocator.locate(pt, geom);
assertEquals(expected, loc);
}

}

0 comments on commit fa4e05b

Please sign in to comment.