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 some algorithms handling of XYZM coordinates #795

Merged
merged 1 commit into from
Nov 2, 2021
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 @@ -93,9 +93,9 @@ public static double ofRingSigned(CoordinateSequence ring)
* Based on the Shoelace formula.
* http://en.wikipedia.org/wiki/Shoelace_formula
*/
Coordinate p0 = new Coordinate();
Coordinate p1 = new Coordinate();
Coordinate p2 = new Coordinate();
Coordinate p0 = ring.createCoordinate();
Coordinate p1 = ring.createCoordinate();
Coordinate p2 = ring.createCoordinate();
ring.getCoordinate(0, p1);
ring.getCoordinate(1, p2);
double x0 = p1.x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static double ofLine(CoordinateSequence pts)

double len = 0.0;

Coordinate p = new Coordinate();
Coordinate p = pts.createCoordinate();
pts.getCoordinate(0, p);
double x0 = p.x;
double y0 = p.y;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.locationtech.jts.geom;

import org.locationtech.jts.geom.impl.PackedCoordinateSequenceFactory;
import org.locationtech.jts.io.ParseException;

import junit.textui.TestRunner;
import test.jts.GeometryTestCase;

/**
* Tests to confirm that operations call {@link CoordinateSequence#createCoordinate()}
* to ensure they work correctly with coordinates of any dimension
* (in particular XYZM coordinates, which do not fit in the default {@link Coordinate}).
*
* @author Martin Davis
*
*/
public class GeometryXYZMTest extends GeometryTestCase {
public static void main(String args[]) {
TestRunner.run(GeometryXYZMTest.class);
}

static GeometryFactory geomFact = new GeometryFactory(PackedCoordinateSequenceFactory.DOUBLE_FACTORY);

public GeometryXYZMTest(String name) { super(name); }

public void testArea() {
Polygon geom = (Polygon) read(geomFact, "POLYGON ZM ((1 9 2 3, 9 9 2 3, 9 1 2 3, 1 1 2 3, 1 9 2 3))");
double area = geom.getArea();
assertEquals(64.0, area);
}

public void testLength() {
Polygon geom = (Polygon) read(geomFact, "POLYGON ZM ((1 9 2 3, 9 9 2 3, 9 1 2 3, 1 1 2 3, 1 9 2 3))");
double len = geom.getLength();
assertEquals(32.0, len);
}
}