mirror of https://github.com/apache/lucene.git
Add more tests, and catch degenerate case early
This commit is contained in:
parent
da896f803d
commit
31176d1de2
|
@ -88,7 +88,11 @@ public class GeoPolygonFactory {
|
||||||
// First, exercise a sanity filter on the provided pointList, and remove identical points, linear points, and backtracks
|
// First, exercise a sanity filter on the provided pointList, and remove identical points, linear points, and backtracks
|
||||||
//System.err.println(" filtering "+pointList.size()+" points...");
|
//System.err.println(" filtering "+pointList.size()+" points...");
|
||||||
//final long startTime = System.currentTimeMillis();
|
//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"))+")");
|
//System.err.println(" ...done in "+(System.currentTimeMillis()-startTime)+"ms ("+((filteredPointList==null)?"degenerate":(filteredPointList.size()+" points"))+")");
|
||||||
if (filteredPointList == null) {
|
if (filteredPointList == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -264,6 +264,39 @@ public class GeoPolygonTest {
|
||||||
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, Math.PI);
|
gp = new GeoPoint(PlanetModel.SPHERE, 0.0, Math.PI);
|
||||||
assertFalse(c.isWithin(gp));
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue