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/04 15:19:03 UTC

svn commit: r1677595 [8/9] - in /lucene/dev/branches/lucene6196/lucene/spatial/src: java/org/apache/lucene/spatial/spatial4j/geo3d/ test/org/apache/lucene/spatial/spatial4j/ test/org/apache/lucene/spatial/spatial4j/geo3d/

Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/SidedPlane.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/SidedPlane.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/SidedPlane.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/SidedPlane.java Mon May  4 13:19:02 2015
@@ -17,95 +17,107 @@ package org.apache.lucene.spatial.spatia
  * limitations under the License.
  */
 
-/** Combination of a plane, and a sign value indicating what evaluation values are on the correct
-* side of the plane.
-*/
-public class SidedPlane extends Plane implements Membership
-{
-    public final double sigNum;
-
-    /** Construct a SidedPlane identical to an existing one, but reversed.
-    *@param sidedPlane is the existing plane.
-    */
-    public SidedPlane(SidedPlane sidedPlane) {
-        super(sidedPlane,sidedPlane.D);
-        this.sigNum = -sidedPlane.sigNum;
-    }
-
-    /** Construct a sided plane from a pair of vectors describing points, and including
-     * origin, plus a point p which describes the side.
-     *@param p point to evaluate
-     *@param A is the first in-plane point
-     *@param B is the second in-plane point
-     */
-    public SidedPlane(Vector p, Vector A, Vector B) {
-        super(A,B);
-        sigNum = Math.signum(evaluate(p));
-    }
-
-    /** Construct a sided plane from a point and a Z coordinate.
-     *@param p point to evaluate.
-     *@param height is the Z coordinate of the plane.
-     */
-    public SidedPlane(Vector p, double height) {
-        super(height);
-        sigNum = Math.signum(evaluate(p));
-    }
-
-    /** Construct a sided vertical plane from a point and specified x and y coordinates.
-     *@param p point to evaluate.
-     *@param x is the specified x.
-     *@param y is the specified y.
-     */
-    public SidedPlane(Vector p, double x, double y) {
-        super(x,y);
-        sigNum = Math.signum(evaluate(p));
-    }
-
-    /** Construct a sided plane with a normal vector and offset.
-     *@param p point to evaluate.
-     *@param v is the normal vector.
-     *@param D is the origin offset for the plan.
-     */
-    public SidedPlane(Vector p, Vector v, double D) {
-        super(v,D);
-        sigNum = Math.signum(evaluate(p));
-    }
-
-    /** Check if a point is within this shape.
-     *@param point is the point to check.
-     *@return true if the point is within this shape
-     */
-    @Override
-    public boolean isWithin(Vector point)
-    {
-        double evalResult = evaluate(point);
-        if (Math.abs(evalResult) < MINIMUM_RESOLUTION)
-            return true;
-        double sigNum = Math.signum(evalResult);
-        return sigNum == this.sigNum;
-    }
-
-    /** Check if a point is within this shape.
-     *@param x is x coordinate of point to check.
-     *@param y is y coordinate of point to check.
-     *@param z is z coordinate of point to check.
-     *@return true if the point is within this shape
-     */
-    @Override
-    public boolean isWithin(double x, double y, double z)
-    {
-        double evalResult = evaluate(x,y,z);
-        if (Math.abs(evalResult) < MINIMUM_RESOLUTION)
-            return true;
-        double sigNum = Math.signum(evalResult);
-        return sigNum == this.sigNum;
-    }
-    
-
-    @Override
-    public String toString() {
-        return "[A="+x+", B="+y+", C="+z+", D="+D+", side="+sigNum+"]";
-    }
+/**
+ * Combination of a plane, and a sign value indicating what evaluation values are on the correct
+ * side of the plane.
+ */
+public class SidedPlane extends Plane implements Membership {
+  public final double sigNum;
+
+  /**
+   * Construct a SidedPlane identical to an existing one, but reversed.
+   *
+   * @param sidedPlane is the existing plane.
+   */
+  public SidedPlane(SidedPlane sidedPlane) {
+    super(sidedPlane, sidedPlane.D);
+    this.sigNum = -sidedPlane.sigNum;
+  }
+
+  /**
+   * Construct a sided plane from a pair of vectors describing points, and including
+   * origin, plus a point p which describes the side.
+   *
+   * @param p point to evaluate
+   * @param A is the first in-plane point
+   * @param B is the second in-plane point
+   */
+  public SidedPlane(Vector p, Vector A, Vector B) {
+    super(A, B);
+    sigNum = Math.signum(evaluate(p));
+  }
+
+  /**
+   * Construct a sided plane from a point and a Z coordinate.
+   *
+   * @param p      point to evaluate.
+   * @param height is the Z coordinate of the plane.
+   */
+  public SidedPlane(Vector p, double height) {
+    super(height);
+    sigNum = Math.signum(evaluate(p));
+  }
+
+  /**
+   * Construct a sided vertical plane from a point and specified x and y coordinates.
+   *
+   * @param p point to evaluate.
+   * @param x is the specified x.
+   * @param y is the specified y.
+   */
+  public SidedPlane(Vector p, double x, double y) {
+    super(x, y);
+    sigNum = Math.signum(evaluate(p));
+  }
+
+  /**
+   * Construct a sided plane with a normal vector and offset.
+   *
+   * @param p point to evaluate.
+   * @param v is the normal vector.
+   * @param D is the origin offset for the plan.
+   */
+  public SidedPlane(Vector p, Vector v, double D) {
+    super(v, D);
+    sigNum = Math.signum(evaluate(p));
+  }
+
+  /**
+   * Check if a point is within this shape.
+   *
+   * @param point is the point to check.
+   * @return true if the point is within this shape
+   */
+  @Override
+  public boolean isWithin(Vector point) {
+    double evalResult = evaluate(point);
+    if (Math.abs(evalResult) < MINIMUM_RESOLUTION)
+      return true;
+    double sigNum = Math.signum(evalResult);
+    return sigNum == this.sigNum;
+  }
+
+  /**
+   * Check if a point is within this shape.
+   *
+   * @param x is x coordinate of point to check.
+   * @param y is y coordinate of point to check.
+   * @param z is z coordinate of point to check.
+   * @return true if the point is within this shape
+   */
+  @Override
+  public boolean isWithin(double x, double y, double z) {
+    double evalResult = evaluate(x, y, z);
+    if (Math.abs(evalResult) < MINIMUM_RESOLUTION)
+      return true;
+    double sigNum = Math.signum(evalResult);
+    return sigNum == this.sigNum;
+  }
+
+
+  @Override
+  public String toString() {
+    return "[A=" + x + ", B=" + y + ", C=" + z + ", D=" + D + ", side=" + sigNum + "]";
+  }
 }
   

Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Tools.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Tools.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Tools.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Tools.java Mon May  4 13:19:02 2015
@@ -17,24 +17,24 @@ package org.apache.lucene.spatial.spatia
  * limitations under the License.
  */
 
-/** Static methods globally useful for 3d geometric work.
+/**
+ * Static methods globally useful for 3d geometric work.
  */
-public class Tools
-{
-    private Tools()
-    {
-    }
-  
-    /** Java acos yields a NAN if you take an arc-cos of an
-     * angle that's just a tiny bit greater than 1.0, so
-     * here's a more resilient version.
-     */
-    public static double safeAcos(double value) {
-        if (value > 1.0)
-            value = 1.0;
-        else if (value < -1.0)
-            value = -1.0;
-        return Math.acos(value);
-    }
+public class Tools {
+  private Tools() {
+  }
+
+  /**
+   * Java acos yields a NAN if you take an arc-cos of an
+   * angle that's just a tiny bit greater than 1.0, so
+   * here's a more resilient version.
+   */
+  public static double safeAcos(double value) {
+    if (value > 1.0)
+      value = 1.0;
+    else if (value < -1.0)
+      value = -1.0;
+    return Math.acos(value);
+  }
 
 }
\ No newline at end of file

Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java Mon May  4 13:19:02 2015
@@ -17,270 +17,309 @@ package org.apache.lucene.spatial.spatia
  * limitations under the License.
  */
 
-/** A 3d vector in space, not necessarily
- * going through the origin. */
-public class Vector
-{
-    /** Values that are all considered to be essentially zero have a magnitude
-    * less than this. */
-    public static final double MINIMUM_RESOLUTION = 1e-12;
-    /** For squared quantities, the bound is squared too.
-    */
-    public static final double MINIMUM_RESOLUTION_SQUARED = MINIMUM_RESOLUTION * MINIMUM_RESOLUTION;
-    
-    public final double x;
-    public final double y;
-    public final double z;
-
-    /** Construct from (U.S.) x,y,z coordinates.
-     */
-    public Vector(double x, double y, double z)
-    {
-        this.x = x;
-        this.y = y;
-        this.z = z;
-    }
-    
-    /** Construct a vector that is perpendicular to
-     * two other (non-zero) vectors.  If the vectors are parallel,
-     * the result vector will have magnitude 0.
-     *@param A is the first vector
-     *@param B is the second
-     */
-    public Vector(final Vector A, final Vector B) {
-        // x = u2v3 - u3v2
-        // y = u3v1 - u1v3
-        // z = u1v2 - u2v1
-
-        this(A.y * B.z - A.z * B.y,
-             A.z * B.x - A.x * B.z,
-             A.x * B.y - A.y * B.x);
-    }
-
-    /** Compute a normalized unit vector based on the current vector.
-     *@return the normalized vector, or null if the current vector has
-     * a magnitude of zero.
-     */
-    public Vector normalize() {
-        double denom = magnitude();
-        if (denom < MINIMUM_RESOLUTION)
-            // Degenerate, can't normalize
-            return null;
-        double normFactor = 1.0/denom;
-        return new Vector(x*normFactor,y*normFactor,z*normFactor);
-    }
-    
-    /** Do a dot product.
-     *@param v is the vector to multiply.
-     *@return the result.
-     */
-    public double dotProduct(final Vector v) {
-        return this.x * v.x + this.y * v.y + this.z * v.z;
-    }
-
-    /** Do a dot product.
-     *@param x is the x value of the vector to multiply.
-     *@param y is the y value of the vector to multiply.
-     *@param z is the z value of the vector to multiply.
-     *@return the result.
-     */
-    public double dotProduct(final double x, final double y, final double z) {
-        return this.x * x + this.y * y + this.z * z;
-    }
-    
-    /** Determine if this vector, taken from the origin,
-     * describes a point within a set of planes.
-     *@param bounds is the first part of the set of planes.
-     *@param moreBounds is the second part of the set of planes.
-     *@return true if the point is within the bounds.
-     */
-    public boolean isWithin(final Membership[] bounds, final Membership[] moreBounds) {
-        // Return true if the point described is within all provided bounds
-        for (Membership bound : bounds) {
-            if (bound != null && !bound.isWithin(this))
-                return false;
-        }
-        for (Membership bound : moreBounds) {
-            if (bound != null && !bound.isWithin(this))
-                return false;
-        }
-        return true;
-    }
-
-    /** Translate vector.
-    */
-    public Vector translate(final double xOffset, final double yOffset, final double zOffset) {
-        return new Vector(x - xOffset, y - yOffset, z - zOffset);
-    }
-    
-    /** Rotate vector counter-clockwise in x-y by an angle.
-    */
-    public Vector rotateXY(final double angle) {
-        return rotateXY(Math.sin(angle),Math.cos(angle));
-    }
-    
-    /** Rotate vector counter-clockwise in x-y by an angle, expressed as sin and cos.
-    */
-    public Vector rotateXY(final double sinAngle, final double cosAngle) {
-        return new Vector(x * cosAngle - y * sinAngle, x * sinAngle + y * cosAngle, z);
-    }
-
-    /** Rotate vector counter-clockwise in x-z by an angle.
-    */
-    public Vector rotateXZ(final double angle) {
-        return rotateXZ(Math.sin(angle),Math.cos(angle));
-    }
-    
-    /** Rotate vector counter-clockwise in x-z by an angle, expressed as sin and cos.
-    */
-    public Vector rotateXZ(final double sinAngle, final double cosAngle) {
-        return new Vector(x * cosAngle - z * sinAngle, y, x * sinAngle + z * cosAngle);
-    }
-
-    /** Rotate vector counter-clockwise in z-y by an angle.
-    */
-    public Vector rotateZY(final double angle) {
-        return rotateZY(Math.sin(angle),Math.cos(angle));
-    }
-    
-    /** Rotate vector counter-clockwise in z-y by an angle, expressed as sin and cos.
-    */
-    public Vector rotateZY(final double sinAngle, final double cosAngle) {
-        return new Vector(x, z * sinAngle + y * cosAngle, z * cosAngle - y * sinAngle);
-    }
-
-    /** Compute the square of a straight-line distance to a point described by the
-     * vector taken from the origin.
-     * Monotonically increasing for arc distances up to PI.
-     *@param v is the vector to compute a distance to.
-     *@return the square of the linear distance.
-     */
-    public double linearDistanceSquared(final Vector v) {
-        double deltaX = this.x - v.x;
-        double deltaY = this.y - v.y;
-        double deltaZ = this.z - v.z;
-        return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
-    }
-  
-    /** Compute the square of a straight-line distance to a point described by the
-     * vector taken from the origin.
-     * Monotonically increasing for arc distances up to PI.
-     *@param x is the x part of the vector to compute a distance to.
-     *@param y is the y part of the vector to compute a distance to.
-     *@param z is the z part of the vector to compute a distance to.
-     *@return the square of the linear distance.
-     */
-    public double linearDistanceSquared(final double x, final double y, final double z) {
-        double deltaX = this.x - x;
-        double deltaY = this.y - y;
-        double deltaZ = this.z - z;
-        return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
-    }
-
-    /** Compute the straight-line distance to a point described by the
-     * vector taken from the origin.
-     * Monotonically increasing for arc distances up to PI.
-     *@param v is the vector to compute a distance to.
-     *@return the linear distance.
-     */
-    public double linearDistance(final Vector v) {
-        return Math.sqrt(linearDistanceSquared(v));
-    }
-    
-    /** Compute the straight-line distance to a point described by the
-     * vector taken from the origin.
-     * Monotonically increasing for arc distances up to PI.
-     *@param x is the x part of the vector to compute a distance to.
-     *@param y is the y part of the vector to compute a distance to.
-     *@param z is the z part of the vector to compute a distance to.
-     *@return the linear distance.
-     */
-    public double linearDistance(final double x, final double y, final double z) {
-        return Math.sqrt(linearDistanceSquared(x,y,z));
-    }
-    
-    /** Compute the square of the normal distance to a vector described by a
-     * vector taken from the origin.
-     * Monotonically increasing for arc distances up to PI/2.
-     *@param v is the vector to compute a distance to.
-     *@return the square of the normal distance.
-     */
-    public double normalDistanceSquared(final Vector v) {
-        double t = dotProduct(v);
-        double deltaX = this.x * t - v.x;
-        double deltaY = this.y * t - v.y;
-        double deltaZ = this.z * t - v.z;
-        return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
-    }
-
-    /** Compute the square of the normal distance to a vector described by a
-     * vector taken from the origin.
-     * Monotonically increasing for arc distances up to PI/2.
-     *@param x is the x part of the vector to compute a distance to.
-     *@param y is the y part of the vector to compute a distance to.
-     *@param z is the z part of the vector to compute a distance to.
-     *@return the square of the normal distance.
-     */
-    public double normalDistanceSquared(final double x, final double y, final double z) {
-        double t = dotProduct(x,y,z);
-        double deltaX = this.x * t - x;
-        double deltaY = this.y * t - y;
-        double deltaZ = this.z * t - z;
-        return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
-    }
-    
-    /** Compute the normal (perpendicular) distance to a vector described by a
-     * vector taken from the origin.
-     * Monotonically increasing for arc distances up to PI/2.
-     *@param v is the vector to compute a distance to.
-     *@return the normal distance.
-     */
-    public double normalDistance(final Vector v) {
-        return Math.sqrt(normalDistanceSquared(v));
-    }
-
-    /** Compute the normal (perpendicular) distance to a vector described by a
-     * vector taken from the origin.
-     * Monotonically increasing for arc distances up to PI/2.
-     *@param x is the x part of the vector to compute a distance to.
-     *@param y is the y part of the vector to compute a distance to.
-     *@param z is the z part of the vector to compute a distance to.
-     *@return the normal distance.
-     */
-    public double normalDistance(final double x, final double y, final double z) {
-        return Math.sqrt(normalDistanceSquared(x,y,z));
-    }
-    
-    /** Compute the magnitude of this vector.
-     *@return the magnitude.
-     */
-    public double magnitude() {
-        return Math.sqrt(x * x + y * y + z * z);
-    }
-    
-    @Override
-    public boolean equals(Object o) {
-        if (!(o instanceof Vector))
-            return false;
-        Vector other = (Vector)o;
-        return (other.x == x && other.y == y && other.z == z);
-    }
-
-    @Override
-    public int hashCode() {
-        int result;
-        long temp;
-        temp = Double.doubleToLongBits(x);
-        result = (int) (temp ^ (temp >>> 32));
-        temp = Double.doubleToLongBits(y);
-        result = 31 * result + (int) (temp ^ (temp >>> 32));
-        temp = Double.doubleToLongBits(z);
-        result = 31 * result + (int) (temp ^ (temp >>> 32));
-        return result;
-    }
-
-    @Override
-    public String toString() {
-        return "[X="+x+", Y="+y+", Z="+z+"]";
-    }
+/**
+ * A 3d vector in space, not necessarily
+ * going through the origin.
+ */
+public class Vector {
+  /**
+   * Values that are all considered to be essentially zero have a magnitude
+   * less than this.
+   */
+  public static final double MINIMUM_RESOLUTION = 1e-12;
+  /**
+   * For squared quantities, the bound is squared too.
+   */
+  public static final double MINIMUM_RESOLUTION_SQUARED = MINIMUM_RESOLUTION * MINIMUM_RESOLUTION;
+
+  public final double x;
+  public final double y;
+  public final double z;
+
+  /**
+   * Construct from (U.S.) x,y,z coordinates.
+   */
+  public Vector(double x, double y, double z) {
+    this.x = x;
+    this.y = y;
+    this.z = z;
+  }
+
+  /**
+   * Construct a vector that is perpendicular to
+   * two other (non-zero) vectors.  If the vectors are parallel,
+   * the result vector will have magnitude 0.
+   *
+   * @param A is the first vector
+   * @param B is the second
+   */
+  public Vector(final Vector A, final Vector B) {
+    // x = u2v3 - u3v2
+    // y = u3v1 - u1v3
+    // z = u1v2 - u2v1
+
+    this(A.y * B.z - A.z * B.y,
+        A.z * B.x - A.x * B.z,
+        A.x * B.y - A.y * B.x);
+  }
+
+  /**
+   * Compute a normalized unit vector based on the current vector.
+   *
+   * @return the normalized vector, or null if the current vector has
+   * a magnitude of zero.
+   */
+  public Vector normalize() {
+    double denom = magnitude();
+    if (denom < MINIMUM_RESOLUTION)
+      // Degenerate, can't normalize
+      return null;
+    double normFactor = 1.0 / denom;
+    return new Vector(x * normFactor, y * normFactor, z * normFactor);
+  }
+
+  /**
+   * Do a dot product.
+   *
+   * @param v is the vector to multiply.
+   * @return the result.
+   */
+  public double dotProduct(final Vector v) {
+    return this.x * v.x + this.y * v.y + this.z * v.z;
+  }
+
+  /**
+   * Do a dot product.
+   *
+   * @param x is the x value of the vector to multiply.
+   * @param y is the y value of the vector to multiply.
+   * @param z is the z value of the vector to multiply.
+   * @return the result.
+   */
+  public double dotProduct(final double x, final double y, final double z) {
+    return this.x * x + this.y * y + this.z * z;
+  }
+
+  /**
+   * Determine if this vector, taken from the origin,
+   * describes a point within a set of planes.
+   *
+   * @param bounds     is the first part of the set of planes.
+   * @param moreBounds is the second part of the set of planes.
+   * @return true if the point is within the bounds.
+   */
+  public boolean isWithin(final Membership[] bounds, final Membership[] moreBounds) {
+    // Return true if the point described is within all provided bounds
+    for (Membership bound : bounds) {
+      if (bound != null && !bound.isWithin(this))
+        return false;
+    }
+    for (Membership bound : moreBounds) {
+      if (bound != null && !bound.isWithin(this))
+        return false;
+    }
+    return true;
+  }
+
+  /**
+   * Translate vector.
+   */
+  public Vector translate(final double xOffset, final double yOffset, final double zOffset) {
+    return new Vector(x - xOffset, y - yOffset, z - zOffset);
+  }
+
+  /**
+   * Rotate vector counter-clockwise in x-y by an angle.
+   */
+  public Vector rotateXY(final double angle) {
+    return rotateXY(Math.sin(angle), Math.cos(angle));
+  }
+
+  /**
+   * Rotate vector counter-clockwise in x-y by an angle, expressed as sin and cos.
+   */
+  public Vector rotateXY(final double sinAngle, final double cosAngle) {
+    return new Vector(x * cosAngle - y * sinAngle, x * sinAngle + y * cosAngle, z);
+  }
+
+  /**
+   * Rotate vector counter-clockwise in x-z by an angle.
+   */
+  public Vector rotateXZ(final double angle) {
+    return rotateXZ(Math.sin(angle), Math.cos(angle));
+  }
+
+  /**
+   * Rotate vector counter-clockwise in x-z by an angle, expressed as sin and cos.
+   */
+  public Vector rotateXZ(final double sinAngle, final double cosAngle) {
+    return new Vector(x * cosAngle - z * sinAngle, y, x * sinAngle + z * cosAngle);
+  }
+
+  /**
+   * Rotate vector counter-clockwise in z-y by an angle.
+   */
+  public Vector rotateZY(final double angle) {
+    return rotateZY(Math.sin(angle), Math.cos(angle));
+  }
+
+  /**
+   * Rotate vector counter-clockwise in z-y by an angle, expressed as sin and cos.
+   */
+  public Vector rotateZY(final double sinAngle, final double cosAngle) {
+    return new Vector(x, z * sinAngle + y * cosAngle, z * cosAngle - y * sinAngle);
+  }
+
+  /**
+   * Compute the square of a straight-line distance to a point described by the
+   * vector taken from the origin.
+   * Monotonically increasing for arc distances up to PI.
+   *
+   * @param v is the vector to compute a distance to.
+   * @return the square of the linear distance.
+   */
+  public double linearDistanceSquared(final Vector v) {
+    double deltaX = this.x - v.x;
+    double deltaY = this.y - v.y;
+    double deltaZ = this.z - v.z;
+    return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
+  }
+
+  /**
+   * Compute the square of a straight-line distance to a point described by the
+   * vector taken from the origin.
+   * Monotonically increasing for arc distances up to PI.
+   *
+   * @param x is the x part of the vector to compute a distance to.
+   * @param y is the y part of the vector to compute a distance to.
+   * @param z is the z part of the vector to compute a distance to.
+   * @return the square of the linear distance.
+   */
+  public double linearDistanceSquared(final double x, final double y, final double z) {
+    double deltaX = this.x - x;
+    double deltaY = this.y - y;
+    double deltaZ = this.z - z;
+    return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
+  }
+
+  /**
+   * Compute the straight-line distance to a point described by the
+   * vector taken from the origin.
+   * Monotonically increasing for arc distances up to PI.
+   *
+   * @param v is the vector to compute a distance to.
+   * @return the linear distance.
+   */
+  public double linearDistance(final Vector v) {
+    return Math.sqrt(linearDistanceSquared(v));
+  }
+
+  /**
+   * Compute the straight-line distance to a point described by the
+   * vector taken from the origin.
+   * Monotonically increasing for arc distances up to PI.
+   *
+   * @param x is the x part of the vector to compute a distance to.
+   * @param y is the y part of the vector to compute a distance to.
+   * @param z is the z part of the vector to compute a distance to.
+   * @return the linear distance.
+   */
+  public double linearDistance(final double x, final double y, final double z) {
+    return Math.sqrt(linearDistanceSquared(x, y, z));
+  }
+
+  /**
+   * Compute the square of the normal distance to a vector described by a
+   * vector taken from the origin.
+   * Monotonically increasing for arc distances up to PI/2.
+   *
+   * @param v is the vector to compute a distance to.
+   * @return the square of the normal distance.
+   */
+  public double normalDistanceSquared(final Vector v) {
+    double t = dotProduct(v);
+    double deltaX = this.x * t - v.x;
+    double deltaY = this.y * t - v.y;
+    double deltaZ = this.z * t - v.z;
+    return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
+  }
+
+  /**
+   * Compute the square of the normal distance to a vector described by a
+   * vector taken from the origin.
+   * Monotonically increasing for arc distances up to PI/2.
+   *
+   * @param x is the x part of the vector to compute a distance to.
+   * @param y is the y part of the vector to compute a distance to.
+   * @param z is the z part of the vector to compute a distance to.
+   * @return the square of the normal distance.
+   */
+  public double normalDistanceSquared(final double x, final double y, final double z) {
+    double t = dotProduct(x, y, z);
+    double deltaX = this.x * t - x;
+    double deltaY = this.y * t - y;
+    double deltaZ = this.z * t - z;
+    return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
+  }
+
+  /**
+   * Compute the normal (perpendicular) distance to a vector described by a
+   * vector taken from the origin.
+   * Monotonically increasing for arc distances up to PI/2.
+   *
+   * @param v is the vector to compute a distance to.
+   * @return the normal distance.
+   */
+  public double normalDistance(final Vector v) {
+    return Math.sqrt(normalDistanceSquared(v));
+  }
+
+  /**
+   * Compute the normal (perpendicular) distance to a vector described by a
+   * vector taken from the origin.
+   * Monotonically increasing for arc distances up to PI/2.
+   *
+   * @param x is the x part of the vector to compute a distance to.
+   * @param y is the y part of the vector to compute a distance to.
+   * @param z is the z part of the vector to compute a distance to.
+   * @return the normal distance.
+   */
+  public double normalDistance(final double x, final double y, final double z) {
+    return Math.sqrt(normalDistanceSquared(x, y, z));
+  }
+
+  /**
+   * Compute the magnitude of this vector.
+   *
+   * @return the magnitude.
+   */
+  public double magnitude() {
+    return Math.sqrt(x * x + y * y + z * z);
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (!(o instanceof Vector))
+      return false;
+    Vector other = (Vector) o;
+    return (other.x == x && other.y == y && other.z == z);
+  }
+
+  @Override
+  public int hashCode() {
+    int result;
+    long temp;
+    temp = Double.doubleToLongBits(x);
+    result = (int) (temp ^ (temp >>> 32));
+    temp = Double.doubleToLongBits(y);
+    result = 31 * result + (int) (temp ^ (temp >>> 32));
+    temp = Double.doubleToLongBits(z);
+    result = 31 * result + (int) (temp ^ (temp >>> 32));
+    return result;
+  }
+
+  @Override
+  public String toString() {
+    return "[X=" + x + ", Y=" + y + ", Z=" + z + "]";
+  }
 }

Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/package-info.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/package-info.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/package-info.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/package-info.java Mon May  4 13:19:02 2015
@@ -1,2 +1,4 @@
-/** Shapes implemented using 3D planar geometry. */
+/**
+ * Shapes implemented using 3D planar geometry.
+ */
 package org.apache.lucene.spatial.spatial4j.geo3d;
\ No newline at end of file

Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dRptTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dRptTest.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dRptTest.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dRptTest.java Mon May  4 13:19:02 2015
@@ -78,24 +78,8 @@ public class Geo3dRptTest extends Random
   }
 
   @Test
-  public void testFailure() throws IOException {
+  public void testFailure1() throws IOException {
     setupStrategy();
-    // [junit4]    > Throwable #1: java.lang.AssertionError: [Intersects] qIdx:25 Shouldn't match I#1:Rect(minX=-49.0,maxX=-45.0,minY=73.0,maxY=86.0) 
-    // Q:Geo3dShape{GeoCompositeMembershipShape: {[GeoCompositeMembershipShape: {[GeoConvexPolygon: {[
-    // [X=-0.8606462131055999, Y=0.4385211485883089, Z=-0.25881904510252074], 
-    //  [X=-0.4668467715008339, Y=0.28050984011500923, Z=-0.838670567945424],
-    // [X=-0.9702957262759965, Y=1.1882695554102554E-16, Z=0.24192189559966773]]}]}, 
-    // GeoConvexPolygon: {[[X=0.8473975608908426, Y=-0.43177062311338915, Z=0.3090169943749474],
-    //[X=-0.4668467715008339, Y=0.28050984011500923, Z=-0.838670567945424], 
-    // [X=-0.8606462131055999, Y=0.4385211485883089, Z=-0.25881904510252074]]}]}}
-    //
-    // Points in order (I think):
-    // 
-    // [X=0.8473975608908426, Y=-0.43177062311338915, Z=0.3090169943749474],
-    //[X=-0.4668467715008339, Y=0.28050984011500923, Z=-0.838670567945424], 
-    // [X=-0.9702957262759965, Y=1.1882695554102554E-16, Z=0.24192189559966773],
-    // [X=-0.8606462131055999, Y=0.4385211485883089, Z=-0.25881904510252074], 
-    // Index: 0
     final List<GeoPoint> points = new ArrayList<GeoPoint>();
     points.add(new GeoPoint(18 * DEGREES_TO_RADIANS, -27 * DEGREES_TO_RADIANS));
     points.add(new GeoPoint(-57 * DEGREES_TO_RADIANS, 146 * DEGREES_TO_RADIANS));
@@ -108,8 +92,7 @@ public class Geo3dRptTest extends Random
   }
 
   @Test
-  @Repeat(iterations = 2000)
-  //@Seed("B808B88D6F8E285C")
+  @Repeat(iterations = 10)
   public void testOperations() throws IOException {
     setupStrategy();
 

Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java Mon May  4 13:19:02 2015
@@ -54,26 +54,7 @@ public class Geo3dShapeRectRelationTest
   protected final static double RADIANS_PER_DEGREE = Math.PI/180.0;
   
   @Test
-  public void testFailure() {
-      /*
-   [junit4]   1> S-R Rel: {}, Shape {}, Rectangle {} [WITHIN, Geo3dShape{GeoCompositeMembershipShape: {[
-    GeoConvexPolygon: {points=[
-      [X=0.35168818443386646, Y=-0.19637966197066342, Z=0.9152870857244183],
-      [X=0.5003343189532654, Y=0.522128543226148, Z=0.6906861469771293], 
-      [X=0.8344549994139991, Y=0.216175219373972, Z=0.5069054433339593]] 
-    edges={
-      [A=-0.6135342247741855, B=0.21504338363863665, C=0.28188192383666794, D=0.0, side=-1.0] internal? false;
-      [A=0.11536057134002048, B=0.32272431860685813, C=-0.3275328920717585, D=0.0, side=-1.0] internal? false;
-      [A=0.29740830615965186, B=-0.5854932295360462, C=-0.2398962611358763, D=0.0, side=-1.0] internal? false; }}]}}, 
-    Rect(minX=-30.0,maxX=62.0,minY=30.0,maxY=88.0)](no slf4j subst; sorry)
-   [junit4] FAILURE 1.85s J2 | Geo3dShapeRectRelationTest.testGeoPolygonRect <<<
-   [junit4]    > Throwable #1: java.lang.AssertionError: Rect(minX=-30.0,maxX=62.0,minY=30.0,maxY=88.0) intersect Pt(x=82.75500168892472,y=34.2730264413182)
-   [junit4]    > 	at __randomizedtesting.SeedInfo.seed([3EBD2127AF6641F7:3A64BDAC8843B64]:0)
-   [junit4]    > 	at org.apache.lucene.spatial.spatial4j.RandomizedShapeTest._assertIntersect(RandomizedShapeTest.java:167)
-   [junit4]    > 	at org.apache.lucene.spatial.spatial4j.RandomizedShapeTest.assertRelation(RandomizedShapeTest.java:152)
-   [junit4]    > 	at org.apache.lucene.spatial.spatial4j.RectIntersectionTestHelper.testRelateWithRectangle(RectIntersectionTestHelper.java:105)
-   [junit4]    > 	at org.apache.lucene.spatial.spatial4j.Geo3dShapeRectRelationTest.testGeoPolygonRect(Geo3dShapeRectRelationTest.java:219)
-    */
+  public void testFailure1() {
       final GeoBBox rect = GeoBBoxFactory.makeGeoBBox(88 * RADIANS_PER_DEGREE, 30 * RADIANS_PER_DEGREE, -30 * RADIANS_PER_DEGREE, 62 * RADIANS_PER_DEGREE);
       final List<GeoPoint> points = new ArrayList<GeoPoint>();
       points.add(new GeoPoint(66.2465299717 * RADIANS_PER_DEGREE, -29.1786158537 * RADIANS_PER_DEGREE));
@@ -82,20 +63,7 @@ public class Geo3dShapeRectRelationTest
       final GeoShape path = GeoPolygonFactory.makeGeoPolygon(points,0);
     
       final GeoPoint point = new GeoPoint(34.2730264413182 * RADIANS_PER_DEGREE, 82.75500168892472 * RADIANS_PER_DEGREE);
-      
-      System.err.println("Rectangle = "+rect+"; path = "+path+"; point = "+point);
 
-      /*
-         [junit4]   2> Rectangle = GeoRectangle: {toplat=1.53588974175501(87.99999999999999), bottomlat=0.5235987755982988(29.999999999999996), leftlon=-0.5235987755982988(-29.999999999999996), rightlon=1.0821041362364843(62.0)};
-         path = GeoCompositeMembershipShape: {[GeoConvexPolygon: {points=[
-         [X=0.3516881844340107, Y=-0.1963796619709742, Z=0.9152870857242963], 
-         [X=0.500334318953081, Y=0.5221285432268337, Z=0.6906861469767445], 
-         [X=0.8344549994140144, Y=0.21617521937373424, Z=0.5069054433340355]] 
-         edges={[A=-0.6135342247748885, B=0.21504338363844255, C=0.28188192383710364, D=0.0, side=-1.0] internal? false;
-         [A=0.1153605713406553, B=0.32272431860660283, C=-0.3275328920724975, D=0.0, side=-1.0] internal? false;
-         [A=0.29740830615958036, B=-0.5854932295358584, C=-0.2398962611360862, D=0.0, side=-1.0] internal? false; }}]};
-         point = [X=0.10421465978661167, Y=0.8197657811637465, Z=0.5631370780889439]
-        */
       // Apparently the rectangle thinks the polygon is completely within it... "shape inside rectangle"
       assertTrue(GeoArea.WITHIN == rect.getRelationship(path));
 
@@ -135,7 +103,6 @@ public class Geo3dShapeRectRelationTest
   }
 
   @Test
-  //@Seed("FAD1BAB12B6DCCFE")
   public void testGeoCircleRect() {
     new RectIntersectionTestHelper<Geo3dShape>(ctx) {
 

Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTest.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTest.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTest.java Mon May  4 13:19:02 2015
@@ -54,8 +54,9 @@ public abstract class RandomizedShapeTes
     this.ctx = ctx;
   }
 
-  public static void checkShapesImplementEquals( Class[] classes ) {
-    for( Class clazz : classes ) {
+  @SuppressWarnings("unchecked")
+  public static void checkShapesImplementEquals( Class<?>[] classes ) {
+    for( Class<?> clazz : classes ) {
       try {
         clazz.getDeclaredMethod( "equals", Object.class );
       } catch (Exception e) {

Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxTest.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxTest.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxTest.java Mon May  4 13:19:02 2015
@@ -28,241 +28,242 @@ import static org.junit.Assert.assertTru
 
 public class GeoBBoxTest {
 
-    protected final double DEGREES_TO_RADIANS = Math.PI/180.0;
-    @Test
-    public void testBBoxDegenerate() {
-        GeoBBox box;
-        GeoConvexPolygon cp;
-        int relationship;
-        List<GeoPoint> points = new ArrayList<GeoPoint>();
-        points.add(new GeoPoint(24*DEGREES_TO_RADIANS,-30*DEGREES_TO_RADIANS));
-        points.add(new GeoPoint(-11*DEGREES_TO_RADIANS,101*DEGREES_TO_RADIANS));
-        points.add(new GeoPoint(-49*DEGREES_TO_RADIANS,-176*DEGREES_TO_RADIANS));
-        GeoMembershipShape shape = GeoPolygonFactory.makeGeoPolygon(points,0);
-        box = GeoBBoxFactory.makeGeoBBox(-64*DEGREES_TO_RADIANS,-64*DEGREES_TO_RADIANS,-180*DEGREES_TO_RADIANS,180*DEGREES_TO_RADIANS);
-        relationship = box.getRelationship(shape);
-        assertEquals(GeoArea.CONTAINS,relationship);
-        box = GeoBBoxFactory.makeGeoBBox(-61.85*DEGREES_TO_RADIANS,-67.5*DEGREES_TO_RADIANS,-180*DEGREES_TO_RADIANS,-168.75*DEGREES_TO_RADIANS);
-        System.out.println("Shape = "+shape+" Rect = "+box);
-        relationship = box.getRelationship(shape);
-        assertEquals(GeoArea.CONTAINS,relationship);
-    }
-    
-    @Test
-    public void testBBoxPointWithin() {
-        GeoBBox box;
-        GeoPoint gp;
-        // Standard normal Rect box, not crossing dateline
-        box = GeoBBoxFactory.makeGeoBBox(0.0,-Math.PI * 0.25, -1.0, 1.0);
-        gp = new GeoPoint(-0.1,0.0);
-        assertTrue(box.isWithin(gp));
-        gp = new GeoPoint(0.1,0.0);
-        assertFalse(box.isWithin(gp));
-        gp = new GeoPoint(-Math.PI * 0.5,0.0);
-        assertFalse(box.isWithin(gp));
-        gp = new GeoPoint(-0.1,1.1);
-        assertFalse(box.isWithin(gp));
-        gp = new GeoPoint(-0.1,-1.1);
-        assertFalse(box.isWithin(gp));
-        // Standard normal Rect box, crossing dateline
-        box = GeoBBoxFactory.makeGeoBBox(0.0,-Math.PI * 0.25, Math.PI-1.0, -Math.PI+1.0);
-        gp = new GeoPoint(-0.1,-Math.PI);
-        assertTrue(box.isWithin(gp));
-        gp = new GeoPoint(0.1,-Math.PI);
-        assertFalse(box.isWithin(gp));
-        gp = new GeoPoint(-Math.PI * 0.5,-Math.PI);
-        assertFalse(box.isWithin(gp));
-        gp = new GeoPoint(-0.1,-Math.PI+1.1);
-        assertFalse(box.isWithin(gp));
-        gp = new GeoPoint(-0.1,-Math.PI-1.1);
-        assertFalse(box.isWithin(gp));
-        // Latitude zone rectangle
-        box = GeoBBoxFactory.makeGeoBBox(0.0,-Math.PI * 0.25, -Math.PI, Math.PI);
-        gp = new GeoPoint(-0.1,-Math.PI);
-        assertTrue(box.isWithin(gp));
-        gp = new GeoPoint(0.1,-Math.PI);
-        assertFalse(box.isWithin(gp));
-        gp = new GeoPoint(-Math.PI * 0.5,-Math.PI);
-        assertFalse(box.isWithin(gp));
-        gp = new GeoPoint(-0.1,-Math.PI+1.1);
-        assertTrue(box.isWithin(gp));
-        gp = new GeoPoint(-0.1,-Math.PI-1.1);
-        assertTrue(box.isWithin(gp));
-        // World
-        box = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5,-Math.PI * 0.5, -Math.PI, Math.PI);
-        gp = new GeoPoint(-0.1,-Math.PI);
-        assertTrue(box.isWithin(gp));
-        gp = new GeoPoint(0.1,-Math.PI);
-        assertTrue(box.isWithin(gp));
-        gp = new GeoPoint(-Math.PI * 0.5,-Math.PI);
-        assertTrue(box.isWithin(gp));
-        gp = new GeoPoint(-0.1,-Math.PI+1.1);
-        assertTrue(box.isWithin(gp));
-        gp = new GeoPoint(-0.1,-Math.PI-1.1);
-        assertTrue(box.isWithin(gp));
-
-    }
-
-    @Test
-    public void testBBoxExpand() {
-        GeoBBox box;
-        GeoPoint gp;
-        // Standard normal Rect box, not crossing dateline
-        box = GeoBBoxFactory.makeGeoBBox(0.0,-Math.PI * 0.25, -1.0, 1.0);
-        box = box.expand(0.1);
-        gp = new GeoPoint(0.05,0.0);
-        assertTrue(box.isWithin(gp));
-        gp = new GeoPoint(0.15,0.0);
-        assertFalse(box.isWithin(gp));
-        gp = new GeoPoint(-Math.PI * 0.25 - 0.05,0.0);
-        assertTrue(box.isWithin(gp));
-        gp = new GeoPoint(-Math.PI * 0.25 - 0.15,0.0);
-        assertFalse(box.isWithin(gp));
-        gp = new GeoPoint(-0.1,-1.05);
-        assertTrue(box.isWithin(gp));
-        gp = new GeoPoint(-0.1,-1.15);
-        assertFalse(box.isWithin(gp));
-        gp = new GeoPoint(-0.1,1.05);
-        assertTrue(box.isWithin(gp));
-        gp = new GeoPoint(-0.1,1.15);
-        assertFalse(box.isWithin(gp));
-    }
-
-    @Test
-    public void testBBoxBounds() {
-        GeoBBox c;
-        Bounds b;
-        
-        c = GeoBBoxFactory.makeGeoBBox(0.0,-Math.PI * 0.25, -1.0, 1.0);
-
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(-1.0,b.getLeftLongitude(),0.000001);
-        assertEquals(1.0,b.getRightLongitude(),0.000001);
-        assertEquals(-Math.PI * 0.25,b.getMinLatitude(),0.000001);
-        assertEquals(0.0,b.getMaxLatitude(),0.000001);
-
-        c = GeoBBoxFactory.makeGeoBBox(0.0,-Math.PI * 0.25, 1.0, -1.0);
-
-        b = c.getBounds(null);
-        assertTrue(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        //assertEquals(1.0,b.getLeftLongitude(),0.000001);
-        //assertEquals(-1.0,b.getRightLongitude(),0.000001);
-        assertEquals(-Math.PI * 0.25,b.getMinLatitude(),0.000001);
-        assertEquals(0.0,b.getMaxLatitude(),0.000001);
-
-        c = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, -1.0, 1.0);
-
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertTrue(b.checkNoTopLatitudeBound());
-        assertTrue(b.checkNoBottomLatitudeBound());
-        assertEquals(-1.0,b.getLeftLongitude(),0.000001);
-        assertEquals(1.0,b.getRightLongitude(),0.000001);
-
-        c = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, 1.0, -1.0);
-
-        b = c.getBounds(null);
-        assertTrue(b.checkNoLongitudeBound());
-        assertTrue(b.checkNoTopLatitudeBound());
-        assertTrue(b.checkNoBottomLatitudeBound());
-        //assertEquals(1.0,b.getLeftLongitude(),0.000001);
-        //assertEquals(-1.0,b.getRightLongitude(),0.000001);
-
-        // Check wide variants of rectangle and longitude slice
-
-        c = GeoBBoxFactory.makeGeoBBox(0.0,-Math.PI * 0.25, -Math.PI+0.1, Math.PI-0.1);
-
-        b = c.getBounds(null);
-        assertTrue(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        //assertEquals(-Math.PI+0.1,b.getLeftLongitude(),0.000001);
-        //assertEquals(Math.PI-0.1,b.getRightLongitude(),0.000001);
-        assertEquals(-Math.PI * 0.25,b.getMinLatitude(),0.000001);
-        assertEquals(0.0,b.getMaxLatitude(),0.000001);
-
-        c = GeoBBoxFactory.makeGeoBBox(0.0,-Math.PI * 0.25, Math.PI-0.1, -Math.PI+0.1);
-
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(Math.PI-0.1,b.getLeftLongitude(),0.000001);
-        assertEquals(-Math.PI+0.1,b.getRightLongitude(),0.000001);
-        assertEquals(-Math.PI * 0.25,b.getMinLatitude(),0.000001);
-        assertEquals(0.0,b.getMaxLatitude(),0.000001);
-
-        c = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, -Math.PI+0.1, Math.PI-0.1);
-
-        b = c.getBounds(null);
-        assertTrue(b.checkNoLongitudeBound());
-        assertTrue(b.checkNoTopLatitudeBound());
-        assertTrue(b.checkNoBottomLatitudeBound());
-        //assertEquals(-Math.PI+0.1,b.getLeftLongitude(),0.000001);
-        //assertEquals(Math.PI-0.1,b.getRightLongitude(),0.000001);
-
-        c = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, Math.PI-0.1, -Math.PI+0.1);
-
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertTrue(b.checkNoTopLatitudeBound());
-        assertTrue(b.checkNoBottomLatitudeBound());
-        assertEquals(Math.PI-0.1,b.getLeftLongitude(),0.000001);
-        assertEquals(-Math.PI+0.1,b.getRightLongitude(),0.000001);
-        
-        // Check latitude zone
-        c = GeoBBoxFactory.makeGeoBBox(1.0, -1.0, -Math.PI, Math.PI);
-
-        b = c.getBounds(null);
-        assertTrue(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(-1.0,b.getMinLatitude(),0.000001);
-        assertEquals(1.0,b.getMaxLatitude(),0.000001);
-
-        // Now, combine a few things to test the bounds object
-        GeoBBox c1;
-        GeoBBox c2;
-        
-        c1 = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, -Math.PI, 0.0);
-        c2 = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, 0.0, Math.PI);
-
-        b = new Bounds();
-        b = c1.getBounds(b);
-        b = c2.getBounds(b);
-        assertTrue(b.checkNoLongitudeBound());
-        assertTrue(b.checkNoTopLatitudeBound());
-        assertTrue(b.checkNoBottomLatitudeBound());
-
-        c1 = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, -Math.PI, 0.0);
-        c2 = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, 0.0, Math.PI*0.5);
-
-        b = new Bounds();
-        b = c1.getBounds(b);
-        b = c2.getBounds(b);
-        assertTrue(b.checkNoLongitudeBound());
-        assertTrue(b.checkNoTopLatitudeBound());
-        assertTrue(b.checkNoBottomLatitudeBound());
-        //assertEquals(-Math.PI,b.getLeftLongitude(),0.000001);
-        //assertEquals(Math.PI*0.5,b.getRightLongitude(),0.000001);
-
-        c1 = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, -Math.PI * 0.5, 0.0);
-        c2 = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, 0.0, Math.PI);
-
-        b = new Bounds();
-        b = c1.getBounds(b);
-        b = c2.getBounds(b);
-        assertTrue(b.checkNoLongitudeBound());
-        assertTrue(b.checkNoTopLatitudeBound());
-        assertTrue(b.checkNoBottomLatitudeBound());
-        //assertEquals(-Math.PI * 0.5,b.getLeftLongitude(),0.000001);
-        //assertEquals(Math.PI,b.getRightLongitude(),0.000001);
+  protected final double DEGREES_TO_RADIANS = Math.PI / 180.0;
 
-    }
+  @Test
+  public void testBBoxDegenerate() {
+    GeoBBox box;
+    GeoConvexPolygon cp;
+    int relationship;
+    List<GeoPoint> points = new ArrayList<GeoPoint>();
+    points.add(new GeoPoint(24 * DEGREES_TO_RADIANS, -30 * DEGREES_TO_RADIANS));
+    points.add(new GeoPoint(-11 * DEGREES_TO_RADIANS, 101 * DEGREES_TO_RADIANS));
+    points.add(new GeoPoint(-49 * DEGREES_TO_RADIANS, -176 * DEGREES_TO_RADIANS));
+    GeoMembershipShape shape = GeoPolygonFactory.makeGeoPolygon(points, 0);
+    box = GeoBBoxFactory.makeGeoBBox(-64 * DEGREES_TO_RADIANS, -64 * DEGREES_TO_RADIANS, -180 * DEGREES_TO_RADIANS, 180 * DEGREES_TO_RADIANS);
+    relationship = box.getRelationship(shape);
+    assertEquals(GeoArea.CONTAINS, relationship);
+    box = GeoBBoxFactory.makeGeoBBox(-61.85 * DEGREES_TO_RADIANS, -67.5 * DEGREES_TO_RADIANS, -180 * DEGREES_TO_RADIANS, -168.75 * DEGREES_TO_RADIANS);
+    System.out.println("Shape = " + shape + " Rect = " + box);
+    relationship = box.getRelationship(shape);
+    assertEquals(GeoArea.CONTAINS, relationship);
+  }
+
+  @Test
+  public void testBBoxPointWithin() {
+    GeoBBox box;
+    GeoPoint gp;
+    // Standard normal Rect box, not crossing dateline
+    box = GeoBBoxFactory.makeGeoBBox(0.0, -Math.PI * 0.25, -1.0, 1.0);
+    gp = new GeoPoint(-0.1, 0.0);
+    assertTrue(box.isWithin(gp));
+    gp = new GeoPoint(0.1, 0.0);
+    assertFalse(box.isWithin(gp));
+    gp = new GeoPoint(-Math.PI * 0.5, 0.0);
+    assertFalse(box.isWithin(gp));
+    gp = new GeoPoint(-0.1, 1.1);
+    assertFalse(box.isWithin(gp));
+    gp = new GeoPoint(-0.1, -1.1);
+    assertFalse(box.isWithin(gp));
+    // Standard normal Rect box, crossing dateline
+    box = GeoBBoxFactory.makeGeoBBox(0.0, -Math.PI * 0.25, Math.PI - 1.0, -Math.PI + 1.0);
+    gp = new GeoPoint(-0.1, -Math.PI);
+    assertTrue(box.isWithin(gp));
+    gp = new GeoPoint(0.1, -Math.PI);
+    assertFalse(box.isWithin(gp));
+    gp = new GeoPoint(-Math.PI * 0.5, -Math.PI);
+    assertFalse(box.isWithin(gp));
+    gp = new GeoPoint(-0.1, -Math.PI + 1.1);
+    assertFalse(box.isWithin(gp));
+    gp = new GeoPoint(-0.1, -Math.PI - 1.1);
+    assertFalse(box.isWithin(gp));
+    // Latitude zone rectangle
+    box = GeoBBoxFactory.makeGeoBBox(0.0, -Math.PI * 0.25, -Math.PI, Math.PI);
+    gp = new GeoPoint(-0.1, -Math.PI);
+    assertTrue(box.isWithin(gp));
+    gp = new GeoPoint(0.1, -Math.PI);
+    assertFalse(box.isWithin(gp));
+    gp = new GeoPoint(-Math.PI * 0.5, -Math.PI);
+    assertFalse(box.isWithin(gp));
+    gp = new GeoPoint(-0.1, -Math.PI + 1.1);
+    assertTrue(box.isWithin(gp));
+    gp = new GeoPoint(-0.1, -Math.PI - 1.1);
+    assertTrue(box.isWithin(gp));
+    // World
+    box = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, -Math.PI, Math.PI);
+    gp = new GeoPoint(-0.1, -Math.PI);
+    assertTrue(box.isWithin(gp));
+    gp = new GeoPoint(0.1, -Math.PI);
+    assertTrue(box.isWithin(gp));
+    gp = new GeoPoint(-Math.PI * 0.5, -Math.PI);
+    assertTrue(box.isWithin(gp));
+    gp = new GeoPoint(-0.1, -Math.PI + 1.1);
+    assertTrue(box.isWithin(gp));
+    gp = new GeoPoint(-0.1, -Math.PI - 1.1);
+    assertTrue(box.isWithin(gp));
+
+  }
+
+  @Test
+  public void testBBoxExpand() {
+    GeoBBox box;
+    GeoPoint gp;
+    // Standard normal Rect box, not crossing dateline
+    box = GeoBBoxFactory.makeGeoBBox(0.0, -Math.PI * 0.25, -1.0, 1.0);
+    box = box.expand(0.1);
+    gp = new GeoPoint(0.05, 0.0);
+    assertTrue(box.isWithin(gp));
+    gp = new GeoPoint(0.15, 0.0);
+    assertFalse(box.isWithin(gp));
+    gp = new GeoPoint(-Math.PI * 0.25 - 0.05, 0.0);
+    assertTrue(box.isWithin(gp));
+    gp = new GeoPoint(-Math.PI * 0.25 - 0.15, 0.0);
+    assertFalse(box.isWithin(gp));
+    gp = new GeoPoint(-0.1, -1.05);
+    assertTrue(box.isWithin(gp));
+    gp = new GeoPoint(-0.1, -1.15);
+    assertFalse(box.isWithin(gp));
+    gp = new GeoPoint(-0.1, 1.05);
+    assertTrue(box.isWithin(gp));
+    gp = new GeoPoint(-0.1, 1.15);
+    assertFalse(box.isWithin(gp));
+  }
+
+  @Test
+  public void testBBoxBounds() {
+    GeoBBox c;
+    Bounds b;
+
+    c = GeoBBoxFactory.makeGeoBBox(0.0, -Math.PI * 0.25, -1.0, 1.0);
+
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(-1.0, b.getLeftLongitude(), 0.000001);
+    assertEquals(1.0, b.getRightLongitude(), 0.000001);
+    assertEquals(-Math.PI * 0.25, b.getMinLatitude(), 0.000001);
+    assertEquals(0.0, b.getMaxLatitude(), 0.000001);
+
+    c = GeoBBoxFactory.makeGeoBBox(0.0, -Math.PI * 0.25, 1.0, -1.0);
+
+    b = c.getBounds(null);
+    assertTrue(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    //assertEquals(1.0,b.getLeftLongitude(),0.000001);
+    //assertEquals(-1.0,b.getRightLongitude(),0.000001);
+    assertEquals(-Math.PI * 0.25, b.getMinLatitude(), 0.000001);
+    assertEquals(0.0, b.getMaxLatitude(), 0.000001);
+
+    c = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, -1.0, 1.0);
+
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertTrue(b.checkNoTopLatitudeBound());
+    assertTrue(b.checkNoBottomLatitudeBound());
+    assertEquals(-1.0, b.getLeftLongitude(), 0.000001);
+    assertEquals(1.0, b.getRightLongitude(), 0.000001);
+
+    c = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, 1.0, -1.0);
+
+    b = c.getBounds(null);
+    assertTrue(b.checkNoLongitudeBound());
+    assertTrue(b.checkNoTopLatitudeBound());
+    assertTrue(b.checkNoBottomLatitudeBound());
+    //assertEquals(1.0,b.getLeftLongitude(),0.000001);
+    //assertEquals(-1.0,b.getRightLongitude(),0.000001);
+
+    // Check wide variants of rectangle and longitude slice
+
+    c = GeoBBoxFactory.makeGeoBBox(0.0, -Math.PI * 0.25, -Math.PI + 0.1, Math.PI - 0.1);
+
+    b = c.getBounds(null);
+    assertTrue(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    //assertEquals(-Math.PI+0.1,b.getLeftLongitude(),0.000001);
+    //assertEquals(Math.PI-0.1,b.getRightLongitude(),0.000001);
+    assertEquals(-Math.PI * 0.25, b.getMinLatitude(), 0.000001);
+    assertEquals(0.0, b.getMaxLatitude(), 0.000001);
+
+    c = GeoBBoxFactory.makeGeoBBox(0.0, -Math.PI * 0.25, Math.PI - 0.1, -Math.PI + 0.1);
+
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(Math.PI - 0.1, b.getLeftLongitude(), 0.000001);
+    assertEquals(-Math.PI + 0.1, b.getRightLongitude(), 0.000001);
+    assertEquals(-Math.PI * 0.25, b.getMinLatitude(), 0.000001);
+    assertEquals(0.0, b.getMaxLatitude(), 0.000001);
+
+    c = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, -Math.PI + 0.1, Math.PI - 0.1);
+
+    b = c.getBounds(null);
+    assertTrue(b.checkNoLongitudeBound());
+    assertTrue(b.checkNoTopLatitudeBound());
+    assertTrue(b.checkNoBottomLatitudeBound());
+    //assertEquals(-Math.PI+0.1,b.getLeftLongitude(),0.000001);
+    //assertEquals(Math.PI-0.1,b.getRightLongitude(),0.000001);
+
+    c = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, Math.PI - 0.1, -Math.PI + 0.1);
+
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertTrue(b.checkNoTopLatitudeBound());
+    assertTrue(b.checkNoBottomLatitudeBound());
+    assertEquals(Math.PI - 0.1, b.getLeftLongitude(), 0.000001);
+    assertEquals(-Math.PI + 0.1, b.getRightLongitude(), 0.000001);
+
+    // Check latitude zone
+    c = GeoBBoxFactory.makeGeoBBox(1.0, -1.0, -Math.PI, Math.PI);
+
+    b = c.getBounds(null);
+    assertTrue(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(-1.0, b.getMinLatitude(), 0.000001);
+    assertEquals(1.0, b.getMaxLatitude(), 0.000001);
+
+    // Now, combine a few things to test the bounds object
+    GeoBBox c1;
+    GeoBBox c2;
+
+    c1 = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, -Math.PI, 0.0);
+    c2 = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, 0.0, Math.PI);
+
+    b = new Bounds();
+    b = c1.getBounds(b);
+    b = c2.getBounds(b);
+    assertTrue(b.checkNoLongitudeBound());
+    assertTrue(b.checkNoTopLatitudeBound());
+    assertTrue(b.checkNoBottomLatitudeBound());
+
+    c1 = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, -Math.PI, 0.0);
+    c2 = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, 0.0, Math.PI * 0.5);
+
+    b = new Bounds();
+    b = c1.getBounds(b);
+    b = c2.getBounds(b);
+    assertTrue(b.checkNoLongitudeBound());
+    assertTrue(b.checkNoTopLatitudeBound());
+    assertTrue(b.checkNoBottomLatitudeBound());
+    //assertEquals(-Math.PI,b.getLeftLongitude(),0.000001);
+    //assertEquals(Math.PI*0.5,b.getRightLongitude(),0.000001);
+
+    c1 = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, -Math.PI * 0.5, 0.0);
+    c2 = GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, 0.0, Math.PI);
+
+    b = new Bounds();
+    b = c1.getBounds(b);
+    b = c2.getBounds(b);
+    assertTrue(b.checkNoLongitudeBound());
+    assertTrue(b.checkNoTopLatitudeBound());
+    assertTrue(b.checkNoBottomLatitudeBound());
+    //assertEquals(-Math.PI * 0.5,b.getLeftLongitude(),0.000001);
+    //assertEquals(Math.PI,b.getRightLongitude(),0.000001);
+
+  }
 
 }

Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircleTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircleTest.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircleTest.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircleTest.java Mon May  4 13:19:02 2015
@@ -17,201 +17,203 @@ package org.apache.lucene.spatial.spatia
  * limitations under the License.
  */
 
