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/27 06:54:51 UTC
svn commit: r1681907 [1/4] - in
/lucene/dev/branches/lucene6487/lucene/spatial/src:
java/org/apache/lucene/spatial/spatial4j/
java/org/apache/lucene/spatial/spatial4j/geo3d/
test/org/apache/lucene/spatial/spatial4j/
test/org/apache/lucene/spatial/spati...
Author: dsmiley
Date: Wed May 27 04:54:50 2015
New Revision: 1681907
URL: http://svn.apache.org/r1681907
Log:
LUCENE-6487: Geo3D with WGS84 in-progress with David's mods
(PlanetModel, and refactor of Geo3dShapeRectRelationTestCase)
Added:
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseBBox.java
- copied, changed from r1681906, lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxBase.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseShape.java (with props)
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/PlanetModel.java (with props)
lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTestCase.java (with props)
lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeSphereModelRectRelationTest.java
- copied, changed from r1681647, lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java
lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeWGS84ModelRectRelationTest.java (with props)
lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoModelTest.java (with props)
Removed:
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxBase.java
lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java
Modified:
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShape.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Bounds.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoAreaFactory.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseExtendedShape.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoConvexPolygon.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateHorizontalLine.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateLatitudeZone.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateLongitudeSlice.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegeneratePoint.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateVerticalLine.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoLatitudeZone.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoLongitudeSlice.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoNorthLatitudeZone.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoNorthRectangle.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPath.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPoint.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPolygonFactory.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoRectangle.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoSouthLatitudeZone.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoSouthRectangle.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoWideDegenerateHorizontalLine.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoWideLongitudeSlice.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoWideNorthRectangle.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoWideRectangle.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoWideSouthRectangle.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoWorld.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/SidedPlane.java
lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java
lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dRptTest.java
lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxTest.java
lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircleTest.java
lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoConvexPolygonTest.java
lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPathTest.java
lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPolygonTest.java
lucene/dev/branches/lucene6487/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/PlaneTest.java
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShape.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShape.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShape.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/Geo3dShape.java Wed May 27 04:54:50 2015
@@ -28,6 +28,7 @@ import org.apache.lucene.spatial.spatial
import org.apache.lucene.spatial.spatial4j.geo3d.GeoAreaFactory;
import org.apache.lucene.spatial.spatial4j.geo3d.GeoPoint;
import org.apache.lucene.spatial.spatial4j.geo3d.GeoShape;
+import org.apache.lucene.spatial.spatial4j.geo3d.PlanetModel;
/**
* A 3D planar geometry based Spatial4j Shape implementation.
@@ -38,17 +39,23 @@ public class Geo3dShape implements Shape
public final SpatialContext ctx;
public final GeoShape shape;
+ public final PlanetModel planetModel;
private Rectangle boundingBox = null;
public final static double RADIANS_PER_DEGREE = Math.PI / 180.0;
public final static double DEGREES_PER_RADIAN = 1.0 / RADIANS_PER_DEGREE;
- public Geo3dShape(GeoShape shape, SpatialContext ctx) {
+ public Geo3dShape(final GeoShape shape, final SpatialContext ctx) {
+ this(PlanetModel.SPHERE, shape, ctx);
+ }
+
+ public Geo3dShape(final PlanetModel planetModel, final GeoShape shape, final SpatialContext ctx) {
if (!ctx.isGeo()) {
throw new IllegalArgumentException("SpatialContext.isGeo() must be true");
}
this.ctx = ctx;
+ this.planetModel = planetModel;
this.shape = shape;
}
@@ -64,7 +71,8 @@ public class Geo3dShape implements Shape
protected SpatialRelation relate(Rectangle r) {
// Construct the right kind of GeoArea first
- GeoArea geoArea = GeoAreaFactory.makeGeoArea(r.getMaxY() * RADIANS_PER_DEGREE,
+ GeoArea geoArea = GeoAreaFactory.makeGeoArea(planetModel,
+ r.getMaxY() * RADIANS_PER_DEGREE,
r.getMinY() * RADIANS_PER_DEGREE,
r.getMinX() * RADIANS_PER_DEGREE,
r.getMaxX() * RADIANS_PER_DEGREE);
@@ -83,7 +91,7 @@ public class Geo3dShape implements Shape
protected SpatialRelation relate(Point p) {
// Create a GeoPoint
- GeoPoint point = new GeoPoint(p.getY()*RADIANS_PER_DEGREE, p.getX()*RADIANS_PER_DEGREE);
+ GeoPoint point = new GeoPoint(planetModel, p.getY()*RADIANS_PER_DEGREE, p.getX()*RADIANS_PER_DEGREE);
if (shape.isWithin(point)) {
// Point within shape
return SpatialRelation.CONTAINS;
@@ -91,7 +99,9 @@ public class Geo3dShape implements Shape
return SpatialRelation.DISJOINT;
}
- protected final double ROUNDOFF_ADJUSTMENT = 0.01;
+ // The required size of this adjustment depends on the actual planetary model chosen.
+ // This value is big enough to account for WGS84.
+ protected final double ROUNDOFF_ADJUSTMENT = 0.05;
@Override
public Rectangle getBoundingBox() {
@@ -150,7 +160,7 @@ public class Geo3dShape implements Shape
@Override
public String toString() {
- return "Geo3dShape{" + shape + '}';
+ return "Geo3dShape{planetmodel=" + planetModel+", shape="+shape + '}';
}
@Override
@@ -158,11 +168,11 @@ public class Geo3dShape implements Shape
if (!(other instanceof Geo3dShape))
return false;
Geo3dShape tr = (Geo3dShape)other;
- return tr.shape.equals(shape);
+ return tr.planetModel.equals(planetModel) && tr.shape.equals(shape);
}
@Override
public int hashCode() {
- return shape.hashCode();
+ return planetModel.hashCode() + shape.hashCode();
}
}
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Bounds.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Bounds.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Bounds.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Bounds.java Wed May 27 04:54:50 2015
@@ -254,11 +254,11 @@ public class Bounds {
}
}
- public Bounds addPoint(Vector v) {
+ public Bounds addPoint(final Vector v) {
return addPoint(v.x, v.y, v.z);
}
- public Bounds addPoint(double x, double y, double z) {
+ public Bounds addPoint(final double x, final double y, final double z) {
if (!noLongitudeBound) {
// Get a longitude value
double longitude = Math.atan2(y, x);
@@ -267,7 +267,7 @@ public class Bounds {
}
if (!noTopLatitudeBound || !noBottomLatitudeBound) {
// Compute a latitude value
- double latitude = Math.asin(z);
+ double latitude = Math.asin(z/Math.sqrt(z * z + x * x + y * y));
addLatitudeBound(latitude);
}
return this;
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoAreaFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoAreaFactory.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoAreaFactory.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoAreaFactory.java Wed May 27 04:54:50 2015
@@ -35,8 +35,8 @@ public class GeoAreaFactory {
* @param rightLon is the right longitude
* @return a GeoArea corresponding to what was specified.
*/
- public static GeoArea makeGeoArea(double topLat, double bottomLat, double leftLon, double rightLon) {
- return GeoBBoxFactory.makeGeoBBox(topLat, bottomLat, leftLon, rightLon);
+ public static GeoArea makeGeoArea(final PlanetModel planetModel, final double topLat, final double bottomLat, final double leftLon, final double rightLon) {
+ return GeoBBoxFactory.makeGeoBBox(planetModel, topLat, bottomLat, leftLon, rightLon);
}
}
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java Wed May 27 04:54:50 2015
@@ -29,13 +29,14 @@ public class GeoBBoxFactory {
/**
* Create a geobbox of the right kind given the specified bounds.
*
+ * @param planetModel is the planet model
* @param topLat is the top latitude
* @param bottomLat is the bottom latitude
* @param leftLon is the left longitude
* @param rightLon is the right longitude
* @return a GeoBBox corresponding to what was specified.
*/
- public static GeoBBox makeGeoBBox(double topLat, double bottomLat, double leftLon, double rightLon) {
+ public static GeoBBox makeGeoBBox(final PlanetModel planetModel, double topLat, double bottomLat, double leftLon, double rightLon) {
//System.err.println("Making rectangle for topLat="+topLat*180.0/Math.PI+", bottomLat="+bottomLat*180.0/Math.PI+", leftLon="+leftLon*180.0/Math.PI+", rightlon="+rightLon*180.0/Math.PI);
if (topLat > Math.PI * 0.5)
topLat = Math.PI * 0.5;
@@ -47,17 +48,17 @@ public class GeoBBoxFactory {
rightLon = Math.PI;
if (Math.abs(leftLon + Math.PI) < Vector.MINIMUM_RESOLUTION && Math.abs(rightLon - Math.PI) < Vector.MINIMUM_RESOLUTION) {
if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION && Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION)
- return new GeoWorld();
+ return new GeoWorld(planetModel);
if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_RESOLUTION) {
if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION || Math.abs(topLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION)
- return new GeoDegeneratePoint(topLat, 0.0);
- return new GeoDegenerateLatitudeZone(topLat);
+ return new GeoDegeneratePoint(planetModel, topLat, 0.0);
+ return new GeoDegenerateLatitudeZone(planetModel, topLat);
}
if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION)
- return new GeoNorthLatitudeZone(bottomLat);
+ return new GeoNorthLatitudeZone(planetModel, bottomLat);
else if (Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION)
- return new GeoSouthLatitudeZone(topLat);
- return new GeoLatitudeZone(topLat, bottomLat);
+ return new GeoSouthLatitudeZone(planetModel, topLat);
+ return new GeoLatitudeZone(planetModel, topLat, bottomLat);
}
//System.err.println(" not latitude zone");
double extent = rightLon - leftLon;
@@ -65,47 +66,47 @@ public class GeoBBoxFactory {
extent += Math.PI * 2.0;
if (topLat == Math.PI * 0.5 && bottomLat == -Math.PI * 0.5) {
if (Math.abs(leftLon - rightLon) < Vector.MINIMUM_RESOLUTION)
- return new GeoDegenerateLongitudeSlice(leftLon);
+ return new GeoDegenerateLongitudeSlice(planetModel, leftLon);
if (extent >= Math.PI)
- return new GeoWideLongitudeSlice(leftLon, rightLon);
+ return new GeoWideLongitudeSlice(planetModel, leftLon, rightLon);
- return new GeoLongitudeSlice(leftLon, rightLon);
+ return new GeoLongitudeSlice(planetModel, leftLon, rightLon);
}
//System.err.println(" not longitude slice");
if (Math.abs(leftLon - rightLon) < Vector.MINIMUM_RESOLUTION) {
if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_RESOLUTION)
- return new GeoDegeneratePoint(topLat, leftLon);
- return new GeoDegenerateVerticalLine(topLat, bottomLat, leftLon);
+ return new GeoDegeneratePoint(planetModel, topLat, leftLon);
+ return new GeoDegenerateVerticalLine(planetModel, topLat, bottomLat, leftLon);
}
//System.err.println(" not vertical line");
if (extent >= Math.PI) {
if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_RESOLUTION) {
//System.err.println(" wide degenerate line");
- return new GeoWideDegenerateHorizontalLine(topLat, leftLon, rightLon);
+ return new GeoWideDegenerateHorizontalLine(planetModel, topLat, leftLon, rightLon);
}
if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) {
- return new GeoWideNorthRectangle(bottomLat, leftLon, rightLon);
+ return new GeoWideNorthRectangle(planetModel, bottomLat, leftLon, rightLon);
} else if (Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) {
- return new GeoWideSouthRectangle(topLat, leftLon, rightLon);
+ return new GeoWideSouthRectangle(planetModel, topLat, leftLon, rightLon);
}
//System.err.println(" wide rect");
- return new GeoWideRectangle(topLat, bottomLat, leftLon, rightLon);
+ return new GeoWideRectangle(planetModel, topLat, bottomLat, leftLon, rightLon);
}
if (Math.abs(topLat - bottomLat) < Vector.MINIMUM_RESOLUTION) {
if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION || Math.abs(topLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) {
- return new GeoDegeneratePoint(topLat, 0.0);
+ return new GeoDegeneratePoint(planetModel, topLat, 0.0);
}
//System.err.println(" horizontal line");
- return new GeoDegenerateHorizontalLine(topLat, leftLon, rightLon);
+ return new GeoDegenerateHorizontalLine(planetModel, topLat, leftLon, rightLon);
}
if (Math.abs(topLat - Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) {
- return new GeoNorthRectangle(bottomLat, leftLon, rightLon);
+ return new GeoNorthRectangle(planetModel, bottomLat, leftLon, rightLon);
} else if (Math.abs(bottomLat + Math.PI * 0.5) < Vector.MINIMUM_RESOLUTION) {
- return new GeoSouthRectangle(topLat, leftLon, rightLon);
+ return new GeoSouthRectangle(planetModel, topLat, leftLon, rightLon);
}
//System.err.println(" rectangle");
- return new GeoRectangle(topLat, bottomLat, leftLon, rightLon);
+ return new GeoRectangle(planetModel, topLat, bottomLat, leftLon, rightLon);
}
}
Copied: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseBBox.java (from r1681906, lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxBase.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseBBox.java?p2=lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseBBox.java&p1=lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxBase.java&r1=1681906&r2=1681907&rev=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxBase.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseBBox.java Wed May 27 04:54:50 2015
@@ -23,11 +23,12 @@ package org.apache.lucene.spatial.spatia
*
* @lucene.internal
*/
-public abstract class GeoBBoxBase implements GeoBBox {
-
- protected final static GeoPoint NORTH_POLE = new GeoPoint(0.0, 0.0, 1.0);
- protected final static GeoPoint SOUTH_POLE = new GeoPoint(0.0, 0.0, -1.0);
+public abstract class GeoBaseBBox extends GeoBaseShape implements GeoBBox {
+ public GeoBaseBBox(final PlanetModel planetModel) {
+ super(planetModel);
+ }
+
@Override
public abstract boolean isWithin(final Vector point);
@@ -45,6 +46,9 @@ public abstract class GeoBBoxBase implem
} else {
foundOutside = true;
}
+ if (foundInside && foundOutside) {
+ return SOME_INSIDE;
+ }
}
if (!foundInside && !foundOutside)
return NONE_INSIDE;
@@ -54,5 +58,15 @@ public abstract class GeoBBoxBase implem
return NONE_INSIDE;
return SOME_INSIDE;
}
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ return super.equals(o);
+ }
}
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseExtendedShape.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseExtendedShape.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseExtendedShape.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseExtendedShape.java Wed May 27 04:54:50 2015
@@ -22,11 +22,10 @@ package org.apache.lucene.spatial.spatia
*
* @lucene.internal
*/
-public abstract class GeoBaseExtendedShape implements GeoShape {
- protected final static GeoPoint NORTH_POLE = new GeoPoint(0.0, 0.0, 1.0);
- protected final static GeoPoint SOUTH_POLE = new GeoPoint(0.0, 0.0, -1.0);
+public abstract class GeoBaseExtendedShape extends GeoBaseShape implements GeoShape {
- public GeoBaseExtendedShape() {
+ public GeoBaseExtendedShape(final PlanetModel planetModel) {
+ super(planetModel);
}
/**
@@ -83,12 +82,22 @@ public abstract class GeoBaseExtendedSha
public Bounds getBounds(Bounds bounds) {
if (bounds == null)
bounds = new Bounds();
- if (isWithin(NORTH_POLE)) {
+ if (isWithin(planetModel.NORTH_POLE)) {
bounds.noTopLatitudeBound().noLongitudeBound();
}
- if (isWithin(SOUTH_POLE)) {
+ if (isWithin(planetModel.SOUTH_POLE)) {
bounds.noBottomLatitudeBound().noLongitudeBound();
}
return bounds;
}
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ return super.equals(o);
+ }
}
Added: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseShape.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseShape.java?rev=1681907&view=auto
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseShape.java (added)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseShape.java Wed May 27 04:54:50 2015
@@ -0,0 +1,47 @@
+package org.apache.lucene.spatial.spatial4j.geo3d;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * All bounding box shapes can derive from this base class, which furnishes
+ * some common code
+ *
+ * @lucene.internal
+ */
+public abstract class GeoBaseShape {
+
+ protected final PlanetModel planetModel;
+
+ public GeoBaseShape(final PlanetModel planetModel) {
+ this.planetModel = planetModel;
+ }
+
+ @Override
+ public int hashCode() {
+ return planetModel.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (!(o instanceof GeoBaseShape))
+ return false;
+ return planetModel.equals(((GeoBaseShape)o).planetModel);
+ }
+}
+
+
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java Wed May 27 04:54:50 2015
@@ -25,45 +25,42 @@ package org.apache.lucene.spatial.spatia
public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape, GeoSizeable {
public final GeoPoint center;
public final double cutoffAngle;
- public final double cutoffNormalDistance;
- public final double cutoffLinearDistance;
public final SidedPlane circlePlane;
public final GeoPoint[] edgePoints;
public static final GeoPoint[] circlePoints = new GeoPoint[0];
- public GeoCircle(final double lat, final double lon, final double cutoffAngle) {
- super();
+ public GeoCircle(final PlanetModel planetModel, final double lat, final double lon, final double cutoffAngle) {
+ super(planetModel);
if (lat < -Math.PI * 0.5 || lat > Math.PI * 0.5)
throw new IllegalArgumentException("Latitude out of bounds");
if (lon < -Math.PI || lon > Math.PI)
throw new IllegalArgumentException("Longitude out of bounds");
if (cutoffAngle <= 0.0 || cutoffAngle > Math.PI)
throw new IllegalArgumentException("Cutoff angle out of bounds");
- final double sinAngle = Math.sin(cutoffAngle);
final double cosAngle = Math.cos(cutoffAngle);
- this.center = new GeoPoint(lat, lon);
- this.cutoffNormalDistance = sinAngle;
- // Need the chord distance. This is just the chord distance: sqrt((1 - cos(angle))^2 + (sin(angle))^2).
- final double xDiff = 1.0 - cosAngle;
- this.cutoffLinearDistance = Math.sqrt(xDiff * xDiff + sinAngle * sinAngle);
+ this.center = new GeoPoint(planetModel, lat, lon);
+ final double magnitude = center.magnitude();
+ // In an ellipsoidal world, cutoff distances make no sense, unfortunately. Only membership
+ // can be used to make in/out determination.
this.cutoffAngle = cutoffAngle;
- this.circlePlane = new SidedPlane(center, center, -cosAngle);
+ // The plane's normal vector needs to be normalized, since we compute D on that basis
+ this.circlePlane = new SidedPlane(center, center.normalize(), -cosAngle * magnitude);
// Compute a point on the circle boundary.
if (cutoffAngle == Math.PI)
this.edgePoints = new GeoPoint[0];
else {
- // Move from center only in latitude. Then, if we go past the north pole, adjust the longitude also.
- double newLat = lat + cutoffAngle;
- double newLon = lon;
- if (newLat > Math.PI * 0.5) {
- newLat = Math.PI - newLat;
- newLon += Math.PI;
+ // We already have circle plane, which is the definitive determination of the edge of the "circle".
+ // Next, compute vertical plane going through origin and the center point (C = 0, D = 0).
+ Plane verticalPlane = Plane.constructNormalizedVerticalPlane(this.center.x, this.center.y);
+ if (verticalPlane == null) {
+ verticalPlane = new Plane(1.0,0.0);
}
- while (newLon > Math.PI) {
- newLon -= Math.PI * 2.0;
+ // Finally, use Plane.findIntersections() to find the intersection points.
+ final GeoPoint edgePoint = this.circlePlane.getSampleIntersectionPoint(planetModel, verticalPlane);
+ if (edgePoint == null) {
+ throw new RuntimeException("Could not find edge point for circle at lat="+lat+" lon="+lon+" cutoffAngle="+cutoffAngle+" planetModel="+planetModel);
}
- final GeoPoint edgePoint = new GeoPoint(newLat, newLon);
//if (Math.abs(circlePlane.evaluate(edgePoint)) > 1e-10)
// throw new RuntimeException("Computed an edge point that does not satisfy circlePlane equation! "+circlePlane.evaluate(edgePoint));
this.edgePoints = new GeoPoint[]{edgePoint};
@@ -92,10 +89,9 @@ public class GeoCircle extends GeoBaseEx
*/
@Override
public double computeNormalDistance(final GeoPoint point) {
- double normalDistance = this.center.normalDistance(point);
- if (normalDistance > cutoffNormalDistance)
+ if (!isWithin(point))
return Double.MAX_VALUE;
- return normalDistance;
+ return this.center.normalDistance(point);
}
/**
@@ -105,10 +101,9 @@ public class GeoCircle extends GeoBaseEx
*/
@Override
public double computeNormalDistance(final double x, final double y, final double z) {
- double normalDistance = this.center.normalDistance(x, y, z);
- if (normalDistance > cutoffNormalDistance)
+ if (!isWithin(x,y,z))
return Double.MAX_VALUE;
- return normalDistance;
+ return this.center.normalDistance(x, y, z);
}
/**
@@ -118,10 +113,9 @@ public class GeoCircle extends GeoBaseEx
*/
@Override
public double computeSquaredNormalDistance(final GeoPoint point) {
- double normalDistanceSquared = this.center.normalDistanceSquared(point);
- if (normalDistanceSquared > cutoffNormalDistance * cutoffNormalDistance)
+ if (!isWithin(point))
return Double.MAX_VALUE;
- return normalDistanceSquared;
+ return this.center.normalDistanceSquared(point);
}
/**
@@ -131,10 +125,9 @@ public class GeoCircle extends GeoBaseEx
*/
@Override
public double computeSquaredNormalDistance(final double x, final double y, final double z) {
- double normalDistanceSquared = this.center.normalDistanceSquared(x, y, z);
- if (normalDistanceSquared > cutoffNormalDistance * cutoffNormalDistance)
+ if (!isWithin(x,y,z))
return Double.MAX_VALUE;
- return normalDistanceSquared;
+ return this.center.normalDistanceSquared(x, y, z);
}
/**
@@ -143,10 +136,9 @@ public class GeoCircle extends GeoBaseEx
*/
@Override
public double computeLinearDistance(final GeoPoint point) {
- double linearDistance = this.center.linearDistance(point);
- if (linearDistance > cutoffLinearDistance)
+ if (!isWithin(point))
return Double.MAX_VALUE;
- return linearDistance;
+ return this.center.linearDistance(point);
}
/**
@@ -155,10 +147,9 @@ public class GeoCircle extends GeoBaseEx
*/
@Override
public double computeLinearDistance(final double x, final double y, final double z) {
- double linearDistance = this.center.linearDistance(x, y, z);
- if (linearDistance > cutoffLinearDistance)
+ if (!isWithin(x,y,z))
return Double.MAX_VALUE;
- return linearDistance;
+ return this.center.linearDistance(x, y, z);
}
/**
@@ -166,10 +157,9 @@ public class GeoCircle extends GeoBaseEx
*/
@Override
public double computeSquaredLinearDistance(final GeoPoint point) {
- double linearDistanceSquared = this.center.linearDistanceSquared(point);
- if (linearDistanceSquared > cutoffLinearDistance * cutoffLinearDistance)
+ if (!isWithin(point))
return Double.MAX_VALUE;
- return linearDistanceSquared;
+ return this.center.linearDistanceSquared(point);
}
/**
@@ -177,10 +167,9 @@ public class GeoCircle extends GeoBaseEx
*/
@Override
public double computeSquaredLinearDistance(final double x, final double y, final double z) {
- double linearDistanceSquared = this.center.linearDistanceSquared(x, y, z);
- if (linearDistanceSquared > cutoffLinearDistance * cutoffLinearDistance)
+ if (!isWithin(x,y,z))
return Double.MAX_VALUE;
- return linearDistanceSquared;
+ return this.center.linearDistanceSquared(x, y, z);
}
/**
@@ -189,10 +178,9 @@ public class GeoCircle extends GeoBaseEx
*/
@Override
public double computeArcDistance(final GeoPoint point) {
- double dist = this.center.arcDistance(point);
- if (dist > cutoffAngle)
+ if (!isWithin(point))
return Double.MAX_VALUE;
- return dist;
+ return this.center.arcDistance(point);
}
@Override
@@ -214,7 +202,7 @@ public class GeoCircle extends GeoBaseEx
@Override
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
- return circlePlane.intersects(p, notablePoints, circlePoints, bounds);
+ return circlePlane.intersects(planetModel, p, notablePoints, circlePoints, bounds);
}
/**
@@ -230,7 +218,7 @@ public class GeoCircle extends GeoBaseEx
public Bounds getBounds(Bounds bounds) {
bounds = super.getBounds(bounds);
bounds.addPoint(center);
- circlePlane.recordBounds(bounds);
+ circlePlane.recordBounds(planetModel, bounds);
return bounds;
}
@@ -239,21 +227,20 @@ public class GeoCircle extends GeoBaseEx
if (!(o instanceof GeoCircle))
return false;
GeoCircle other = (GeoCircle) o;
- return other.center.equals(center) && other.cutoffAngle == cutoffAngle;
+ return super.equals(other) && other.center.equals(center) && other.cutoffAngle == cutoffAngle;
}
@Override
public int hashCode() {
- int result;
- long temp;
- result = center.hashCode();
- temp = Double.doubleToLongBits(cutoffAngle);
+ int result = super.hashCode();
+ result = 31 * result + center.hashCode();
+ long temp = Double.doubleToLongBits(cutoffAngle);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public String toString() {
- return "GeoCircle: {center=" + center + ", radius=" + cutoffAngle + "(" + cutoffAngle * 180.0 / Math.PI + ")}";
+ return "GeoCircle: {planetmodel=" + planetModel+", center=" + center + ", radius=" + cutoffAngle + "(" + cutoffAngle * 180.0 / Math.PI + ")}";
}
}
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoConvexPolygon.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoConvexPolygon.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoConvexPolygon.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoConvexPolygon.java Wed May 27 04:54:50 2015
@@ -45,7 +45,8 @@ public class GeoConvexPolygon extends Ge
* Create a convex polygon from a list of points. The first point must be on the
* external edge.
*/
- public GeoConvexPolygon(final List<GeoPoint> pointList) {
+ public GeoConvexPolygon(final PlanetModel planetModel, final List<GeoPoint> pointList) {
+ super(planetModel);
this.points = pointList;
this.isInternalEdges = null;
donePoints(false);
@@ -55,7 +56,8 @@ public class GeoConvexPolygon extends Ge
* Create a convex polygon from a list of points, keeping track of which boundaries
* are internal. This is used when creating a polygon as a building block for another shape.
*/
- public GeoConvexPolygon(final List<GeoPoint> pointList, final BitSet internalEdgeFlags, final boolean returnEdgeInternal) {
+ public GeoConvexPolygon(final PlanetModel planetModel, final List<GeoPoint> pointList, final BitSet internalEdgeFlags, final boolean returnEdgeInternal) {
+ super(planetModel);
this.points = pointList;
this.isInternalEdges = internalEdgeFlags;
donePoints(returnEdgeInternal);
@@ -65,7 +67,8 @@ public class GeoConvexPolygon extends Ge
* Create a convex polygon, with a starting latitude and longitude.
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}
*/
- public GeoConvexPolygon(final double startLatitude, final double startLongitude) {
+ public GeoConvexPolygon(final PlanetModel planetModel, final double startLatitude, final double startLongitude) {
+ super(planetModel);
points = new ArrayList<GeoPoint>();
isInternalEdges = new BitSet();
// Argument checking
@@ -74,7 +77,7 @@ public class GeoConvexPolygon extends Ge
if (startLongitude < -Math.PI || startLongitude > Math.PI)
throw new IllegalArgumentException("Longitude out of range");
- final GeoPoint p = new GeoPoint(startLatitude, startLongitude);
+ final GeoPoint p = new GeoPoint(planetModel, startLatitude, startLongitude);
points.add(p);
}
@@ -94,7 +97,7 @@ public class GeoConvexPolygon extends Ge
if (longitude < -Math.PI || longitude > Math.PI)
throw new IllegalArgumentException("Longitude out of range");
- final GeoPoint p = new GeoPoint(latitude, longitude);
+ final GeoPoint p = new GeoPoint(planetModel, latitude, longitude);
isInternalEdges.set(points.size(), isInternalEdge);
points.add(p);
}
@@ -191,7 +194,7 @@ public class GeoConvexPolygon extends Ge
membershipBounds[count++] = edges[otherIndex];
}
}
- if (edge.intersects(p, notablePoints, points, bounds, membershipBounds)) {
+ if (edge.intersects(planetModel, p, notablePoints, points, bounds, membershipBounds)) {
//System.err.println(" intersects!");
return true;
}
@@ -230,7 +233,7 @@ public class GeoConvexPolygon extends Ge
membershipBounds[count++] = edges[otherIndex];
}
}
- edge.recordBounds(bounds, membershipBounds);
+ edge.recordBounds(planetModel, bounds, membershipBounds);
}
if (fullDistance >= Math.PI) {
@@ -245,6 +248,8 @@ public class GeoConvexPolygon extends Ge
if (!(o instanceof GeoConvexPolygon))
return false;
GeoConvexPolygon other = (GeoConvexPolygon) o;
+ if (!super.equals(other))
+ return false;
if (other.points.size() != points.size())
return false;
@@ -257,17 +262,14 @@ public class GeoConvexPolygon extends Ge
@Override
public int hashCode() {
- return points.hashCode();
+ int result = super.hashCode();
+ result = 31 * result + points.hashCode();
+ return result;
}
@Override
public String toString() {
- StringBuilder edgeString = new StringBuilder("{");
- for (int i = 0; i < edges.length; i++) {
- edgeString.append(edges[i]).append(" internal? ").append(internalEdges[i]).append("; ");
- }
- edgeString.append("}");
- return "GeoConvexPolygon: {points=" + points + " edges=" + edgeString + "}";
+ return "GeoConvexPolygon: {planetmodel=" + planetModel + ", points=" + points + "}";
}
}
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateHorizontalLine.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateHorizontalLine.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateHorizontalLine.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateHorizontalLine.java Wed May 27 04:54:50 2015
@@ -24,7 +24,7 @@ package org.apache.lucene.spatial.spatia
*
* @lucene.internal
*/
-public class GeoDegenerateHorizontalLine extends GeoBBoxBase {
+public class GeoDegenerateHorizontalLine extends GeoBaseBBox {
public final double latitude;
public final double leftLon;
public final double rightLon;
@@ -44,7 +44,8 @@ public class GeoDegenerateHorizontalLine
/**
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}
*/
- public GeoDegenerateHorizontalLine(final double latitude, final double leftLon, double rightLon) {
+ public GeoDegenerateHorizontalLine(final PlanetModel planetModel, final double latitude, final double leftLon, double rightLon) {
+ super(planetModel);
// Argument checking
if (latitude > Math.PI * 0.5 || latitude < -Math.PI * 0.5)
throw new IllegalArgumentException("Latitude out of range");
@@ -71,10 +72,10 @@ public class GeoDegenerateHorizontalLine
final double cosRightLon = Math.cos(rightLon);
// Now build the two points
- this.LHC = new GeoPoint(sinLatitude, sinLeftLon, cosLatitude, cosLeftLon);
- this.RHC = new GeoPoint(sinLatitude, sinRightLon, cosLatitude, cosRightLon);
+ this.LHC = new GeoPoint(planetModel, sinLatitude, sinLeftLon, cosLatitude, cosLeftLon);
+ this.RHC = new GeoPoint(planetModel, sinLatitude, sinRightLon, cosLatitude, cosRightLon);
- this.plane = new Plane(sinLatitude);
+ this.plane = new Plane(planetModel, sinLatitude);
// Normalize
while (leftLon > rightLon) {
@@ -84,7 +85,7 @@ public class GeoDegenerateHorizontalLine
final double sinMiddleLon = Math.sin(middleLon);
final double cosMiddleLon = Math.cos(middleLon);
- this.centerPoint = new GeoPoint(sinLatitude, sinMiddleLon, cosLatitude, cosMiddleLon);
+ this.centerPoint = new GeoPoint(planetModel, sinLatitude, sinMiddleLon, cosLatitude, cosMiddleLon);
this.leftPlane = new SidedPlane(centerPoint, cosLeftLon, sinLeftLon);
this.rightPlane = new SidedPlane(centerPoint, cosRightLon, sinRightLon);
@@ -107,7 +108,7 @@ public class GeoDegenerateHorizontalLine
newLeftLon = -Math.PI;
newRightLon = Math.PI;
}
- return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, newLeftLon, newRightLon);
+ return GeoBBoxFactory.makeGeoBBox(planetModel, newTopLat, newBottomLat, newLeftLon, newRightLon);
}
@Override
@@ -148,7 +149,7 @@ public class GeoDegenerateHorizontalLine
@Override
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
- return p.intersects(plane, notablePoints, planePoints, bounds, leftPlane, rightPlane);
+ return p.intersects(planetModel, plane, notablePoints, planePoints, bounds, leftPlane, rightPlane);
}
/**
@@ -170,12 +171,18 @@ public class GeoDegenerateHorizontalLine
@Override
public int getRelationship(final GeoShape path) {
- if (path.intersects(plane, planePoints, leftPlane, rightPlane))
+ //System.err.println("getting relationship between "+this+" and "+path);
+ if (path.intersects(plane, planePoints, leftPlane, rightPlane)) {
+ //System.err.println(" overlaps");
return OVERLAPS;
+ }
- if (path.isWithin(centerPoint))
+ if (path.isWithin(centerPoint)) {
+ //System.err.println(" contains");
return CONTAINS;
+ }
+ //System.err.println(" disjoint");
return DISJOINT;
}
@@ -184,19 +191,20 @@ public class GeoDegenerateHorizontalLine
if (!(o instanceof GeoDegenerateHorizontalLine))
return false;
GeoDegenerateHorizontalLine other = (GeoDegenerateHorizontalLine) o;
- return other.LHC.equals(LHC) && other.RHC.equals(RHC);
+ return super.equals(other) && other.LHC.equals(LHC) && other.RHC.equals(RHC);
}
@Override
public int hashCode() {
- int result = LHC.hashCode();
+ int result = super.hashCode();
+ result = 31 * result + LHC.hashCode();
result = 31 * result + RHC.hashCode();
return result;
}
@Override
public String toString() {
- return "GeoDegenerateHorizontalLine: {latitude=" + latitude + "(" + latitude * 180.0 / Math.PI + "), leftlon=" + leftLon + "(" + leftLon * 180.0 / Math.PI + "), rightLon=" + rightLon + "(" + rightLon * 180.0 / Math.PI + ")}";
+ return "GeoDegenerateHorizontalLine: {planetmodel="+planetModel+", latitude=" + latitude + "(" + latitude * 180.0 / Math.PI + "), leftlon=" + leftLon + "(" + leftLon * 180.0 / Math.PI + "), rightLon=" + rightLon + "(" + rightLon * 180.0 / Math.PI + ")}";
}
}
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateLatitudeZone.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateLatitudeZone.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateLatitudeZone.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateLatitudeZone.java Wed May 27 04:54:50 2015
@@ -23,7 +23,7 @@ package org.apache.lucene.spatial.spatia
*
* @lucene.internal
*/
-public class GeoDegenerateLatitudeZone extends GeoBBoxBase {
+public class GeoDegenerateLatitudeZone extends GeoBaseBBox {
public final double latitude;
public final double sinLatitude;
@@ -32,14 +32,15 @@ public class GeoDegenerateLatitudeZone e
public final GeoPoint[] edgePoints;
public final static GeoPoint[] planePoints = new GeoPoint[0];
- public GeoDegenerateLatitudeZone(final double latitude) {
+ public GeoDegenerateLatitudeZone(final PlanetModel planetModel, final double latitude) {
+ super(planetModel);
this.latitude = latitude;
this.sinLatitude = Math.sin(latitude);
double cosLatitude = Math.cos(latitude);
- this.plane = new Plane(sinLatitude);
+ this.plane = new Plane(planetModel, sinLatitude);
// Compute an interior point.
- interiorPoint = new GeoPoint(cosLatitude, 0.0, sinLatitude);
+ interiorPoint = new GeoPoint(planetModel, sinLatitude, 0.0, cosLatitude, 1.0);
edgePoints = new GeoPoint[]{interiorPoint};
}
@@ -47,7 +48,7 @@ public class GeoDegenerateLatitudeZone e
public GeoBBox expand(final double angle) {
double newTopLat = latitude + angle;
double newBottomLat = latitude - angle;
- return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, -Math.PI, Math.PI);
+ return GeoBBoxFactory.makeGeoBBox(planetModel, newTopLat, newBottomLat, -Math.PI, Math.PI);
}
@Override
@@ -83,7 +84,7 @@ public class GeoDegenerateLatitudeZone e
@Override
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
- return p.intersects(plane, notablePoints, planePoints, bounds);
+ return p.intersects(planetModel, plane, notablePoints, planePoints, bounds);
}
/**
@@ -125,19 +126,20 @@ public class GeoDegenerateLatitudeZone e
if (!(o instanceof GeoDegenerateLatitudeZone))
return false;
GeoDegenerateLatitudeZone other = (GeoDegenerateLatitudeZone) o;
- return other.latitude == latitude;
+ return super.equals(other) && other.latitude == latitude;
}
@Override
public int hashCode() {
+ int result = super.hashCode();
long temp = Double.doubleToLongBits(latitude);
- int result = (int) (temp ^ (temp >>> 32));
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public String toString() {
- return "GeoDegenerateLatitudeZone: {lat=" + latitude + "(" + latitude * 180.0 / Math.PI + ")}";
+ return "GeoDegenerateLatitudeZone: {planetmodel="+planetModel+", lat=" + latitude + "(" + latitude * 180.0 / Math.PI + ")}";
}
}
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateLongitudeSlice.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateLongitudeSlice.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateLongitudeSlice.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateLongitudeSlice.java Wed May 27 04:54:50 2015
@@ -22,7 +22,7 @@ package org.apache.lucene.spatial.spatia
*
* @lucene.internal
*/
-public class GeoDegenerateLongitudeSlice extends GeoBBoxBase {
+public class GeoDegenerateLongitudeSlice extends GeoBaseBBox {
public final double longitude;
public final double sinLongitude;
@@ -32,12 +32,13 @@ public class GeoDegenerateLongitudeSlice
public final GeoPoint interiorPoint;
public final GeoPoint[] edgePoints;
- public final static GeoPoint[] planePoints = new GeoPoint[]{NORTH_POLE, SOUTH_POLE};
+ public final GeoPoint[] planePoints;
/**
* Accepts only values in the following ranges: lon: {@code -PI -> PI}
*/
- public GeoDegenerateLongitudeSlice(final double longitude) {
+ public GeoDegenerateLongitudeSlice(final PlanetModel planetModel, final double longitude) {
+ super(planetModel);
// Argument checking
if (longitude < -Math.PI || longitude > Math.PI)
throw new IllegalArgumentException("Longitude out of range");
@@ -48,9 +49,10 @@ public class GeoDegenerateLongitudeSlice
this.plane = new Plane(cosLongitude, sinLongitude);
// We need a bounding plane too, which is perpendicular to the longitude plane and sided so that the point (0.0, longitude) is inside.
- this.interiorPoint = new GeoPoint(cosLongitude, sinLongitude, 0.0);
+ this.interiorPoint = new GeoPoint(planetModel, 0.0, sinLongitude, 1.0, cosLongitude);
this.boundingPlane = new SidedPlane(interiorPoint, -sinLongitude, cosLongitude);
this.edgePoints = new GeoPoint[]{interiorPoint};
+ this.planePoints = new GeoPoint[]{planetModel.NORTH_POLE, planetModel.SOUTH_POLE};
}
@Override
@@ -63,7 +65,7 @@ public class GeoDegenerateLongitudeSlice
newLeftLon = -Math.PI;
newRightLon = Math.PI;
}
- return GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, newLeftLon, newRightLon);
+ return GeoBBoxFactory.makeGeoBBox(planetModel, Math.PI * 0.5, -Math.PI * 0.5, newLeftLon, newRightLon);
}
@Override
@@ -100,7 +102,7 @@ public class GeoDegenerateLongitudeSlice
@Override
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
- return p.intersects(plane, notablePoints, planePoints, bounds, boundingPlane);
+ return p.intersects(planetModel, plane, notablePoints, planePoints, bounds, boundingPlane);
}
/**
@@ -138,21 +140,20 @@ public class GeoDegenerateLongitudeSlice
if (!(o instanceof GeoDegenerateLongitudeSlice))
return false;
GeoDegenerateLongitudeSlice other = (GeoDegenerateLongitudeSlice) o;
- return other.longitude == longitude;
+ return super.equals(other) && other.longitude == longitude;
}
@Override
public int hashCode() {
- int result;
- long temp;
- temp = Double.doubleToLongBits(longitude);
- result = (int) (temp ^ (temp >>> 32));
+ int result = super.hashCode();
+ long temp = Double.doubleToLongBits(longitude);
+ result = result * 31 + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public String toString() {
- return "GeoDegenerateLongitudeSlice: {longitude=" + longitude + "(" + longitude * 180.0 / Math.PI + ")}";
+ return "GeoDegenerateLongitudeSlice: {planetmodel="+planetModel+", longitude=" + longitude + "(" + longitude * 180.0 / Math.PI + ")}";
}
}
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegeneratePoint.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegeneratePoint.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegeneratePoint.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegeneratePoint.java Wed May 27 04:54:50 2015
@@ -26,10 +26,12 @@ package org.apache.lucene.spatial.spatia
public class GeoDegeneratePoint extends GeoPoint implements GeoBBox {
public final double latitude;
public final double longitude;
+ public final PlanetModel planetModel;
public final GeoPoint[] edgePoints;
- public GeoDegeneratePoint(final double lat, final double lon) {
- super(lat, lon);
+ public GeoDegeneratePoint(final PlanetModel planetModel, final double lat, final double lon) {
+ super(planetModel, lat, lon);
+ this.planetModel = planetModel;
this.latitude = lat;
this.longitude = lon;
this.edgePoints = new GeoPoint[]{this};
@@ -47,7 +49,7 @@ public class GeoDegeneratePoint extends
final double newBottomLat = latitude - angle;
final double newLeftLon = longitude - angle;
final double newRightLon = longitude + angle;
- return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, newLeftLon, newRightLon);
+ return GeoBBoxFactory.makeGeoBBox(planetModel, newTopLat, newBottomLat, newLeftLon, newRightLon);
}
/**
@@ -108,15 +110,14 @@ public class GeoDegeneratePoint extends
if (!(o instanceof GeoDegeneratePoint))
return false;
GeoDegeneratePoint other = (GeoDegeneratePoint) o;
- return other.latitude == latitude && other.longitude == longitude;
+ return super.equals(other) && other.latitude == latitude && other.longitude == longitude;
}
@Override
public int hashCode() {
- int result;
- long temp;
- temp = Double.doubleToLongBits(latitude);
- result = (int) (temp ^ (temp >>> 32));
+ int result = super.hashCode();
+ long temp = Double.doubleToLongBits(latitude);
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(longitude);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
@@ -124,7 +125,7 @@ public class GeoDegeneratePoint extends
@Override
public String toString() {
- return "GeoDegeneratePoint: {lat=" + latitude + "(" + latitude * 180.0 / Math.PI + "), lon=" + longitude + "(" + longitude * 180.0 / Math.PI + ")}";
+ return "GeoDegeneratePoint: {planetmodel="+planetModel+", lat=" + latitude + "(" + latitude * 180.0 / Math.PI + "), lon=" + longitude + "(" + longitude * 180.0 / Math.PI + ")}";
}
/**
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateVerticalLine.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateVerticalLine.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateVerticalLine.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateVerticalLine.java Wed May 27 04:54:50 2015
@@ -22,7 +22,7 @@ package org.apache.lucene.spatial.spatia
*
* @lucene.internal
*/
-public class GeoDegenerateVerticalLine extends GeoBBoxBase {
+public class GeoDegenerateVerticalLine extends GeoBaseBBox {
public final double topLat;
public final double bottomLat;
public final double longitude;
@@ -43,7 +43,8 @@ public class GeoDegenerateVerticalLine e
/**
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, longitude: {@code -PI -> PI}
*/
- public GeoDegenerateVerticalLine(final double topLat, final double bottomLat, final double longitude) {
+ public GeoDegenerateVerticalLine(final PlanetModel planetModel, final double topLat, final double bottomLat, final double longitude) {
+ super(planetModel);
// Argument checking
if (topLat > Math.PI * 0.5 || topLat < -Math.PI * 0.5)
throw new IllegalArgumentException("Top latitude out of range");
@@ -66,8 +67,8 @@ public class GeoDegenerateVerticalLine e
final double cosLongitude = Math.cos(longitude);
// Now build the two points
- this.UHC = new GeoPoint(sinTopLat, sinLongitude, cosTopLat, cosLongitude);
- this.LHC = new GeoPoint(sinBottomLat, sinLongitude, cosBottomLat, cosLongitude);
+ this.UHC = new GeoPoint(planetModel, sinTopLat, sinLongitude, cosTopLat, cosLongitude);
+ this.LHC = new GeoPoint(planetModel, sinBottomLat, sinLongitude, cosBottomLat, cosLongitude);
this.plane = new Plane(cosLongitude, sinLongitude);
@@ -75,10 +76,10 @@ public class GeoDegenerateVerticalLine e
final double sinMiddleLat = Math.sin(middleLat);
final double cosMiddleLat = Math.cos(middleLat);
- this.centerPoint = new GeoPoint(sinMiddleLat, sinLongitude, cosMiddleLat, cosLongitude);
+ this.centerPoint = new GeoPoint(planetModel, sinMiddleLat, sinLongitude, cosMiddleLat, cosLongitude);
- this.topPlane = new SidedPlane(centerPoint, sinTopLat);
- this.bottomPlane = new SidedPlane(centerPoint, sinBottomLat);
+ this.topPlane = new SidedPlane(centerPoint, planetModel, sinTopLat);
+ this.bottomPlane = new SidedPlane(centerPoint, planetModel, sinBottomLat);
this.boundingPlane = new SidedPlane(centerPoint, -sinLongitude, cosLongitude);
@@ -98,7 +99,7 @@ public class GeoDegenerateVerticalLine e
newLeftLon = -Math.PI;
newRightLon = Math.PI;
}
- return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, newLeftLon, newRightLon);
+ return GeoBBoxFactory.makeGeoBBox(planetModel, newTopLat, newBottomLat, newLeftLon, newRightLon);
}
@Override
@@ -144,7 +145,7 @@ public class GeoDegenerateVerticalLine e
@Override
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
- return p.intersects(plane, notablePoints, planePoints, bounds, boundingPlane, topPlane, bottomPlane);
+ return p.intersects(planetModel, plane, notablePoints, planePoints, bounds, boundingPlane, topPlane, bottomPlane);
}
/**
@@ -187,12 +188,13 @@ public class GeoDegenerateVerticalLine e
if (!(o instanceof GeoDegenerateVerticalLine))
return false;
GeoDegenerateVerticalLine other = (GeoDegenerateVerticalLine) o;
- return other.UHC.equals(UHC) && other.LHC.equals(LHC);
+ return super.equals(other) && other.UHC.equals(UHC) && other.LHC.equals(LHC);
}
@Override
public int hashCode() {
- int result = UHC.hashCode();
+ int result = super.hashCode();
+ result = 31 * result + UHC.hashCode();
result = 31 * result + LHC.hashCode();
return result;
}
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoLatitudeZone.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoLatitudeZone.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoLatitudeZone.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoLatitudeZone.java Wed May 27 04:54:50 2015
@@ -22,7 +22,7 @@ package org.apache.lucene.spatial.spatia
*
* @lucene.internal
*/
-public class GeoLatitudeZone extends GeoBBoxBase {
+public class GeoLatitudeZone extends GeoBaseBBox {
public final double topLat;
public final double bottomLat;
public final double cosTopLat;
@@ -40,7 +40,8 @@ public class GeoLatitudeZone extends Geo
// Edge points
public final GeoPoint[] edgePoints;
- public GeoLatitudeZone(final double topLat, final double bottomLat) {
+ public GeoLatitudeZone(final PlanetModel planetModel, final double topLat, final double bottomLat) {
+ super(planetModel);
this.topLat = topLat;
this.bottomLat = bottomLat;
@@ -49,19 +50,15 @@ public class GeoLatitudeZone extends Geo
this.cosTopLat = Math.cos(topLat);
this.cosBottomLat = Math.cos(bottomLat);
- // Construct sample points, so we get our sidedness right
- final Vector topPoint = new Vector(0.0, 0.0, sinTopLat);
- final Vector bottomPoint = new Vector(0.0, 0.0, sinBottomLat);
-
// Compute an interior point. Pick one whose lat is between top and bottom.
final double middleLat = (topLat + bottomLat) * 0.5;
final double sinMiddleLat = Math.sin(middleLat);
- this.interiorPoint = new GeoPoint(Math.sqrt(1.0 - sinMiddleLat * sinMiddleLat), 0.0, sinMiddleLat);
- this.topBoundaryPoint = new GeoPoint(Math.sqrt(1.0 - sinTopLat * sinTopLat), 0.0, sinTopLat);
- this.bottomBoundaryPoint = new GeoPoint(Math.sqrt(1.0 - sinBottomLat * sinBottomLat), 0.0, sinBottomLat);
+ this.interiorPoint = new GeoPoint(planetModel, sinMiddleLat, 0.0, Math.sqrt(1.0 - sinMiddleLat * sinMiddleLat), 1.0);
+ this.topBoundaryPoint = new GeoPoint(planetModel, sinTopLat, 0.0, Math.sqrt(1.0 - sinTopLat * sinTopLat), 1.0);
+ this.bottomBoundaryPoint = new GeoPoint(planetModel, sinBottomLat, 0.0, Math.sqrt(1.0 - sinBottomLat * sinBottomLat), 1.0);
- this.topPlane = new SidedPlane(interiorPoint, sinTopLat);
- this.bottomPlane = new SidedPlane(interiorPoint, sinBottomLat);
+ this.topPlane = new SidedPlane(interiorPoint, planetModel, sinTopLat);
+ this.bottomPlane = new SidedPlane(interiorPoint, planetModel, sinBottomLat);
this.edgePoints = new GeoPoint[]{topBoundaryPoint, bottomBoundaryPoint};
}
@@ -70,7 +67,7 @@ public class GeoLatitudeZone extends Geo
public GeoBBox expand(final double angle) {
final double newTopLat = topLat + angle;
final double newBottomLat = bottomLat - angle;
- return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, -Math.PI, Math.PI);
+ return GeoBBoxFactory.makeGeoBBox(planetModel, newTopLat, newBottomLat, -Math.PI, Math.PI);
}
@Override
@@ -115,8 +112,8 @@ public class GeoLatitudeZone extends Geo
@Override
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
- return p.intersects(topPlane, notablePoints, planePoints, bounds, bottomPlane) ||
- p.intersects(bottomPlane, notablePoints, planePoints, bounds, topPlane);
+ return p.intersects(planetModel, topPlane, notablePoints, planePoints, bounds, bottomPlane) ||
+ p.intersects(planetModel, bottomPlane, notablePoints, planePoints, bounds, topPlane);
}
/**
@@ -181,18 +178,19 @@ public class GeoLatitudeZone extends Geo
if (!(o instanceof GeoLatitudeZone))
return false;
GeoLatitudeZone other = (GeoLatitudeZone) o;
- return other.topPlane.equals(topPlane) && other.bottomPlane.equals(bottomPlane);
+ return super.equals(other) && other.topBoundaryPoint.equals(topBoundaryPoint) && other.bottomBoundaryPoint.equals(bottomBoundaryPoint);
}
@Override
public int hashCode() {
- int result = topPlane.hashCode();
- result = 31 * result + bottomPlane.hashCode();
+ int result = super.hashCode();
+ result = 31 * result + topBoundaryPoint.hashCode();
+ result = 31 * result + bottomBoundaryPoint.hashCode();
return result;
}
@Override
public String toString() {
- return "GeoLatitudeZone: {toplat=" + topLat + "(" + topLat * 180.0 / Math.PI + "), bottomlat=" + bottomLat + "(" + bottomLat * 180.0 / Math.PI + ")}";
+ return "GeoLatitudeZone: {planetmodel="+planetModel+", toplat=" + topLat + "(" + topLat * 180.0 / Math.PI + "), bottomlat=" + bottomLat + "(" + bottomLat * 180.0 / Math.PI + ")}";
}
}
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoLongitudeSlice.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoLongitudeSlice.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoLongitudeSlice.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoLongitudeSlice.java Wed May 27 04:54:50 2015
@@ -24,23 +24,24 @@ package org.apache.lucene.spatial.spatia
*
* @lucene.internal
*/
-public class GeoLongitudeSlice extends GeoBBoxBase {
+public class GeoLongitudeSlice extends GeoBaseBBox {
public final double leftLon;
public final double rightLon;
public final SidedPlane leftPlane;
public final SidedPlane rightPlane;
- public final static GeoPoint[] planePoints = new GeoPoint[]{NORTH_POLE, SOUTH_POLE};
+ public final GeoPoint[] planePoints;
public final GeoPoint centerPoint;
- public final static GeoPoint[] edgePoints = new GeoPoint[]{NORTH_POLE};
+ public final GeoPoint[] edgePoints;
/**
* Accepts only values in the following ranges: lon: {@code -PI -> PI}
*/
- public GeoLongitudeSlice(final double leftLon, double rightLon) {
+ public GeoLongitudeSlice(final PlanetModel planetModel, final double leftLon, double rightLon) {
+ super(planetModel);
// Argument checking
if (leftLon < -Math.PI || leftLon > Math.PI)
throw new IllegalArgumentException("Left longitude out of range");
@@ -66,11 +67,13 @@ public class GeoLongitudeSlice extends G
rightLon += Math.PI * 2.0;
}
final double middleLon = (leftLon + rightLon) * 0.5;
- this.centerPoint = new GeoPoint(0.0, middleLon);
+ this.centerPoint = new GeoPoint(planetModel, 0.0, middleLon);
this.leftPlane = new SidedPlane(centerPoint, cosLeftLon, sinLeftLon);
this.rightPlane = new SidedPlane(centerPoint, cosRightLon, sinRightLon);
+ this.planePoints = new GeoPoint[]{planetModel.NORTH_POLE, planetModel.SOUTH_POLE};
+ this.edgePoints = new GeoPoint[]{planetModel.NORTH_POLE};
}
@Override
@@ -85,7 +88,7 @@ public class GeoLongitudeSlice extends G
newLeftLon = -Math.PI;
newRightLon = Math.PI;
}
- return GeoBBoxFactory.makeGeoBBox(Math.PI * 0.5, -Math.PI * 0.5, newLeftLon, newRightLon);
+ return GeoBBoxFactory.makeGeoBBox(planetModel, Math.PI * 0.5, -Math.PI * 0.5, newLeftLon, newRightLon);
}
@Override
@@ -126,8 +129,8 @@ public class GeoLongitudeSlice extends G
@Override
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
- return p.intersects(leftPlane, notablePoints, planePoints, bounds, rightPlane) ||
- p.intersects(rightPlane, notablePoints, planePoints, bounds, leftPlane);
+ return p.intersects(planetModel, leftPlane, notablePoints, planePoints, bounds, rightPlane) ||
+ p.intersects(planetModel, rightPlane, notablePoints, planePoints, bounds, leftPlane);
}
/**
@@ -154,7 +157,7 @@ public class GeoLongitudeSlice extends G
if (insideRectangle == SOME_INSIDE)
return OVERLAPS;
- final boolean insideShape = path.isWithin(NORTH_POLE);
+ final boolean insideShape = path.isWithin(planetModel.NORTH_POLE);
if (insideRectangle == ALL_INSIDE && insideShape)
return OVERLAPS;
@@ -180,15 +183,14 @@ public class GeoLongitudeSlice extends G
if (!(o instanceof GeoLongitudeSlice))
return false;
GeoLongitudeSlice other = (GeoLongitudeSlice) o;
- return other.leftLon == leftLon && other.rightLon == rightLon;
+ return super.equals(other) && other.leftLon == leftLon && other.rightLon == rightLon;
}
@Override
public int hashCode() {
- int result;
- long temp;
- temp = Double.doubleToLongBits(leftLon);
- result = (int) (temp ^ (temp >>> 32));
+ int result = super.hashCode();
+ long temp = Double.doubleToLongBits(leftLon);
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(rightLon);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
@@ -196,7 +198,7 @@ public class GeoLongitudeSlice extends G
@Override
public String toString() {
- return "GeoLongitudeSlice: {leftlon=" + leftLon + "(" + leftLon * 180.0 / Math.PI + "), rightlon=" + rightLon + "(" + rightLon * 180.0 / Math.PI + ")}";
+ return "GeoLongitudeSlice: {planetmodel="+planetModel+", leftlon=" + leftLon + "(" + leftLon * 180.0 / Math.PI + "), rightlon=" + rightLon + "(" + rightLon * 180.0 / Math.PI + ")}";
}
}
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoNorthLatitudeZone.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoNorthLatitudeZone.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoNorthLatitudeZone.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoNorthLatitudeZone.java Wed May 27 04:54:50 2015
@@ -22,7 +22,7 @@ package org.apache.lucene.spatial.spatia
*
* @lucene.internal
*/
-public class GeoNorthLatitudeZone extends GeoBBoxBase {
+public class GeoNorthLatitudeZone extends GeoBaseBBox {
public final double bottomLat;
public final double cosBottomLat;
public final SidedPlane bottomPlane;
@@ -34,22 +34,20 @@ public class GeoNorthLatitudeZone extend
// Edge points
public final GeoPoint[] edgePoints;
- public GeoNorthLatitudeZone(final double bottomLat) {
+ public GeoNorthLatitudeZone(final PlanetModel planetModel, final double bottomLat) {
+ super(planetModel);
this.bottomLat = bottomLat;
final double sinBottomLat = Math.sin(bottomLat);
this.cosBottomLat = Math.cos(bottomLat);
- // Construct sample points, so we get our sidedness right
- final Vector bottomPoint = new Vector(0.0, 0.0, sinBottomLat);
-
// Compute an interior point. Pick one whose lat is between top and bottom.
final double middleLat = (Math.PI * 0.5 + bottomLat) * 0.5;
final double sinMiddleLat = Math.sin(middleLat);
- this.interiorPoint = new GeoPoint(Math.sqrt(1.0 - sinMiddleLat * sinMiddleLat), 0.0, sinMiddleLat);
- this.bottomBoundaryPoint = new GeoPoint(Math.sqrt(1.0 - sinBottomLat * sinBottomLat), 0.0, sinBottomLat);
+ this.interiorPoint = new GeoPoint(planetModel, sinMiddleLat, 0.0, Math.sqrt(1.0 - sinMiddleLat * sinMiddleLat), 1.0);
+ this.bottomBoundaryPoint = new GeoPoint(planetModel, sinBottomLat, 0.0, Math.sqrt(1.0 - sinBottomLat * sinBottomLat), 1.0);
- this.bottomPlane = new SidedPlane(interiorPoint, sinBottomLat);
+ this.bottomPlane = new SidedPlane(interiorPoint, planetModel, sinBottomLat);
this.edgePoints = new GeoPoint[]{bottomBoundaryPoint};
}
@@ -58,7 +56,7 @@ public class GeoNorthLatitudeZone extend
public GeoBBox expand(final double angle) {
final double newTopLat = Math.PI * 0.5;
final double newBottomLat = bottomLat - angle;
- return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, -Math.PI, Math.PI);
+ return GeoBBoxFactory.makeGeoBBox(planetModel, newTopLat, newBottomLat, -Math.PI, Math.PI);
}
@Override
@@ -101,7 +99,7 @@ public class GeoNorthLatitudeZone extend
@Override
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
return
- p.intersects(bottomPlane, notablePoints, planePoints, bounds);
+ p.intersects(planetModel, bottomPlane, notablePoints, planePoints, bounds);
}
/**
@@ -159,18 +157,19 @@ public class GeoNorthLatitudeZone extend
if (!(o instanceof GeoNorthLatitudeZone))
return false;
GeoNorthLatitudeZone other = (GeoNorthLatitudeZone) o;
- return other.bottomPlane.equals(bottomPlane);
+ return super.equals(other) && other.bottomBoundaryPoint.equals(bottomBoundaryPoint);
}
@Override
public int hashCode() {
- int result = bottomPlane.hashCode();
+ int result = super.hashCode();
+ result = 31 * result + bottomBoundaryPoint.hashCode();
return result;
}
@Override
public String toString() {
- return "GeoNorthLatitudeZone: {bottomlat=" + bottomLat + "(" + bottomLat * 180.0 / Math.PI + ")}";
+ return "GeoNorthLatitudeZone: {planetmodel="+planetModel+", bottomlat=" + bottomLat + "(" + bottomLat * 180.0 / Math.PI + ")}";
}
}
Modified: lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoNorthRectangle.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoNorthRectangle.java?rev=1681907&r1=1681906&r2=1681907&view=diff
==============================================================================
--- lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoNorthRectangle.java (original)
+++ lucene/dev/branches/lucene6487/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoNorthRectangle.java Wed May 27 04:54:50 2015
@@ -25,7 +25,7 @@ package org.apache.lucene.spatial.spatia
*
* @lucene.internal
*/
-public class GeoNorthRectangle extends GeoBBoxBase {
+public class GeoNorthRectangle extends GeoBaseBBox {
public final double bottomLat;
public final double leftLon;
public final double rightLon;
@@ -45,12 +45,13 @@ public class GeoNorthRectangle extends G
public final GeoPoint centerPoint;
- public final GeoPoint[] edgePoints = new GeoPoint[]{NORTH_POLE};
+ public final GeoPoint[] edgePoints;
/**
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}
*/
- public GeoNorthRectangle(final double bottomLat, final double leftLon, double rightLon) {
+ public GeoNorthRectangle(final PlanetModel planetModel, final double bottomLat, final double leftLon, double rightLon) {
+ super(planetModel);
// Argument checking
if (bottomLat > Math.PI * 0.5 || bottomLat < -Math.PI * 0.5)
throw new IllegalArgumentException("Bottom latitude out of range");
@@ -77,8 +78,8 @@ public class GeoNorthRectangle extends G
final double cosRightLon = Math.cos(rightLon);
// Now build the points
- this.LRHC = new GeoPoint(sinBottomLat, sinRightLon, cosBottomLat, cosRightLon);
- this.LLHC = new GeoPoint(sinBottomLat, sinLeftLon, cosBottomLat, cosLeftLon);
+ this.LRHC = new GeoPoint(planetModel, sinBottomLat, sinRightLon, cosBottomLat, cosRightLon);
+ this.LLHC = new GeoPoint(planetModel, sinBottomLat, sinLeftLon, cosBottomLat, cosLeftLon);
final double middleLat = (Math.PI * 0.5 + bottomLat) * 0.5;
final double sinMiddleLat = Math.sin(middleLat);
@@ -91,16 +92,17 @@ public class GeoNorthRectangle extends G
final double sinMiddleLon = Math.sin(middleLon);
final double cosMiddleLon = Math.cos(middleLon);
- this.centerPoint = new GeoPoint(sinMiddleLat, sinMiddleLon, cosMiddleLat, cosMiddleLon);
+ this.centerPoint = new GeoPoint(planetModel, sinMiddleLat, sinMiddleLon, cosMiddleLat, cosMiddleLon);
- this.bottomPlane = new SidedPlane(centerPoint, sinBottomLat);
+ this.bottomPlane = new SidedPlane(centerPoint, planetModel, sinBottomLat);
this.leftPlane = new SidedPlane(centerPoint, cosLeftLon, sinLeftLon);
this.rightPlane = new SidedPlane(centerPoint, cosRightLon, sinRightLon);
this.bottomPlanePoints = new GeoPoint[]{LLHC, LRHC};
- this.leftPlanePoints = new GeoPoint[]{NORTH_POLE, LLHC};
- this.rightPlanePoints = new GeoPoint[]{NORTH_POLE, LRHC};
+ this.leftPlanePoints = new GeoPoint[]{planetModel.NORTH_POLE, LLHC};
+ this.rightPlanePoints = new GeoPoint[]{planetModel.NORTH_POLE, LRHC};
+ this.edgePoints = new GeoPoint[]{planetModel.NORTH_POLE};
}
@Override
@@ -117,7 +119,7 @@ public class GeoNorthRectangle extends G
newLeftLon = -Math.PI;
newRightLon = Math.PI;
}
- return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, newLeftLon, newRightLon);
+ return GeoBBoxFactory.makeGeoBBox(planetModel, newTopLat, newBottomLat, newLeftLon, newRightLon);
}
@Override
@@ -164,9 +166,9 @@ public class GeoNorthRectangle extends G
@Override
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
return
- p.intersects(bottomPlane, notablePoints, bottomPlanePoints, bounds, leftPlane, rightPlane) ||
- p.intersects(leftPlane, notablePoints, leftPlanePoints, bounds, rightPlane, bottomPlane) ||
- p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, leftPlane, bottomPlane);
+ p.intersects(planetModel, bottomPlane, notablePoints, bottomPlanePoints, bounds, leftPlane, rightPlane) ||
+ p.intersects(planetModel, leftPlane, notablePoints, leftPlanePoints, bounds, rightPlane, bottomPlane) ||
+ p.intersects(planetModel, rightPlane, notablePoints, rightPlanePoints, bounds, leftPlane, bottomPlane);
}
/**
@@ -196,7 +198,7 @@ public class GeoNorthRectangle extends G
return OVERLAPS;
}
- final boolean insideShape = path.isWithin(NORTH_POLE);
+ final boolean insideShape = path.isWithin(planetModel.NORTH_POLE);
if (insideRectangle == ALL_INSIDE && insideShape) {
//System.err.println(" inside of each other");
@@ -229,19 +231,20 @@ public class GeoNorthRectangle extends G
if (!(o instanceof GeoNorthRectangle))
return false;
GeoNorthRectangle other = (GeoNorthRectangle) o;
- return other.LLHC.equals(LLHC) && other.LRHC.equals(LRHC);
+ return super.equals(other) && other.LLHC.equals(LLHC) && other.LRHC.equals(LRHC);
}
@Override
public int hashCode() {
- int result = LLHC.hashCode();
+ int result = super.hashCode();
+ result = 31 * result + LLHC.hashCode();
result = 31 * result + LRHC.hashCode();
return result;
}
@Override
public String toString() {
- return "GeoNorthRectangle: {bottomlat=" + bottomLat + "(" + bottomLat * 180.0 / Math.PI + "), leftlon=" + leftLon + "(" + leftLon * 180.0 / Math.PI + "), rightlon=" + rightLon + "(" + rightLon * 180.0 / Math.PI + ")}";
+ return "GeoNorthRectangle: {planetmodel="+planetModel+", bottomlat=" + bottomLat + "(" + bottomLat * 180.0 / Math.PI + "), leftlon=" + leftLon + "(" + leftLon * 180.0 / Math.PI + "), rightlon=" + rightLon + "(" + rightLon * 180.0 / Math.PI + ")}";
}
}