You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2015/05/06 20:49:33 UTC

svn commit: r1678059 - in /lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j: RandomizedShapeTestCase.java RectIntersectionTestHelper.java

Author: dsmiley
Date: Wed May  6 18:49:32 2015
New Revision: 1678059

URL: http://svn.apache.org/r1678059
Log:
LUCENE-6196: Fix RandomizedShapeTestCase.randomPointIn(Shape)

Modified:
    lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTestCase.java
    lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java

Modified: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTestCase.java?rev=1678059&r1=1678058&r2=1678059&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTestCase.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTestCase.java Wed May  6 18:49:32 2015
@@ -272,15 +272,17 @@ public abstract class RandomizedShapeTes
     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
   }
 }
 

Modified: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java?rev=1678059&r1=1678058&r2=1678059&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RectIntersectionTestHelper.java Wed May  6 18:49:32 2015
@@ -72,13 +72,13 @@ public abstract class RectIntersectionTe
   
   @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 RectIntersectionTe
           case 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;