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 @@ -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));
}

}