Apache Lucene open-source search software
LUCENE-6196: Fix RandomizedShapeTestCase.randomPointIn(Shape)
David Wayne Smileyf06df3cc1dfd
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTestCase.javaindex ee4d1fc060b..e110e168d5e 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTestCase.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTestCase.java@@ -272,15 +272,17 @@ public abstract class RandomizedShapeTestCase extends RandomizedTest {return p;}- protected Point randomPointIn(Shape shape) {+ protected Point randomPointInOrNull(Shape shape) {if (!shape.hasArea())// or try the center?throw new UnsupportedOperationException("Need area to define shape!");Rectangle bbox = shape.getBoundingBox();- Point p;- do {- p = randomPointIn(bbox);- } while (!bbox.relate(p).intersects());- return p;+ for (int i = 0; i < 1000; i++) {+ Point p = randomPointIn(bbox);+ if (shape.relate(p).intersects()) {+ return p;+ }+ }+ return null;//tried too many times and failed}}diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.javaindex 5652e327f82..32a78da7d8f 100644--- a/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java@@ -72,13 +72,13 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends Random@SuppressWarnings("unchecked")@Override- protected Point randomPointIn(Shape shape) {+ protected Point randomPointInOrNull(Shape shape) {if (!shape.hasArea()) {final Point pt = randomPointInEmptyShape((S) shape);assert shape.relate(pt).intersects() : "faulty randomPointInEmptyShape";return pt;}- return super.randomPointIn(shape);+ return super.randomPointInOrNull(shape);}public void testRelateWithRectangle() {@@ -132,7 +132,10 @@ public abstract class RectIntersectionTestHelper<S extends Shape> extends Randomcase WITHIN:i_W++;for (int j = 0; j < MAX_TRIES; j++) {- Point p = randomPointIn(s);+ Point p = randomPointInOrNull(s);+ if (p == null) {//couldn't find a random point in shape+ break;+ }assertRelation(null, CONTAINS, r, p);}break;