From 3467e23ee6503e199cede3be63fced189c37ed37 Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Fri, 19 Jan 2024 10:28:31 -0800 Subject: [PATCH] Add TestBuilder Selection functions for prep geoms --- .../jtstest/function/SelectionFunctions.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/modules/app/src/main/java/org/locationtech/jtstest/function/SelectionFunctions.java b/modules/app/src/main/java/org/locationtech/jtstest/function/SelectionFunctions.java index c58f9aea6e..0545649fc9 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/function/SelectionFunctions.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/function/SelectionFunctions.java @@ -16,12 +16,23 @@ import java.util.List; import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.prep.PreparedGeometry; +import org.locationtech.jts.geom.prep.PreparedGeometryFactory; import org.locationtech.jts.operation.distance.IndexedFacetDistance; - - public class SelectionFunctions { + + public static Geometry intersectsPrep(Geometry a, final Geometry mask) + { + PreparedGeometry prep = PreparedGeometryFactory.prepare(mask); + return select(a, new GeometryPredicate() { + public boolean isTrue(Geometry g) { + return prep.intersects(g); + } + }); + } + public static Geometry intersects(Geometry a, final Geometry mask) { return select(a, new GeometryPredicate() { @@ -35,7 +46,17 @@ public static Geometry covers(Geometry a, final Geometry mask) { return select(a, new GeometryPredicate() { public boolean isTrue(Geometry g) { - return g.covers(mask); + return mask.covers(g); + } + }); + } + + public static Geometry coversPrep(Geometry a, final Geometry mask) + { + PreparedGeometry prep = PreparedGeometryFactory.prepare(mask); + return select(a, new GeometryPredicate() { + public boolean isTrue(Geometry g) { + return prep.covers(g); } }); } @@ -168,7 +189,7 @@ public boolean isTrue(Geometry g) { }); } - private static Geometry select(Geometry geom, GeometryPredicate pred) + public static Geometry select(Geometry geom, GeometryPredicate pred) { List selected = new ArrayList(); for (int i = 0; i < geom.getNumGeometries(); i++ ) {