Skip to content

Commit

Permalink
Fix RayCrossingCounter to handle XYZM coordinates (#589)
Browse files Browse the repository at this point in the history
* Fix RayCrossingCounter to handle XYZM coordinates

Signed-off-by: mukoki <[email protected]>
  • Loading branch information
mukoki authored Sep 1, 2020
1 parent 85b9cef commit b28e852
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}

}

0 comments on commit b28e852

Please sign in to comment.