From b28e8528ce2a42a251af3920e993e394206c54ef Mon Sep 17 00:00:00 2001 From: mukoki Date: Tue, 1 Sep 2020 21:34:09 +0200 Subject: [PATCH] Fix RayCrossingCounter to handle XYZM coordinates (#589) * Fix RayCrossingCounter to handle XYZM coordinates Signed-off-by: mukoki --- .../jts/algorithm/RayCrossingCounter.java | 8 ++++++-- .../jts/algorithm/RayCrossingCounterTest.java | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/locationtech/jts/algorithm/RayCrossingCounter.java b/modules/core/src/main/java/org/locationtech/jts/algorithm/RayCrossingCounter.java index 6cc128ab39..3e22a7331d 100644 --- a/modules/core/src/main/java/org/locationtech/jts/algorithm/RayCrossingCounter.java +++ b/modules/core/src/main/java/org/locationtech/jts/algorithm/RayCrossingCounter.java @@ -85,8 +85,12 @@ public static int locatePointInRing(Coordinate p, CoordinateSequence ring) { Coordinate p1 = new Coordinate(); Coordinate p2 = new Coordinate(); for (int i = 1; i < ring.size(); i++) { - ring.getCoordinate(i, p1); - ring.getCoordinate(i - 1, p2); + //ring.getCoordinate(i, p1); // throws exception if ring contains M ordinate + p1.x = ring.getOrdinate(i, CoordinateSequence.X); + p1.y = ring.getOrdinate(i, CoordinateSequence.Y); + //ring.getCoordinate(i - 1, p2); // throws exception if ring contains M ordinate + p2.x = ring.getOrdinate(i - 1, CoordinateSequence.X); + p2.y = ring.getOrdinate(i - 1, CoordinateSequence.Y); counter.countSegment(p1, p2); if (counter.isOnSegment()) return counter.getLocation(); diff --git a/modules/core/src/test/java/org/locationtech/jts/algorithm/RayCrossingCounterTest.java b/modules/core/src/test/java/org/locationtech/jts/algorithm/RayCrossingCounterTest.java index 132a8ebbe4..2940c55511 100644 --- a/modules/core/src/test/java/org/locationtech/jts/algorithm/RayCrossingCounterTest.java +++ b/modules/core/src/test/java/org/locationtech/jts/algorithm/RayCrossingCounterTest.java @@ -12,7 +12,10 @@ package org.locationtech.jts.algorithm; import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.CoordinateSequence; import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.Location; +import org.locationtech.jts.geom.impl.PackedCoordinateSequenceFactory; import org.locationtech.jts.io.WKTReader; import junit.textui.TestRunner; @@ -28,15 +31,28 @@ public class RayCrossingCounterTest extends AbstractPointInRingTest { public static void main(String args[]) { TestRunner.run(RayCrossingCounterTest.class); + //new RayCrossingCounterTest("RayCrossingCounterTest").testRunPtInRing4d(); } public RayCrossingCounterTest(String name) { super(name); } protected void runPtInRing(int expectedLoc, Coordinate pt, String wkt) - throws Exception + throws Exception { Geometry geom = reader.read(wkt); assertEquals(expectedLoc, RayCrossingCounter.locatePointInRing(pt, geom.getCoordinates())); } + public void testRunPtInRing4d() + { + CoordinateSequence cs = new PackedCoordinateSequenceFactory(PackedCoordinateSequenceFactory.DOUBLE) + .create(new double[]{ + 0.0, 0.0, 0.0, 0.0, + 10.0, 0.0, 0.0, 0.0, + 5.0, 10.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0 + }, 4, 1); + assertEquals(Location.INTERIOR, RayCrossingCounter.locatePointInRing(new Coordinate(5.0, 2.0), cs)); + } + }