LUCENE-7241: Various changes towards making GeoComplexPolygon fully testable.

This commit is contained in:
Karl Wright 2016-05-01 09:35:00 -04:00
parent 7bc4859daf
commit ccc9057ea0
3 changed files with 46 additions and 13 deletions

View File

@ -1225,7 +1225,33 @@ class GeoComplexPolygon extends GeoBasePolygon {
@Override
public String toString() {
return "GeoComplexPolygon: {planetmodel=" + planetModel + ", number of shapes="+shapeStartEdges.length+", address="+ Integer.toHexString(hashCode())+"}";
final StringBuilder edgeDescription = new StringBuilder();
for (final Edge shapeStartEdge : shapeStartEdges) {
fillInEdgeDescription(edgeDescription, shapeStartEdge);
}
return "GeoComplexPolygon: {planetmodel=" + planetModel + ", number of shapes="+shapeStartEdges.length+", address="+ Integer.toHexString(hashCode())+", testPoint="+testPoint+", testPointInSet="+testPointInSet+", shapes={"+edgeDescription+"}}";
}
private static void fillInEdgeDescription(final StringBuilder description, final Edge startEdge) {
description.append(" {");
Edge currentEdge = startEdge;
int edgeCounter = 0;
while (true) {
if (edgeCounter > 0) {
description.append(", ");
}
if (edgeCounter >= 20) {
description.append("...");
break;
}
description.append(currentEdge.startPoint);
currentEdge = currentEdge.next;
if (currentEdge == startEdge) {
break;
}
edgeCounter++;
}
}
}

View File

@ -502,7 +502,11 @@ public class GeoPolygonFactory {
final GeoPoint closePoint = points.get(pointIndex);
// 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 maxArcDistance = points.get(0).arcDistance(points.get(1));
double maxArcDistance = points.get(0).arcDistance(points.get(1));
double trialArcDistance = points.get(0).arcDistance(points.get(2));
if (trialArcDistance > maxArcDistance) {
maxArcDistance = trialArcDistance;
}
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.
final double x = Math.cos(arcDistance);

View File

@ -925,8 +925,8 @@ public class TestGeo3DPoint extends LuceneTestCase {
angles[i] = angle;
accumulatedAngle += angle;
}
// Pick the arc distance randomly
arcDistance[i] = random().nextDouble() * (Math.PI - MINIMUM_ARC_ANGLE) + MINIMUM_ARC_ANGLE;
// Pick the arc distance randomly; not quite the full range though
arcDistance[i] = random().nextDouble() * (Math.PI * 0.5 - MINIMUM_ARC_ANGLE) + MINIMUM_ARC_ANGLE;
}
if (clockwiseDesired) {
// Reverse the signs
@ -938,6 +938,15 @@ public class TestGeo3DPoint extends LuceneTestCase {
// Now, use the pole's information plus angles and arcs to create GeoPoints in the right order.
final List<GeoPoint> polyPoints = convertToPoints(pm, pole, angles, arcDistance);
// Next, do some holes. No more than 2 of these. The poles for holes must always be within the polygon, so we're
// going to use Geo3D to help us select those given the points we just made.
final int holeCount = createHoles?TestUtil.nextInt(random(), 0, 2):0;
final List<Polygon> holeList = new ArrayList<>();
/* Hole logic is broken and needs rethinking
// Create the geo3d polygon, so we can test out our poles.
final GeoPolygon poly;
try {
@ -946,14 +955,7 @@ public class TestGeo3DPoint extends LuceneTestCase {
// This is what happens when three adjacent points are colinear, so try again.
continue;
}
// Next, do some holes. No more than 2 of these. The poles for holes must always be within the polygon, so we're
// going to use Geo3D to help us select those given the points we just made.
final int holeCount = createHoles?TestUtil.nextInt(random(), 0, 2):0;
final List<Polygon> holeList = new ArrayList<>();
for (int i = 0; i < holeCount; i++) {
// Choose a pole. The poly has to be within the polygon, but it also cannot be on the polygon edge.
// If we can't find a good pole we have to give it up and not do the hole.
@ -979,7 +981,8 @@ public class TestGeo3DPoint extends LuceneTestCase {
}
}
}
*/
final Polygon[] holes = holeList.toArray(new Polygon[0]);
// Finally, build the polygon and return it