From 65dc8ed2aedddc80ff9b8fced0a5d20d6b0e93ef Mon Sep 17 00:00:00 2001 From: Karl Wright Date: Tue, 26 Apr 2016 08:03:02 -0400 Subject: [PATCH] Separate point filtering from edge filtering. --- .../spatial3d/geom/GeoPolygonFactory.java | 17 +++++++++++++---- .../lucene/spatial3d/geom/GeoPolygonTest.java | 8 ++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java index 609c8643c62..fea5b89d226 100755 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java @@ -90,7 +90,7 @@ public class GeoPolygonFactory { // First, exercise a sanity filter on the provided pointList, and remove identical points, linear points, and backtracks //System.err.println(" filtering "+pointList.size()+" points..."); //final long startTime = System.currentTimeMillis(); - final List filteredPointList = filterPoints(pointList, leniencyValue); + final List filteredPointList = filterEdges(filterPoints(pointList), leniencyValue); //System.err.println(" ...done in "+(System.currentTimeMillis()-startTime)+"ms ("+((filteredPointList==null)?"degenerate":(filteredPointList.size()+" points"))+")"); if (filteredPointList == null) { return null; @@ -167,12 +167,11 @@ public class GeoPolygonFactory { } } - /** Filter duplicate points and coplanar points. + /** Filter duplicate points. * @param input with input list of points - * @param leniencyValue is the allowed distance of a point from the plane for cleanup of overly detailed polygons * @return the filtered list, or null if we can't get a legit polygon from the input. */ - static List filterPoints(final List input, final double leniencyValue) { + static List filterPoints(final List input) { final List noIdenticalPoints = new ArrayList<>(input.size()); @@ -214,6 +213,16 @@ public class GeoPolygonFactory { return null; } + return noIdenticalPoints; + } + + /** Filter coplanar points. + * @param noIdenticalPoints with input list of points + * @param leniencyValue is the allowed distance of a point from the plane for cleanup of overly detailed polygons + * @return the filtered list, or null if we can't get a legit polygon from the input. + */ + static List filterEdges(final List noIdenticalPoints, final double leniencyValue) { + // Now, do the depth-first search needed to find a path that has no coplanarities in it. // This is, unfortunately, not easy, because coplanarity is not transitive as you walk around the polygon. // If point C is not coplanar with edge A-B, there is no guarantee that A is not coplanar with B-C. diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java index ce43c5b172f..d76ae4ee56b 100755 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPolygonTest.java @@ -44,7 +44,7 @@ public class GeoPolygonTest { originalPoints.add(point2); originalPoints.add(point2); originalPoints.add(point3); - final List filteredPoints =GeoPolygonFactory.filterPoints(originalPoints, 0.0); + final List filteredPoints = GeoPolygonFactory.filterEdges(GeoPolygonFactory.filterPoints(originalPoints), 0.0); assertEquals(3, filteredPoints.size()); assertEquals(point1, filteredPoints.get(0)); assertEquals(point2, filteredPoints.get(1)); @@ -57,7 +57,7 @@ public class GeoPolygonTest { originalPoints.add(point1); originalPoints.add(point3); originalPoints.add(point2); - final List filteredPoints =GeoPolygonFactory.filterPoints(originalPoints, 0.0); + final List filteredPoints = GeoPolygonFactory.filterEdges(GeoPolygonFactory.filterPoints(originalPoints), 0.0); assertEquals(3, filteredPoints.size()); assertEquals(point2, filteredPoints.get(0)); assertEquals(point1, filteredPoints.get(1)); @@ -71,7 +71,7 @@ public class GeoPolygonTest { originalPoints.add(point3); originalPoints.add(point4); originalPoints.add(point5); - final List filteredPoints =GeoPolygonFactory.filterPoints(originalPoints, 0.0); + final List filteredPoints = GeoPolygonFactory.filterEdges(GeoPolygonFactory.filterPoints(originalPoints), 0.0); assertEquals(3, filteredPoints.size()); assertEquals(point1, filteredPoints.get(0)); assertEquals(point3, filteredPoints.get(1)); @@ -85,7 +85,7 @@ public class GeoPolygonTest { originalPoints.add(point3); originalPoints.add(point4); System.err.println("Before: "+originalPoints); - final List filteredPoints =GeoPolygonFactory.filterPoints(originalPoints, 0.0); + final List filteredPoints = GeoPolygonFactory.filterEdges(GeoPolygonFactory.filterPoints(originalPoints), 0.0); System.err.println("After: "+filteredPoints); assertEquals(3, filteredPoints.size()); assertEquals(point5, filteredPoints.get(0));