Separate point filtering from edge filtering.

This commit is contained in:
Karl Wright 2016-04-26 08:03:02 -04:00
parent 129f6d4767
commit 65dc8ed2ae
2 changed files with 17 additions and 8 deletions

View File

@ -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<GeoPoint> filteredPointList = filterPoints(pointList, leniencyValue);
final List<GeoPoint> 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<GeoPoint> filterPoints(final List<GeoPoint> input, final double leniencyValue) {
static List<GeoPoint> filterPoints(final List<GeoPoint> input) {
final List<GeoPoint> 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<GeoPoint> filterEdges(final List<GeoPoint> 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.

View File

@ -44,7 +44,7 @@ public class GeoPolygonTest {
originalPoints.add(point2);
originalPoints.add(point2);
originalPoints.add(point3);
final List<GeoPoint> filteredPoints =GeoPolygonFactory.filterPoints(originalPoints, 0.0);
final List<GeoPoint> 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<GeoPoint> filteredPoints =GeoPolygonFactory.filterPoints(originalPoints, 0.0);
final List<GeoPoint> 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<GeoPoint> filteredPoints =GeoPolygonFactory.filterPoints(originalPoints, 0.0);
final List<GeoPoint> 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<GeoPoint> filteredPoints =GeoPolygonFactory.filterPoints(originalPoints, 0.0);
final List<GeoPoint> filteredPoints = GeoPolygonFactory.filterEdges(GeoPolygonFactory.filterPoints(originalPoints), 0.0);
System.err.println("After: "+filteredPoints);
assertEquals(3, filteredPoints.size());
assertEquals(point5, filteredPoints.get(0));