LUCENE-8139: Optimize polygon interior point discovery to check center of mass first. Committed on behalf of Ignacio Vera.

This commit is contained in:
Karl Wright 2018-01-25 10:33:42 -05:00
parent 776899b4e8
commit c10ba5a6d9
2 changed files with 23 additions and 2 deletions

View File

@ -162,6 +162,14 @@ public class GeoPolygonFactory {
if (filteredPointList == null) {
return null;
}
//First approximation to find a point
final GeoPoint centerOfMass = getCenterOfMass(filteredPointList);
final Boolean isCenterOfMassInside = isInsidePolygon(centerOfMass, filteredPointList);
if (isCenterOfMassInside != null) {
return generateGeoPolygon(planetModel, filteredPointList, holes, centerOfMass, isCenterOfMassInside);
}
//System.err.println("points="+pointList);
// Create a random number generator. Effectively this furnishes us with a repeatable sequence
// of points to use for poles.
@ -182,6 +190,19 @@ public class GeoPolygonFactory {
}
throw new IllegalArgumentException("cannot find a point that is inside the polygon "+filteredPointList);
}
private static GeoPoint getCenterOfMass(List<GeoPoint> points) {
double x = 0;
double y = 0;
double z = 0;
//get center of mass
for (GeoPoint point : points) {
x += point.x;
y += point.y;
z += point.z;
}
return new GeoPoint(x / points.size(), y / points.size(), z / points.size());
}
/** Use this class to specify a polygon with associated holes.
*/

View File

@ -51,7 +51,7 @@ public class RandomPlaneTest extends RandomGeo3dShapeGenerator {
}
}
/*
@Test
@Repeat(iterations = 10)
public void testPolygonAccuracy() {
@ -70,5 +70,5 @@ public class RandomPlaneTest extends RandomGeo3dShapeGenerator {
}
}
*/
}