LUCENE-7226: Slight improvements to filtering and pole discovery operations.

This commit is contained in:
Karl Wright 2016-04-19 20:12:05 -04:00
parent 92f6a39ff5
commit 0221516716
2 changed files with 17 additions and 11 deletions

View File

@ -136,6 +136,7 @@ public final class Geo3DPoint extends Field {
* @return query matching points within this polygon * @return query matching points within this polygon
*/ */
public static Query newPolygonQuery(final String field, final Polygon... polygons) { public static Query newPolygonQuery(final String field, final Polygon... polygons) {
//System.err.println("Creating polygon...");
if (polygons.length < 1) { if (polygons.length < 1) {
throw new IllegalArgumentException("need at least one polygon"); throw new IllegalArgumentException("need at least one polygon");
} }
@ -158,6 +159,7 @@ public final class Geo3DPoint extends Field {
} }
shape = poly; shape = poly;
} }
//System.err.println("...done");
return newShapeQuery(field, shape); return newShapeQuery(field, shape);
} }
@ -221,7 +223,10 @@ public final class Geo3DPoint extends Field {
points.add(new GeoPoint(PlanetModel.WGS84, fromDegrees(polyLats[index]), fromDegrees(polyLons[index]))); points.add(new GeoPoint(PlanetModel.WGS84, fromDegrees(polyLats[index]), fromDegrees(polyLons[index])));
} }
} }
return GeoPolygonFactory.makeGeoPolygon(PlanetModel.WGS84, points, holeList); //System.err.println(" building polygon with "+points.size()+" points...");
final GeoPolygon rval = GeoPolygonFactory.makeGeoPolygon(PlanetModel.WGS84, points, holeList);
//System.err.println(" ...done");
return rval;
} }
/** /**

View File

@ -64,7 +64,10 @@ public class GeoPolygonFactory {
final List<GeoPoint> pointList, final List<GeoPoint> pointList,
final List<GeoPolygon> holes) { final List<GeoPolygon> holes) {
// 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...");
//final long startTime = System.currentTimeMillis();
final List<GeoPoint> filteredPointList = filterPoints(pointList); final List<GeoPoint> filteredPointList = filterPoints(pointList);
//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;
} }
@ -86,7 +89,7 @@ public class GeoPolygonFactory {
} }
// If pole choice was illegal, try another one // If pole choice was illegal, try another one
} }
throw new IllegalArgumentException("cannot find a point that is inside the polygon"); throw new IllegalArgumentException("cannot find a point that is inside the polygon "+filteredPointList);
} }
/** /**
@ -274,12 +277,12 @@ public class GeoPolygonFactory {
while (checkIndex != considerPointIndex) { while (checkIndex != considerPointIndex) {
if (!considerPlane.evaluateIsZero(points.get(checkIndex))) { if (!considerPlane.evaluateIsZero(points.get(checkIndex))) {
// This possibility is no good. But does it say anything about other possibilities? I think // This possibility is no good. But does it say anything about other possibilities? I think
// it may mean we don't have to consider any further extensions; gotta work that through // it may mean we don't have to consider any further extensions. I can't prove this, but
// mathematically though before coding it. // it makes this algorithm complete in not an insane period of time at least...
//System.err.println(" interior point not coplanar with trial plane"); //System.err.println(" interior point not coplanar with trial plane");
isChoiceLegal = false; //isChoiceLegal = false;
break; //break;
//return null; return null;
} }
checkIndex = getLegalIndex(checkIndex + 1, points.size()); checkIndex = getLegalIndex(checkIndex + 1, points.size());
} }
@ -309,9 +312,6 @@ public class GeoPolygonFactory {
return null; return null;
} }
/** The maximum distance from the close point to the trial pole: 2 degrees */
private final static double MAX_POLE_DISTANCE = Math.PI * 0.25 / 180.0;
/** Pick a random pole that has a good chance of being inside the polygon described by the points. /** Pick a random pole that has a good chance of being inside the polygon described by the points.
* @param generator is the random number generator to use. * @param generator is the random number generator to use.
* @param planetModel is the planet model to use. * @param planetModel is the planet model to use.
@ -323,7 +323,8 @@ public class GeoPolygonFactory {
final GeoPoint closePoint = points.get(pointIndex); final GeoPoint closePoint = points.get(pointIndex);
// We pick a random angle and random arc distance, then generate a point based on closePoint // We pick a random angle and random arc distance, then generate a point based on closePoint
final double angle = generator.nextDouble() * Math.PI * 2.0 - Math.PI; final double angle = generator.nextDouble() * Math.PI * 2.0 - Math.PI;
final double arcDistance = MAX_POLE_DISTANCE - generator.nextDouble() * MAX_POLE_DISTANCE; final double maxArcDistance = points.get(0).arcDistance(points.get(1));
final double arcDistance = maxArcDistance - generator.nextDouble() * maxArcDistance;
// We come up with a unit circle (x,y,z) coordinate given the random angle and arc distance. The point is centered around the positive x axis. // We come up with a unit circle (x,y,z) coordinate given the random angle and arc distance. The point is centered around the positive x axis.
final double x = Math.cos(arcDistance); final double x = Math.cos(arcDistance);
final double sinArcDistance = Math.sin(arcDistance); final double sinArcDistance = Math.sin(arcDistance);