-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DistanceOp optimization for Point-Point (#1049)
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
modules/core/src/test/java/test/jts/perf/operation/distance/PointPointDistancePerfTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package test.jts.perf.operation.distance; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.locationtech.jts.geom.Coordinate; | ||
import org.locationtech.jts.geom.Envelope; | ||
import org.locationtech.jts.geom.Geometry; | ||
import org.locationtech.jts.geom.GeometryFactory; | ||
import org.locationtech.jts.geom.Point; | ||
|
||
import test.jts.perf.PerformanceTestCase; | ||
import test.jts.perf.PerformanceTestRunner; | ||
|
||
public class PointPointDistancePerfTest extends PerformanceTestCase { | ||
|
||
|
||
public static void main(String args[]) { | ||
PerformanceTestRunner.run(PointPointDistancePerfTest.class); | ||
} | ||
|
||
private Point[] grid; | ||
|
||
public PointPointDistancePerfTest(String name) { | ||
super(name); | ||
setRunSize(new int[] {10000}); | ||
setRunIterations(1); | ||
} | ||
|
||
public void startRun(int npts) | ||
{ | ||
System.out.println("\n------- Running with # pts = " + npts); | ||
grid = createPointGrid(new Envelope(0, 10., 0, 10), npts); | ||
} | ||
|
||
private Point[] createPointGrid(Envelope envelope, int npts) { | ||
List<Point> geoms = new ArrayList<Point>(); | ||
GeometryFactory fact = new GeometryFactory(); | ||
int nSide = (int) Math.sqrt(npts); | ||
double xInc = envelope.getWidth() / nSide; | ||
double yInc = envelope.getHeight() / nSide; | ||
for (int i = 0; i < nSide; i++) { | ||
for (int j = 0; j < nSide; j++) { | ||
double x = envelope.getMinX() + i * xInc; | ||
double y = envelope.getMinY() + i * yInc; | ||
Point p = fact.createPoint(new Coordinate(x, y)); | ||
geoms.add(p); | ||
} | ||
} | ||
return GeometryFactory.toPointArray(geoms); | ||
} | ||
|
||
public void runPoints() { | ||
for (Geometry p1 : grid) { | ||
for (Geometry p2 : grid) { | ||
double dist = p1.distance(p2); | ||
} | ||
} | ||
} | ||
|
||
} |