-import static org.junit.Assert.*;
-
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 public class GeoCircleTest {
 
 
-    @Test
-    public void testCircleDistance() {
-        GeoCircle c;
-        GeoPoint gp;
-        c = new GeoCircle(0.0,-0.5,0.1);
-        gp = new GeoPoint(0.0,0.0);
-        assertEquals(Double.MAX_VALUE, c.computeArcDistance(gp), 0.0);
-        assertEquals(Double.MAX_VALUE, c.computeLinearDistance(gp), 0.0);
-        assertEquals(Double.MAX_VALUE, c.computeNormalDistance(gp), 0.0);
-        gp = new GeoPoint(0.0,-0.5);
-        assertEquals(0.0, c.computeArcDistance(gp), 0.000001);
-        assertEquals(0.0, c.computeLinearDistance(gp), 0.000001);
-        assertEquals(0.0, c.computeNormalDistance(gp), 0.000001);
-        gp = new GeoPoint(0.05,-0.5);
-        assertEquals(0.05, c.computeArcDistance(gp), 0.000001);
-        assertEquals(0.049995, c.computeLinearDistance(gp), 0.000001);
-        assertEquals(0.049979, c.computeNormalDistance(gp), 0.000001);
-    }
-
-    @Test
-    public void testCirclePointWithin() {
-        GeoCircle c;
-        GeoPoint gp;
-        c = new GeoCircle(0.0,-0.5,0.1);
-        gp = new GeoPoint(0.0,0.0);
-        assertFalse(c.isWithin(gp));
-        gp = new GeoPoint(0.0,-0.5);
-        assertTrue(c.isWithin(gp));
-        gp = new GeoPoint(0.0,-0.55);
-        assertTrue(c.isWithin(gp));
-        gp = new GeoPoint(0.0,-0.45);
-        assertTrue(c.isWithin(gp));
-        gp = new GeoPoint(Math.PI * 0.5,0.0);
-        assertFalse(c.isWithin(gp));
-        gp = new GeoPoint(0.0,Math.PI);
-        assertFalse(c.isWithin(gp));
-    }
-
-    @Test
-    public void testCircleBounds() {
-        GeoCircle c;
-        Bounds b;
-        
-
-        // Vertical circle cases
-        c = new GeoCircle(0.0,-0.5,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(-0.6,b.getLeftLongitude(),0.000001);
-        assertEquals(-0.4,b.getRightLongitude(),0.000001);
-        assertEquals(-0.1,b.getMinLatitude(),0.000001);
-        assertEquals(0.1,b.getMaxLatitude(),0.000001);
-        c = new GeoCircle(0.0,0.5,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(0.4,b.getLeftLongitude(),0.000001);
-        assertEquals(0.6,b.getRightLongitude(),0.000001);
-        assertEquals(-0.1,b.getMinLatitude(),0.000001);
-        assertEquals(0.1,b.getMaxLatitude(),0.000001);
-        c = new GeoCircle(0.0,0.0,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(-0.1,b.getLeftLongitude(),0.000001);
-        assertEquals(0.1,b.getRightLongitude(),0.000001);
-        assertEquals(-0.1,b.getMinLatitude(),0.000001);
-        assertEquals(0.1,b.getMaxLatitude(),0.000001);
-        c = new GeoCircle(0.0,Math.PI,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(Math.PI-0.1,b.getLeftLongitude(),0.000001);
-        assertEquals(-Math.PI+0.1,b.getRightLongitude(),0.000001);
-        assertEquals(-0.1,b.getMinLatitude(),0.000001);
-        assertEquals(0.1,b.getMaxLatitude(),0.000001);
-        // Horizontal circle cases
-        c = new GeoCircle(Math.PI * 0.5,0.0,0.1);
-        b = c.getBounds(null);
-        assertTrue(b.checkNoLongitudeBound());
-        assertTrue(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(Math.PI * 0.5 - 0.1,b.getMinLatitude(),0.000001);
-        c = new GeoCircle(-Math.PI * 0.5,0.0,0.1);
-        b = c.getBounds(null);
-        assertTrue(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertTrue(b.checkNoBottomLatitudeBound());
-        assertEquals(-Math.PI * 0.5 + 0.1,b.getMaxLatitude(),0.000001);
-        
-        // Now do a somewhat tilted plane, facing different directions.
-        c = new GeoCircle(0.01,0.0,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(0.11,b.getMaxLatitude(),0.000001);
-        assertEquals(-0.09,b.getMinLatitude(),0.000001);
-        assertEquals(-0.1,b.getLeftLongitude(),0.00001);
-        assertEquals(0.1,b.getRightLongitude(),0.00001);
-
-        c = new GeoCircle(0.01,Math.PI,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(0.11,b.getMaxLatitude(),0.000001);
-        assertEquals(-0.09,b.getMinLatitude(),0.000001);
-        assertEquals(Math.PI-0.1,b.getLeftLongitude(),0.00001);
-        assertEquals(-Math.PI+0.1,b.getRightLongitude(),0.00001);
-
-        c = new GeoCircle(0.01,Math.PI * 0.5,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(0.11,b.getMaxLatitude(),0.000001);
-        assertEquals(-0.09,b.getMinLatitude(),0.000001);
-        assertEquals(Math.PI * 0.5 - 0.1,b.getLeftLongitude(),0.00001);
-        assertEquals(Math.PI * 0.5 + 0.1,b.getRightLongitude(),0.00001);
-
-        c = new GeoCircle(0.01,-Math.PI * 0.5,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(0.11,b.getMaxLatitude(),0.000001);
-        assertEquals(-0.09,b.getMinLatitude(),0.000001);
-        assertEquals(-Math.PI * 0.5 - 0.1,b.getLeftLongitude(),0.00001);
-        assertEquals(-Math.PI * 0.5 + 0.1,b.getRightLongitude(),0.00001);
-
-        // Slightly tilted, PI/4 direction.
-        c = new GeoCircle(0.01,Math.PI * 0.25,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(0.11,b.getMaxLatitude(),0.000001);
-        assertEquals(-0.09,b.getMinLatitude(),0.000001);
-        assertEquals(Math.PI * 0.25 - 0.1,b.getLeftLongitude(),0.00001);
-        assertEquals(Math.PI * 0.25 + 0.1,b.getRightLongitude(),0.00001);
-
-        c = new GeoCircle(0.01,-Math.PI * 0.25,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(0.11,b.getMaxLatitude(),0.000001);
-        assertEquals(-0.09,b.getMinLatitude(),0.000001);
-        assertEquals(-Math.PI * 0.25 - 0.1,b.getLeftLongitude(),0.00001);
-        assertEquals(-Math.PI * 0.25 + 0.1,b.getRightLongitude(),0.00001);
-
-        c = new GeoCircle(-0.01,Math.PI * 0.25,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(0.09,b.getMaxLatitude(),0.000001);
-        assertEquals(-0.11,b.getMinLatitude(),0.000001);
-        assertEquals(Math.PI * 0.25 - 0.1,b.getLeftLongitude(),0.00001);
-        assertEquals(Math.PI * 0.25 + 0.1,b.getRightLongitude(),0.00001);
-
-        c = new GeoCircle(-0.01,-Math.PI * 0.25,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(0.09,b.getMaxLatitude(),0.000001);
-        assertEquals(-0.11,b.getMinLatitude(),0.000001);
-        assertEquals(-Math.PI * 0.25 - 0.1,b.getLeftLongitude(),0.00001);
-        assertEquals(-Math.PI * 0.25 + 0.1,b.getRightLongitude(),0.00001);
-
-        // Now do a somewhat tilted plane.
-        c = new GeoCircle(0.01,-0.5,0.1);
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(0.11,b.getMaxLatitude(),0.000001);
-        assertEquals(-0.09,b.getMinLatitude(),0.000001);
-        assertEquals(-0.6,b.getLeftLongitude(),0.00001);
-        assertEquals(-0.4,b.getRightLongitude(),0.00001);
+  @Test
+  public void testCircleDistance() {
+    GeoCircle c;
+    GeoPoint gp;
+    c = new GeoCircle(0.0, -0.5, 0.1);
+    gp = new GeoPoint(0.0, 0.0);
+    assertEquals(Double.MAX_VALUE, c.computeArcDistance(gp), 0.0);
+    assertEquals(Double.MAX_VALUE, c.computeLinearDistance(gp), 0.0);
+    assertEquals(Double.MAX_VALUE, c.computeNormalDistance(gp), 0.0);
+    gp = new GeoPoint(0.0, -0.5);
+    assertEquals(0.0, c.computeArcDistance(gp), 0.000001);
+    assertEquals(0.0, c.computeLinearDistance(gp), 0.000001);
+    assertEquals(0.0, c.computeNormalDistance(gp), 0.000001);
+    gp = new GeoPoint(0.05, -0.5);
+    assertEquals(0.05, c.computeArcDistance(gp), 0.000001);
+    assertEquals(0.049995, c.computeLinearDistance(gp), 0.000001);
+    assertEquals(0.049979, c.computeNormalDistance(gp), 0.000001);
+  }
+
+  @Test
+  public void testCirclePointWithin() {
+    GeoCircle c;
+    GeoPoint gp;
+    c = new GeoCircle(0.0, -0.5, 0.1);
+    gp = new GeoPoint(0.0, 0.0);
+    assertFalse(c.isWithin(gp));
+    gp = new GeoPoint(0.0, -0.5);
+    assertTrue(c.isWithin(gp));
+    gp = new GeoPoint(0.0, -0.55);
+    assertTrue(c.isWithin(gp));
+    gp = new GeoPoint(0.0, -0.45);
+    assertTrue(c.isWithin(gp));
+    gp = new GeoPoint(Math.PI * 0.5, 0.0);
+    assertFalse(c.isWithin(gp));
+    gp = new GeoPoint(0.0, Math.PI);
+    assertFalse(c.isWithin(gp));
+  }
+
+  @Test
+  public void testCircleBounds() {
+    GeoCircle c;
+    Bounds b;
+
+
+    // Vertical circle cases
+    c = new GeoCircle(0.0, -0.5, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(-0.6, b.getLeftLongitude(), 0.000001);
+    assertEquals(-0.4, b.getRightLongitude(), 0.000001);
+    assertEquals(-0.1, b.getMinLatitude(), 0.000001);
+    assertEquals(0.1, b.getMaxLatitude(), 0.000001);
+    c = new GeoCircle(0.0, 0.5, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(0.4, b.getLeftLongitude(), 0.000001);
+    assertEquals(0.6, b.getRightLongitude(), 0.000001);
+    assertEquals(-0.1, b.getMinLatitude(), 0.000001);
+    assertEquals(0.1, b.getMaxLatitude(), 0.000001);
+    c = new GeoCircle(0.0, 0.0, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(-0.1, b.getLeftLongitude(), 0.000001);
+    assertEquals(0.1, b.getRightLongitude(), 0.000001);
+    assertEquals(-0.1, b.getMinLatitude(), 0.000001);
+    assertEquals(0.1, b.getMaxLatitude(), 0.000001);
+    c = new GeoCircle(0.0, Math.PI, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(Math.PI - 0.1, b.getLeftLongitude(), 0.000001);
+    assertEquals(-Math.PI + 0.1, b.getRightLongitude(), 0.000001);
+    assertEquals(-0.1, b.getMinLatitude(), 0.000001);
+    assertEquals(0.1, b.getMaxLatitude(), 0.000001);
+    // Horizontal circle cases
+    c = new GeoCircle(Math.PI * 0.5, 0.0, 0.1);
+    b = c.getBounds(null);
+    assertTrue(b.checkNoLongitudeBound());
+    assertTrue(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(Math.PI * 0.5 - 0.1, b.getMinLatitude(), 0.000001);
+    c = new GeoCircle(-Math.PI * 0.5, 0.0, 0.1);
+    b = c.getBounds(null);
+    assertTrue(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertTrue(b.checkNoBottomLatitudeBound());
+    assertEquals(-Math.PI * 0.5 + 0.1, b.getMaxLatitude(), 0.000001);
+
+    // Now do a somewhat tilted plane, facing different directions.
+    c = new GeoCircle(0.01, 0.0, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(0.11, b.getMaxLatitude(), 0.000001);
+    assertEquals(-0.09, b.getMinLatitude(), 0.000001);
+    assertEquals(-0.1, b.getLeftLongitude(), 0.00001);
+    assertEquals(0.1, b.getRightLongitude(), 0.00001);
+
+    c = new GeoCircle(0.01, Math.PI, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(0.11, b.getMaxLatitude(), 0.000001);
+    assertEquals(-0.09, b.getMinLatitude(), 0.000001);
+    assertEquals(Math.PI - 0.1, b.getLeftLongitude(), 0.00001);
+    assertEquals(-Math.PI + 0.1, b.getRightLongitude(), 0.00001);
+
+    c = new GeoCircle(0.01, Math.PI * 0.5, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(0.11, b.getMaxLatitude(), 0.000001);
+    assertEquals(-0.09, b.getMinLatitude(), 0.000001);
+    assertEquals(Math.PI * 0.5 - 0.1, b.getLeftLongitude(), 0.00001);
+    assertEquals(Math.PI * 0.5 + 0.1, b.getRightLongitude(), 0.00001);
+
+    c = new GeoCircle(0.01, -Math.PI * 0.5, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(0.11, b.getMaxLatitude(), 0.000001);
+    assertEquals(-0.09, b.getMinLatitude(), 0.000001);
+    assertEquals(-Math.PI * 0.5 - 0.1, b.getLeftLongitude(), 0.00001);
+    assertEquals(-Math.PI * 0.5 + 0.1, b.getRightLongitude(), 0.00001);
+
+    // Slightly tilted, PI/4 direction.
+    c = new GeoCircle(0.01, Math.PI * 0.25, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(0.11, b.getMaxLatitude(), 0.000001);
+    assertEquals(-0.09, b.getMinLatitude(), 0.000001);
+    assertEquals(Math.PI * 0.25 - 0.1, b.getLeftLongitude(), 0.00001);
+    assertEquals(Math.PI * 0.25 + 0.1, b.getRightLongitude(), 0.00001);
+
+    c = new GeoCircle(0.01, -Math.PI * 0.25, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(0.11, b.getMaxLatitude(), 0.000001);
+    assertEquals(-0.09, b.getMinLatitude(), 0.000001);
+    assertEquals(-Math.PI * 0.25 - 0.1, b.getLeftLongitude(), 0.00001);
+    assertEquals(-Math.PI * 0.25 + 0.1, b.getRightLongitude(), 0.00001);
+
+    c = new GeoCircle(-0.01, Math.PI * 0.25, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(0.09, b.getMaxLatitude(), 0.000001);
+    assertEquals(-0.11, b.getMinLatitude(), 0.000001);
+    assertEquals(Math.PI * 0.25 - 0.1, b.getLeftLongitude(), 0.00001);
+    assertEquals(Math.PI * 0.25 + 0.1, b.getRightLongitude(), 0.00001);
+
+    c = new GeoCircle(-0.01, -Math.PI * 0.25, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(0.09, b.getMaxLatitude(), 0.000001);
+    assertEquals(-0.11, b.getMinLatitude(), 0.000001);
+    assertEquals(-Math.PI * 0.25 - 0.1, b.getLeftLongitude(), 0.00001);
+    assertEquals(-Math.PI * 0.25 + 0.1, b.getRightLongitude(), 0.00001);
+
+    // Now do a somewhat tilted plane.
+    c = new GeoCircle(0.01, -0.5, 0.1);
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(0.11, b.getMaxLatitude(), 0.000001);
+    assertEquals(-0.09, b.getMinLatitude(), 0.000001);
+    assertEquals(-0.6, b.getLeftLongitude(), 0.00001);
+    assertEquals(-0.4, b.getRightLongitude(), 0.00001);
 
-    }
+  }
 
 }

Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoConvexPolygonTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoConvexPolygonTest.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoConvexPolygonTest.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoConvexPolygonTest.java Mon May  4 13:19:02 2015
@@ -26,63 +26,63 @@ import static org.junit.Assert.assertTru
 public class GeoConvexPolygonTest {
 
 
-    @Test
-    public void testPolygonPointWithin() {
-        GeoConvexPolygon c;
-        GeoPoint gp;
-        c = new GeoConvexPolygon(-0.1,-0.5);
-        c.addPoint(0.0,-0.6,false);
-        c.addPoint(0.1,-0.5,false);
-        c.addPoint(0.0,-0.4,false);
-        c.donePoints(false);
-        // Sample some points within
-        gp = new GeoPoint(0.0,-0.5);
-        assertTrue(c.isWithin(gp));
-        gp = new GeoPoint(0.0,-0.55);
-        assertTrue(c.isWithin(gp));
-        gp = new GeoPoint(0.0,-0.45);
-        assertTrue(c.isWithin(gp));
-        gp = new GeoPoint(-0.05,-0.5);
-        assertTrue(c.isWithin(gp));
-        gp = new GeoPoint(0.05,-0.5);
-        assertTrue(c.isWithin(gp));
-        // Sample some nearby points outside
-        gp = new GeoPoint(0.0,-0.65);
-        assertFalse(c.isWithin(gp));
-        gp = new GeoPoint(0.0,-0.35);
-        assertFalse(c.isWithin(gp));
-        gp = new GeoPoint(-0.15,-0.5);
-        assertFalse(c.isWithin(gp));
-        gp = new GeoPoint(0.15,-0.5);
-        assertFalse(c.isWithin(gp));        
-        // Random points outside
-        gp = new GeoPoint(0.0,0.0);
-        assertFalse(c.isWithin(gp));
-        gp = new GeoPoint(Math.PI * 0.5,0.0);
-        assertFalse(c.isWithin(gp));
-        gp = new GeoPoint(0.0,Math.PI);
-        assertFalse(c.isWithin(gp));
-    }
-
-    @Test
-    public void testPolygonBounds() {
-        GeoConvexPolygon c;
-        Bounds b;
-        
-        c = new GeoConvexPolygon(-0.1,-0.5);
-        c.addPoint(0.0,-0.6,false);
-        c.addPoint(0.1,-0.5,false);
-        c.addPoint(0.0,-0.4,false);
-        c.donePoints(false);
-
-        b = c.getBounds(null);
-        assertFalse(b.checkNoLongitudeBound());
-        assertFalse(b.checkNoTopLatitudeBound());
-        assertFalse(b.checkNoBottomLatitudeBound());
-        assertEquals(-0.6,b.getLeftLongitude(),0.000001);
-        assertEquals(-0.4,b.getRightLongitude(),0.000001);
-        assertEquals(-0.1,b.getMinLatitude(),0.000001);
-        assertEquals(0.1,b.getMaxLatitude(),0.000001);
-    }
+  @Test
+  public void testPolygonPointWithin() {
+    GeoConvexPolygon c;
+    GeoPoint gp;
+    c = new GeoConvexPolygon(-0.1, -0.5);
+    c.addPoint(0.0, -0.6, false);
+    c.addPoint(0.1, -0.5, false);
+    c.addPoint(0.0, -0.4, false);
+    c.donePoints(false);
+    // Sample some points within
+    gp = new GeoPoint(0.0, -0.5);
+    assertTrue(c.isWithin(gp));
+    gp = new GeoPoint(0.0, -0.55);
+    assertTrue(c.isWithin(gp));
+    gp = new GeoPoint(0.0, -0.45);
+    assertTrue(c.isWithin(gp));
+    gp = new GeoPoint(-0.05, -0.5);
+    assertTrue(c.isWithin(gp));
+    gp = new GeoPoint(0.05, -0.5);
+    assertTrue(c.isWithin(gp));
+    // Sample some nearby points outside
+    gp = new GeoPoint(0.0, -0.65);
+    assertFalse(c.isWithin(gp));
+    gp = new GeoPoint(0.0, -0.35);
+    assertFalse(c.isWithin(gp));
+    gp = new GeoPoint(-0.15, -0.5);
+    assertFalse(c.isWithin(gp));
+    gp = new GeoPoint(0.15, -0.5);
+    assertFalse(c.isWithin(gp));
+    // Random points outside
+    gp = new GeoPoint(0.0, 0.0);
+    assertFalse(c.isWithin(gp));
+    gp = new GeoPoint(Math.PI * 0.5, 0.0);
+    assertFalse(c.isWithin(gp));
+    gp = new GeoPoint(0.0, Math.PI);
+    assertFalse(c.isWithin(gp));
+  }
+
+  @Test
+  public void testPolygonBounds() {
+    GeoConvexPolygon c;
+    Bounds b;
+
+    c = new GeoConvexPolygon(-0.1, -0.5);
+    c.addPoint(0.0, -0.6, false);
+    c.addPoint(0.1, -0.5, false);
+    c.addPoint(0.0, -0.4, false);
+    c.donePoints(false);
+
+    b = c.getBounds(null);
+    assertFalse(b.checkNoLongitudeBound());
+    assertFalse(b.checkNoTopLatitudeBound());
+    assertFalse(b.checkNoBottomLatitudeBound());
+    assertEquals(-0.6, b.getLeftLongitude(), 0.000001);
+    assertEquals(-0.4, b.getRightLongitude(), 0.000001);
+    assertEquals(-0.1, b.getMinLatitude(), 0.000001);
+    assertEquals(0.1, b.getMaxLatitude(), 0.000001);
+  }
 
 }