Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RayCrossingCounter to handle XYZM coordinates #589

Merged
merged 5 commits into from
Sep 1, 2020
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));
}

}