Add more tests, and catch degenerate case early

This commit is contained in:
Karl Wright 2016-04-28 19:27:36 -04:00
parent da896f803d
commit 31176d1de2
2 changed files with 38 additions and 1 deletions

View File

@ -88,7 +88,11 @@ 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 = filterEdges(filterPoints(pointList), leniencyValue);
final List<GeoPoint> firstFilteredPointList = filterPoints(pointList);
if (firstFilteredPointList == null) {
return null;
}
final List<GeoPoint> filteredPointList = filterEdges(firstFilteredPointList, leniencyValue);
//System.err.println(" ...done in "+(System.currentTimeMillis()-startTime)+"ms ("+((filteredPointList==null)?"degenerate":(filteredPointList.size()+" points"))+")");
if (filteredPointList == null) {
return null;

View File

@ -264,6 +264,39 @@ public class GeoPolygonTest {
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, Math.PI);
assertFalse(c.isWithin(gp));
// Now, same thing for large polygon
shapes = new ArrayList<>();
shapes.add(new GeoPolygonFactory.PolygonDescription(points));
c = GeoPolygonFactory.makeLargeGeoPolygon(PlanetModel.SPHERE, shapes);
// Sample some points within
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.5);
assertTrue(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.55);
assertTrue(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.45);
assertTrue(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, -0.05, -0.5);
assertTrue(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, 0.05, -0.5);
assertTrue(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.7);
assertTrue(c.isWithin(gp));
// Sample some nearby points outside
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, -0.35);
assertFalse(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, -0.15, -0.5);
assertFalse(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, 0.15, -0.5);
assertFalse(c.isWithin(gp));
// Random points outside
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, 0.0);
assertFalse(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, Math.PI * 0.5, 0.0);
assertFalse(c.isWithin(gp));
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, Math.PI);
assertFalse(c.isWithin(gp));
}
@Test