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 [1/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/
Author: dsmiley
Date: Mon May 4 13:19:02 2015
New Revision: 1677595
URL: http://svn.apache.org/r1677595
Log:
LUCENE-6196: Reformat code. Removed System.err & legacy comments in test. Fixed test compile warning.
Modified:
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Bounds.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoArea.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoAreaFactory.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBox.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxBase.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseExtendedShape.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCompositeMembershipShape.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoConvexPolygon.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateHorizontalLine.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateLatitudeZone.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateLongitudeSlice.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegeneratePoint.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDegenerateVerticalLine.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDistance.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoDistanceShape.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoLatitudeZone.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoLongitudeSlice.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoMembershipShape.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoNorthLatitudeZone.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoNorthRectangle.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPath.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPoint.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoPolygonFactory.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoRectangle.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoShape.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoSizeable.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoSouthLatitudeZone.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoSouthRectangle.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoWideDegenerateHorizontalLine.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoWideLongitudeSlice.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoWideNorthRectangle.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoWideRectangle.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoWideSouthRectangle.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoWorld.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Membership.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Plane.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/SidedPlane.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Tools.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Vector.java
lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/package-info.java
lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dRptTest.java
lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/Geo3dShapeRectRelationTest.java
lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/RandomizedShapeTest.java
lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxTest.java
lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircleTest.java
lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoConvexPolygonTest.java
lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPathTest.java
lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/GeoPolygonTest.java
lucene/dev/branches/lucene6196/lucene/spatial/src/test/org/apache/lucene/spatial/spatial4j/geo3d/PlaneTest.java
Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Bounds.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Bounds.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Bounds.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/Bounds.java Mon May 4 13:19:02 2015
@@ -17,288 +17,288 @@ package org.apache.lucene.spatial.spatia
* limitations under the License.
*/
-/** An object for accumulating bounds information.
-* The bounds object is initially empty. Bounding points
-* are then applied by supplying (x,y,z) tuples. It is also
-* possible to indicate the following edge cases:
-* (1) No longitude bound possible
-* (2) No upper latitude bound possible
-* (3) No lower latitude bound possible
-* When any of these have been applied, further application of
-* points cannot override that decision.
+/**
+ * An object for accumulating bounds information.
+ * The bounds object is initially empty. Bounding points
+ * are then applied by supplying (x,y,z) tuples. It is also
+ * possible to indicate the following edge cases:
+ * (1) No longitude bound possible
+ * (2) No upper latitude bound possible
+ * (3) No lower latitude bound possible
+ * When any of these have been applied, further application of
+ * points cannot override that decision.
*/
-public class Bounds
-{
- protected boolean noLongitudeBound = false;
- protected boolean noTopLatitudeBound = false;
- protected boolean noBottomLatitudeBound = false;
-
- protected Double minLatitude = null;
- protected Double maxLatitude = null;
-
- // For longitude bounds, this class needs to worry about keeping track of the distinction
- // between left-side bounds and right-side bounds. Points are always submitted in pairs
- // which have a maximum longitude separation of Math.PI. It's therefore always possible
- // to determine which point represents a left bound, and which point represents a right
- // bound.
- //
- // The next problem is how to compare two of the same kind of bound, e.g. two left bounds.
- // We need to keep track of the leftmost longitude of the shape, but since this is a circle,
- // this is arbitrary. What we could try to do instead would be to find a pair of (left,right) bounds such
- // that:
- // (1) all other bounds are within, and
- // (2) the left minus right distance is minimized
- // Unfortunately, there are still shapes that cannot be summarized in this way correctly.
- // For example. consider a spiral that entirely circles the globe; we might arbitrarily choose
- // lat/lon bounds that do not in fact circle the globe.
- //
- // One way to handle the longitude issue correctly is therefore to stipulate that we
- // walk the bounds of the shape in some kind of connected order. Each point or circle is therefore
- // added in a sequence. We also need an interior point to make sure we have the right
- // choice of longitude bounds. But even with this, we still can't always choose whether the actual shape
- // goes right or left.
- //
- // We can make the specification truly general by submitting the following in order:
- // addSide(PlaneSide side, Membership... constraints)
- // ...
- // This is unambiguous, but I still can't see yet how this would help compute the bounds. The plane
- // solution would in general seem to boil down to the same logic that relies on points along the path
- // to define the shape boundaries. I guess the one thing that you do know for a bounded edge is that
- // the endpoints are actually connected. But it is not clear whether relationship helps in any way.
- //
- // In any case, if we specify shapes by a sequence of planes, we should stipulate that multiple sequences
- // are allowed, provided they progressively tile an area of the sphere that is connected and sequential.
- // For example, paths do alternating rectangles and circles, in sequence. Each sequence member is
- // described by a sequence of planes. I think it would also be reasonable to insist that the first segment
- // of a shape overlap or adjoin the previous shape.
- //
- // Here's a way to think about it that might help: Traversing every edge should grow the longitude bounds
- // in the direction of the traversal. So if the traversal is always known to be less than PI in total longitude
- // angle, then it is possible to use the endpoints to determine the unambiguous extension of the envelope.
- // For example, say you are currently at longitude -0.5. The next point is at longitude PI-0.1. You could say
- // that the difference in longitude going one way around would be beter than the distance the other way
- // around, and therefore the longitude envelope should be extended accordingly. But in practice, when an
- // edge goes near a pole and may be inclined as well, the longer longitude change might be the right path, even
- // if the arc length is short. So this too doesn't work.
- //
- // Given we have a hard time making an exact match, here's the current proposal. The proposal is a
- // heuristic, based on the idea that most areas are small compared to the circumference of the globe.
- // We keep track of the last point we saw, and take each point as it arrives, and compute its longitude.
- // Then, we have a choice as to which way to expand the envelope: we can expand by going to the left or
- // to the right. We choose the direction with the least longitude difference. (If we aren't sure,
- // and can recognize that, we can set "unconstrained in longitude".)
-
- protected Double leftLongitude = null;
- protected Double rightLongitude = null;
-
- public Bounds() {
- }
-
- public Double getMaxLatitude() {
- return maxLatitude;
- }
-
- public Double getMinLatitude() {
- return minLatitude;
- }
-
- public Double getLeftLongitude() {
- return leftLongitude;
- }
-
- public Double getRightLongitude() {
- return rightLongitude;
- }
-
- public boolean checkNoLongitudeBound() {
- return noLongitudeBound;
- }
-
- public boolean checkNoTopLatitudeBound() {
- return noTopLatitudeBound;
- }
-
- public boolean checkNoBottomLatitudeBound() {
- return noBottomLatitudeBound;
- }
-
- public Bounds addHorizontalCircle(double z) {
- if (!noTopLatitudeBound || !noBottomLatitudeBound) {
- // Compute a latitude value
- double latitude = Math.asin(z);
- addLatitudeBound(latitude);
- }
- return this;
+public class Bounds {
+ protected boolean noLongitudeBound = false;
+ protected boolean noTopLatitudeBound = false;
+ protected boolean noBottomLatitudeBound = false;
+
+ protected Double minLatitude = null;
+ protected Double maxLatitude = null;
+
+ // For longitude bounds, this class needs to worry about keeping track of the distinction
+ // between left-side bounds and right-side bounds. Points are always submitted in pairs
+ // which have a maximum longitude separation of Math.PI. It's therefore always possible
+ // to determine which point represents a left bound, and which point represents a right
+ // bound.
+ //
+ // The next problem is how to compare two of the same kind of bound, e.g. two left bounds.
+ // We need to keep track of the leftmost longitude of the shape, but since this is a circle,
+ // this is arbitrary. What we could try to do instead would be to find a pair of (left,right) bounds such
+ // that:
+ // (1) all other bounds are within, and
+ // (2) the left minus right distance is minimized
+ // Unfortunately, there are still shapes that cannot be summarized in this way correctly.
+ // For example. consider a spiral that entirely circles the globe; we might arbitrarily choose
+ // lat/lon bounds that do not in fact circle the globe.
+ //
+ // One way to handle the longitude issue correctly is therefore to stipulate that we
+ // walk the bounds of the shape in some kind of connected order. Each point or circle is therefore
+ // added in a sequence. We also need an interior point to make sure we have the right
+ // choice of longitude bounds. But even with this, we still can't always choose whether the actual shape
+ // goes right or left.
+ //
+ // We can make the specification truly general by submitting the following in order:
+ // addSide(PlaneSide side, Membership... constraints)
+ // ...
+ // This is unambiguous, but I still can't see yet how this would help compute the bounds. The plane
+ // solution would in general seem to boil down to the same logic that relies on points along the path
+ // to define the shape boundaries. I guess the one thing that you do know for a bounded edge is that
+ // the endpoints are actually connected. But it is not clear whether relationship helps in any way.
+ //
+ // In any case, if we specify shapes by a sequence of planes, we should stipulate that multiple sequences
+ // are allowed, provided they progressively tile an area of the sphere that is connected and sequential.
+ // For example, paths do alternating rectangles and circles, in sequence. Each sequence member is
+ // described by a sequence of planes. I think it would also be reasonable to insist that the first segment
+ // of a shape overlap or adjoin the previous shape.
+ //
+ // Here's a way to think about it that might help: Traversing every edge should grow the longitude bounds
+ // in the direction of the traversal. So if the traversal is always known to be less than PI in total longitude
+ // angle, then it is possible to use the endpoints to determine the unambiguous extension of the envelope.
+ // For example, say you are currently at longitude -0.5. The next point is at longitude PI-0.1. You could say
+ // that the difference in longitude going one way around would be beter than the distance the other way
+ // around, and therefore the longitude envelope should be extended accordingly. But in practice, when an
+ // edge goes near a pole and may be inclined as well, the longer longitude change might be the right path, even
+ // if the arc length is short. So this too doesn't work.
+ //
+ // Given we have a hard time making an exact match, here's the current proposal. The proposal is a
+ // heuristic, based on the idea that most areas are small compared to the circumference of the globe.
+ // We keep track of the last point we saw, and take each point as it arrives, and compute its longitude.
+ // Then, we have a choice as to which way to expand the envelope: we can expand by going to the left or
+ // to the right. We choose the direction with the least longitude difference. (If we aren't sure,
+ // and can recognize that, we can set "unconstrained in longitude".)
+
+ protected Double leftLongitude = null;
+ protected Double rightLongitude = null;
+
+ public Bounds() {
+ }
+
+ public Double getMaxLatitude() {
+ return maxLatitude;
+ }
+
+ public Double getMinLatitude() {
+ return minLatitude;
+ }
+
+ public Double getLeftLongitude() {
+ return leftLongitude;
+ }
+
+ public Double getRightLongitude() {
+ return rightLongitude;
+ }
+
+ public boolean checkNoLongitudeBound() {
+ return noLongitudeBound;
+ }
+
+ public boolean checkNoTopLatitudeBound() {
+ return noTopLatitudeBound;
+ }
+
+ public boolean checkNoBottomLatitudeBound() {
+ return noBottomLatitudeBound;
+ }
+
+ public Bounds addHorizontalCircle(double z) {
+ if (!noTopLatitudeBound || !noBottomLatitudeBound) {
+ // Compute a latitude value
+ double latitude = Math.asin(z);
+ addLatitudeBound(latitude);
}
+ return this;
+ }
- public Bounds addLatitudeZone(double latitude) {
- if (!noTopLatitudeBound || !noBottomLatitudeBound) {
- addLatitudeBound(latitude);
- }
- return this;
+ public Bounds addLatitudeZone(double latitude) {
+ if (!noTopLatitudeBound || !noBottomLatitudeBound) {
+ addLatitudeBound(latitude);
}
+ return this;
+ }
- public Bounds addLongitudeSlice(double newLeftLongitude, double newRightLongitude) {
- if (!noLongitudeBound) {
- addLongitudeBound(newLeftLongitude,newRightLongitude);
- }
- return this;
+ public Bounds addLongitudeSlice(double newLeftLongitude, double newRightLongitude) {
+ if (!noLongitudeBound) {
+ addLongitudeBound(newLeftLongitude, newRightLongitude);
}
-
- protected void addLatitudeBound(double latitude) {
- if (!noTopLatitudeBound && (maxLatitude == null || latitude > maxLatitude))
- maxLatitude = latitude;
- if (!noBottomLatitudeBound && (minLatitude == null || latitude < minLatitude))
- minLatitude = latitude;
- }
-
- protected void addLongitudeBound(double newLeftLongitude, double newRightLongitude) {
- if (leftLongitude == null && rightLongitude == null) {
- leftLongitude = newLeftLongitude;
- rightLongitude = newRightLongitude;
- } else {
- // Map the current range to something monotonically increasing
- double currentLeftLongitude = leftLongitude;
- double currentRightLongitude = rightLongitude;
- if (currentRightLongitude < currentLeftLongitude)
- currentRightLongitude += 2.0 * Math.PI;
- double adjustedLeftLongitude = newLeftLongitude;
- double adjustedRightLongitude = newRightLongitude;
- if (adjustedRightLongitude < adjustedLeftLongitude)
- adjustedRightLongitude += 2.0 * Math.PI;
- // Compare to see what the relationship is
- if (currentLeftLongitude <= adjustedLeftLongitude && currentRightLongitude >= adjustedRightLongitude) {
- // No adjustment needed.
- } else if (currentLeftLongitude >= adjustedLeftLongitude && currentRightLongitude <= adjustedRightLongitude) {
- // New longitude entirely contains old one
- leftLongitude = newLeftLongitude;
- rightLongitude = newRightLongitude;
- } else {
- if (currentLeftLongitude > adjustedLeftLongitude) {
- // New left longitude needed
- leftLongitude = newLeftLongitude;
- }
- if (currentRightLongitude < adjustedRightLongitude) {
- // New right longitude needed
- rightLongitude = newRightLongitude;
- }
- }
- }
- double testRightLongitude = rightLongitude;
- if (testRightLongitude < leftLongitude)
- testRightLongitude += Math.PI * 2.0;
- // If the bound exceeds 180 degrees, we know we could have screwed up.
- if (testRightLongitude - leftLongitude >= Math.PI) {
- noLongitudeBound = true;
- leftLongitude = null;
- rightLongitude = null;
- }
+ return this;
+ }
+
+ protected void addLatitudeBound(double latitude) {
+ if (!noTopLatitudeBound && (maxLatitude == null || latitude > maxLatitude))
+ maxLatitude = latitude;
+ if (!noBottomLatitudeBound && (minLatitude == null || latitude < minLatitude))
+ minLatitude = latitude;
+ }
+
+ protected void addLongitudeBound(double newLeftLongitude, double newRightLongitude) {
+ if (leftLongitude == null && rightLongitude == null) {
+ leftLongitude = newLeftLongitude;
+ rightLongitude = newRightLongitude;
+ } else {
+ // Map the current range to something monotonically increasing
+ double currentLeftLongitude = leftLongitude;
+ double currentRightLongitude = rightLongitude;
+ if (currentRightLongitude < currentLeftLongitude)
+ currentRightLongitude += 2.0 * Math.PI;
+ double adjustedLeftLongitude = newLeftLongitude;
+ double adjustedRightLongitude = newRightLongitude;
+ if (adjustedRightLongitude < adjustedLeftLongitude)
+ adjustedRightLongitude += 2.0 * Math.PI;
+ // Compare to see what the relationship is
+ if (currentLeftLongitude <= adjustedLeftLongitude && currentRightLongitude >= adjustedRightLongitude) {
+ // No adjustment needed.
+ } else if (currentLeftLongitude >= adjustedLeftLongitude && currentRightLongitude <= adjustedRightLongitude) {
+ // New longitude entirely contains old one
+ leftLongitude = newLeftLongitude;
+ rightLongitude = newRightLongitude;
+ } else {
+ if (currentLeftLongitude > adjustedLeftLongitude) {
+ // New left longitude needed
+ leftLongitude = newLeftLongitude;
+ }
+ if (currentRightLongitude < adjustedRightLongitude) {
+ // New right longitude needed
+ rightLongitude = newRightLongitude;
+ }
+ }
+ }
+ double testRightLongitude = rightLongitude;
+ if (testRightLongitude < leftLongitude)
+ testRightLongitude += Math.PI * 2.0;
+ // If the bound exceeds 180 degrees, we know we could have screwed up.
+ if (testRightLongitude - leftLongitude >= Math.PI) {
+ noLongitudeBound = true;
+ leftLongitude = null;
+ rightLongitude = null;
}
-
- protected void addLongitudeBound(double longitude) {
- // If this point is within the current bounds, we're done; otherwise
- // expand one side or the other.
- if (leftLongitude == null && rightLongitude == null) {
- leftLongitude = longitude;
- rightLongitude = longitude;
+ }
+
+ protected void addLongitudeBound(double longitude) {
+ // If this point is within the current bounds, we're done; otherwise
+ // expand one side or the other.
+ if (leftLongitude == null && rightLongitude == null) {
+ leftLongitude = longitude;
+ rightLongitude = longitude;
+ } else {
+ // Compute whether we're to the right of the left value. But the left value may be greater than
+ // the right value.
+ double currentLeftLongitude = leftLongitude;
+ double currentRightLongitude = rightLongitude;
+ if (currentRightLongitude < currentLeftLongitude)
+ currentRightLongitude += 2.0 * Math.PI;
+ // We have a range to look at that's going in the right way.
+ // Now, do the same trick with the computed longitude.
+ if (longitude < currentLeftLongitude)
+ longitude += 2.0 * Math.PI;
+
+ if (longitude < currentLeftLongitude || longitude > currentRightLongitude) {
+ // Outside of current bounds. Consider carefully how we'll expand.
+ double leftExtensionAmt;
+ double rightExtensionAmt;
+ if (longitude < currentLeftLongitude) {
+ leftExtensionAmt = currentLeftLongitude - longitude;
} else {
- // Compute whether we're to the right of the left value. But the left value may be greater than
- // the right value.
- double currentLeftLongitude = leftLongitude;
- double currentRightLongitude = rightLongitude;
- if (currentRightLongitude < currentLeftLongitude)
- currentRightLongitude += 2.0 * Math.PI;
- // We have a range to look at that's going in the right way.
- // Now, do the same trick with the computed longitude.
- if (longitude < currentLeftLongitude)
- longitude += 2.0 * Math.PI;
-
- if (longitude < currentLeftLongitude || longitude > currentRightLongitude) {
- // Outside of current bounds. Consider carefully how we'll expand.
- double leftExtensionAmt;
- double rightExtensionAmt;
- if (longitude < currentLeftLongitude) {
- leftExtensionAmt = currentLeftLongitude - longitude;
- } else {
- leftExtensionAmt = currentLeftLongitude + 2.0 * Math.PI - longitude;
- }
- if (longitude > currentRightLongitude) {
- rightExtensionAmt = longitude - currentRightLongitude;
- } else {
- rightExtensionAmt = longitude + 2.0 * Math.PI - currentRightLongitude;
- }
- if (leftExtensionAmt < rightExtensionAmt) {
- currentLeftLongitude = leftLongitude - leftExtensionAmt;
- while (currentLeftLongitude <= -Math.PI) {
- currentLeftLongitude += 2.0 * Math.PI;
- }
- leftLongitude = currentLeftLongitude;
- } else {
- currentRightLongitude = rightLongitude + rightExtensionAmt;
- while (currentRightLongitude > Math.PI) {
- currentRightLongitude -= 2.0 * Math.PI;
- }
- rightLongitude = currentRightLongitude;
- }
- }
+ leftExtensionAmt = currentLeftLongitude + 2.0 * Math.PI - longitude;
}
- double testRightLongitude = rightLongitude;
- if (testRightLongitude < leftLongitude)
- testRightLongitude += Math.PI * 2.0;
- if (testRightLongitude - leftLongitude >= Math.PI) {
- noLongitudeBound = true;
- leftLongitude = null;
- rightLongitude = null;
- }
- }
-
- public Bounds addPoint(Vector v) {
- return addPoint(v.x, v.y, v.z);
- }
-
- public Bounds addPoint(double x, double y, double z) {
- if (!noLongitudeBound) {
- // Get a longitude value
- double longitude = Math.atan2(y,x);
- //System.err.println(" add longitude bound at "+longitude * 180.0/Math.PI);
- addLongitudeBound(longitude);
- }
- if (!noTopLatitudeBound || !noBottomLatitudeBound) {
- // Compute a latitude value
- double latitude = Math.asin(z);
- addLatitudeBound(latitude);
+ if (longitude > currentRightLongitude) {
+ rightExtensionAmt = longitude - currentRightLongitude;
+ } else {
+ rightExtensionAmt = longitude + 2.0 * Math.PI - currentRightLongitude;
}
- return this;
+ if (leftExtensionAmt < rightExtensionAmt) {
+ currentLeftLongitude = leftLongitude - leftExtensionAmt;
+ while (currentLeftLongitude <= -Math.PI) {
+ currentLeftLongitude += 2.0 * Math.PI;
+ }
+ leftLongitude = currentLeftLongitude;
+ } else {
+ currentRightLongitude = rightLongitude + rightExtensionAmt;
+ while (currentRightLongitude > Math.PI) {
+ currentRightLongitude -= 2.0 * Math.PI;
+ }
+ rightLongitude = currentRightLongitude;
+ }
+ }
+ }
+ double testRightLongitude = rightLongitude;
+ if (testRightLongitude < leftLongitude)
+ testRightLongitude += Math.PI * 2.0;
+ if (testRightLongitude - leftLongitude >= Math.PI) {
+ noLongitudeBound = true;
+ leftLongitude = null;
+ rightLongitude = null;
}
+ }
- public Bounds addPoint(double latitude, double longitude) {
- if (!noLongitudeBound) {
- // Get a longitude value
- addLongitudeBound(longitude);
- }
- if (!noTopLatitudeBound || !noBottomLatitudeBound) {
- // Compute a latitude value
- addLatitudeBound(latitude);
- }
- return this;
+ public Bounds addPoint(Vector v) {
+ return addPoint(v.x, v.y, v.z);
+ }
+
+ public Bounds addPoint(double x, double y, double z) {
+ if (!noLongitudeBound) {
+ // Get a longitude value
+ double longitude = Math.atan2(y, x);
+ //System.err.println(" add longitude bound at "+longitude * 180.0/Math.PI);
+ addLongitudeBound(longitude);
+ }
+ if (!noTopLatitudeBound || !noBottomLatitudeBound) {
+ // Compute a latitude value
+ double latitude = Math.asin(z);
+ addLatitudeBound(latitude);
}
-
- public Bounds noLongitudeBound() {
- noLongitudeBound = true;
- leftLongitude = null;
- rightLongitude = null;
- return this;
- }
-
- public Bounds noTopLatitudeBound() {
- noTopLatitudeBound = true;
- maxLatitude = null;
- return this;
- }
-
- public Bounds noBottomLatitudeBound() {
- noBottomLatitudeBound = true;
- minLatitude = null;
- return this;
+ return this;
+ }
+
+ public Bounds addPoint(double latitude, double longitude) {
+ if (!noLongitudeBound) {
+ // Get a longitude value
+ addLongitudeBound(longitude);
+ }
+ if (!noTopLatitudeBound || !noBottomLatitudeBound) {
+ // Compute a latitude value
+ addLatitudeBound(latitude);
}
+ return this;
+ }
+
+ public Bounds noLongitudeBound() {
+ noLongitudeBound = true;
+ leftLongitude = null;
+ rightLongitude = null;
+ return this;
+ }
+
+ public Bounds noTopLatitudeBound() {
+ noTopLatitudeBound = true;
+ maxLatitude = null;
+ return this;
+ }
+
+ public Bounds noBottomLatitudeBound() {
+ noBottomLatitudeBound = true;
+ minLatitude = null;
+ return this;
+ }
}
Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoArea.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoArea.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoArea.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoArea.java Mon May 4 13:19:02 2015
@@ -17,33 +17,37 @@ package org.apache.lucene.spatial.spatia
* limitations under the License.
*/
-/** A GeoArea represents a standard 2-D breakdown of a part of sphere. It can
-* be bounded in latitude, or bounded in both latitude and longitude, or not
-* bounded at all. The purpose of the interface is to describe bounding shapes used for
-* computation of geo hashes. */
+/**
+ * A GeoArea represents a standard 2-D breakdown of a part of sphere. It can
+ * be bounded in latitude, or bounded in both latitude and longitude, or not
+ * bounded at all. The purpose of the interface is to describe bounding shapes used for
+ * computation of geo hashes.
+ */
public interface GeoArea extends Membership {
// Since we don't know what each GeoArea's constraints are,
// we put the onus on the GeoArea implementation to do the right thing.
// This will, of course, rely heavily on methods provided by
// the underlying GeoShape class.
-
- public static final int CONTAINS = 0;
- public static final int WITHIN = 1;
- public static final int OVERLAPS = 2;
- public static final int DISJOINT = 3;
- /** Find the spatial relationship between a shape and the current geo area.
- * Note: return value is how the GeoShape relates to the GeoArea, not the
- * other way around. For example, if this GeoArea is entirely within the
- * shape, then CONTAINS should be returned. If the shape is entirely enclosed
- * by this GeoArea, then WITHIN should be returned.
- * Note well: When a shape consists of multiple independent overlapping subshapes,
- * it is sometimes impossible to determine the distinction between
- * OVERLAPS and CONTAINS. In that case, OVERLAPS may be returned even
- * though the proper result would in fact be CONTAINS. Code accordingly.
- *@param shape is the shape to consider.
- *@return the relationship, from the perspective of the shape.
- */
- public int getRelationship(GeoShape shape);
+ public static final int CONTAINS = 0;
+ public static final int WITHIN = 1;
+ public static final int OVERLAPS = 2;
+ public static final int DISJOINT = 3;
+
+ /**
+ * Find the spatial relationship between a shape and the current geo area.
+ * Note: return value is how the GeoShape relates to the GeoArea, not the
+ * other way around. For example, if this GeoArea is entirely within the
+ * shape, then CONTAINS should be returned. If the shape is entirely enclosed
+ * by this GeoArea, then WITHIN should be returned.
+ * Note well: When a shape consists of multiple independent overlapping subshapes,
+ * it is sometimes impossible to determine the distinction between
+ * OVERLAPS and CONTAINS. In that case, OVERLAPS may be returned even
+ * though the proper result would in fact be CONTAINS. Code accordingly.
+ *
+ * @param shape is the shape to consider.
+ * @return the relationship, from the perspective of the shape.
+ */
+ public int getRelationship(GeoShape shape);
}
Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoAreaFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoAreaFactory.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoAreaFactory.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoAreaFactory.java Mon May 4 13:19:02 2015
@@ -17,20 +17,21 @@ package org.apache.lucene.spatial.spatia
* limitations under the License.
*/
-public class GeoAreaFactory
-{
- private GeoAreaFactory() {
- }
-
- /** Create a GeoArea of the right kind given the specified bounds.
- *@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 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 class GeoAreaFactory {
+ private GeoAreaFactory() {
+ }
+
+ /**
+ * Create a GeoArea of the right kind given the specified bounds.
+ *
+ * @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 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);
+ }
}
Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBox.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBox.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBox.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBox.java Mon May 4 13:19:02 2015
@@ -17,16 +17,19 @@ package org.apache.lucene.spatial.spatia
* limitations under the License.
*/
-/** All bounding box shapes have this interface in common.
-* This describes methods that bounding boxes have above and beyond
-* GeoMembershipShape's.
-*/
+/**
+ * All bounding box shapes have this interface in common.
+ * This describes methods that bounding boxes have above and beyond
+ * GeoMembershipShape's.
+ */
public interface GeoBBox extends GeoMembershipShape, GeoSizeable, GeoArea {
- /** Expand box by specified angle.
- *@param angle is the angle amount to expand the GeoBBox by.
- *@return a new GeoBBox.
- */
- public GeoBBox expand(double angle);
-
+ /**
+ * Expand box by specified angle.
+ *
+ * @param angle is the angle amount to expand the GeoBBox by.
+ * @return a new GeoBBox.
+ */
+ public GeoBBox expand(double angle);
+
}
Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxBase.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxBase.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxBase.java Mon May 4 13:19:02 2015
@@ -17,39 +17,40 @@ package org.apache.lucene.spatial.spatia
* limitations under the License.
*/
-/** All bounding box shapes can derive from this base class, which furnishes
-* some common code
-*/
+/**
+ * All bounding box shapes can derive from this base class, which furnishes
+ * some common code
+ */
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);
+ 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);
+
+ @Override
+ public abstract boolean isWithin(final Vector point);
- @Override
- public abstract boolean isWithin(final Vector point);
+ protected final static int ALL_INSIDE = 0;
+ protected final static int SOME_INSIDE = 1;
+ protected final static int NONE_INSIDE = 2;
- protected final static int ALL_INSIDE = 0;
- protected final static int SOME_INSIDE = 1;
- protected final static int NONE_INSIDE = 2;
-
- protected int isShapeInsideBBox(final GeoShape path) {
- final GeoPoint[] pathPoints = path.getEdgePoints();
- boolean foundOutside = false;
- boolean foundInside = false;
- for (GeoPoint p : pathPoints) {
- if (isWithin(p)) {
- foundInside = true;
- } else {
- foundOutside = true;
- }
- }
- if (!foundInside && !foundOutside)
- return NONE_INSIDE;
- if (foundInside && !foundOutside)
- return ALL_INSIDE;
- if (foundOutside && !foundInside)
- return NONE_INSIDE;
- return SOME_INSIDE;
+ protected int isShapeInsideBBox(final GeoShape path) {
+ final GeoPoint[] pathPoints = path.getEdgePoints();
+ boolean foundOutside = false;
+ boolean foundInside = false;
+ for (GeoPoint p : pathPoints) {
+ if (isWithin(p)) {
+ foundInside = true;
+ } else {
+ foundOutside = true;
+ }
}
+ if (!foundInside && !foundOutside)
+ return NONE_INSIDE;
+ if (foundInside && !foundOutside)
+ return ALL_INSIDE;
+ if (foundOutside && !foundInside)
+ return NONE_INSIDE;
+ return SOME_INSIDE;
+ }
}
Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBBoxFactory.java Mon May 4 13:19:02 2015
@@ -17,86 +17,87 @@ package org.apache.lucene.spatial.spatia
* limitations under the License.
*/
-public class GeoBBoxFactory
-{
- private GeoBBoxFactory() {
- }
-
- /** Create a geobbox of the right kind given the specified bounds.
- *@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) {
- //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;
- if (bottomLat < -Math.PI * 0.5)
- bottomLat = -Math.PI * 0.5;
- if (leftLon < -Math.PI)
- leftLon = -Math.PI;
- if (rightLon > Math.PI)
- rightLon = Math.PI;
- if (leftLon == -Math.PI && rightLon == Math.PI) {
- if (topLat == Math.PI * 0.5 && bottomLat == -Math.PI * 0.5)
- return new GeoWorld();
- if (topLat == bottomLat) {
- if (topLat == Math.PI * 0.5 || topLat == -Math.PI * 0.5)
- return new GeoDegeneratePoint(topLat,0.0);
- return new GeoDegenerateLatitudeZone(topLat);
- }
- if (topLat == Math.PI * 0.5)
- return new GeoNorthLatitudeZone(bottomLat);
- else if (bottomLat == -Math.PI * 0.5)
- return new GeoSouthLatitudeZone(topLat);
- return new GeoLatitudeZone(topLat, bottomLat);
- }
- //System.err.println(" not latitude zone");
- double extent = rightLon - leftLon;
- if (extent < 0.0)
- extent += Math.PI * 2.0;
- if (topLat == Math.PI * 0.5 && bottomLat == -Math.PI * 0.5) {
- if (leftLon == rightLon)
- return new GeoDegenerateLongitudeSlice(leftLon);
+public class GeoBBoxFactory {
+ private GeoBBoxFactory() {
+ }
- if (extent >= Math.PI)
- return new GeoWideLongitudeSlice(leftLon, rightLon);
-
- return new GeoLongitudeSlice(leftLon, rightLon);
- }
- //System.err.println(" not longitude slice");
- if (leftLon == rightLon) {
- if (topLat == bottomLat)
- return new GeoDegeneratePoint(topLat, leftLon);
- return new GeoDegenerateVerticalLine(topLat, bottomLat, leftLon);
- }
- //System.err.println(" not vertical line");
- if (extent >= Math.PI) {
- if (topLat == bottomLat) {
- //System.err.println(" wide degenerate line");
- return new GeoWideDegenerateHorizontalLine(topLat, leftLon, rightLon);
- }
- if (topLat == Math.PI * 0.5) {
- return new GeoWideNorthRectangle(bottomLat, leftLon, rightLon);
- } else if (bottomLat == -Math.PI * 0.5) {
- return new GeoWideSouthRectangle(topLat, leftLon, rightLon);
- }
- //System.err.println(" wide rect");
- return new GeoWideRectangle(topLat, bottomLat, leftLon, rightLon);
- }
- if (topLat == bottomLat) {
- //System.err.println(" horizontal line");
- return new GeoDegenerateHorizontalLine(topLat, leftLon, rightLon);
- }
- if (topLat == Math.PI * 0.5) {
- return new GeoNorthRectangle(bottomLat, leftLon, rightLon);
- } else if (bottomLat == -Math.PI * 0.5) {
- return new GeoSouthRectangle(topLat, leftLon, rightLon);
- }
- //System.err.println(" rectangle");
- return new GeoRectangle(topLat, bottomLat, leftLon, rightLon);
+ /**
+ * Create a geobbox of the right kind given the specified bounds.
+ *
+ * @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) {
+ //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;
+ if (bottomLat < -Math.PI * 0.5)
+ bottomLat = -Math.PI * 0.5;
+ if (leftLon < -Math.PI)
+ leftLon = -Math.PI;
+ if (rightLon > Math.PI)
+ rightLon = Math.PI;
+ if (leftLon == -Math.PI && rightLon == Math.PI) {
+ if (topLat == Math.PI * 0.5 && bottomLat == -Math.PI * 0.5)
+ return new GeoWorld();
+ if (topLat == bottomLat) {
+ if (topLat == Math.PI * 0.5 || topLat == -Math.PI * 0.5)
+ return new GeoDegeneratePoint(topLat, 0.0);
+ return new GeoDegenerateLatitudeZone(topLat);
+ }
+ if (topLat == Math.PI * 0.5)
+ return new GeoNorthLatitudeZone(bottomLat);
+ else if (bottomLat == -Math.PI * 0.5)
+ return new GeoSouthLatitudeZone(topLat);
+ return new GeoLatitudeZone(topLat, bottomLat);
}
+ //System.err.println(" not latitude zone");
+ double extent = rightLon - leftLon;
+ if (extent < 0.0)
+ extent += Math.PI * 2.0;
+ if (topLat == Math.PI * 0.5 && bottomLat == -Math.PI * 0.5) {
+ if (leftLon == rightLon)
+ return new GeoDegenerateLongitudeSlice(leftLon);
+
+ if (extent >= Math.PI)
+ return new GeoWideLongitudeSlice(leftLon, rightLon);
+
+ return new GeoLongitudeSlice(leftLon, rightLon);
+ }
+ //System.err.println(" not longitude slice");
+ if (leftLon == rightLon) {
+ if (topLat == bottomLat)
+ return new GeoDegeneratePoint(topLat, leftLon);
+ return new GeoDegenerateVerticalLine(topLat, bottomLat, leftLon);
+ }
+ //System.err.println(" not vertical line");
+ if (extent >= Math.PI) {
+ if (topLat == bottomLat) {
+ //System.err.println(" wide degenerate line");
+ return new GeoWideDegenerateHorizontalLine(topLat, leftLon, rightLon);
+ }
+ if (topLat == Math.PI * 0.5) {
+ return new GeoWideNorthRectangle(bottomLat, leftLon, rightLon);
+ } else if (bottomLat == -Math.PI * 0.5) {
+ return new GeoWideSouthRectangle(topLat, leftLon, rightLon);
+ }
+ //System.err.println(" wide rect");
+ return new GeoWideRectangle(topLat, bottomLat, leftLon, rightLon);
+ }
+ if (topLat == bottomLat) {
+ //System.err.println(" horizontal line");
+ return new GeoDegenerateHorizontalLine(topLat, leftLon, rightLon);
+ }
+ if (topLat == Math.PI * 0.5) {
+ return new GeoNorthRectangle(bottomLat, leftLon, rightLon);
+ } else if (bottomLat == -Math.PI * 0.5) {
+ return new GeoSouthRectangle(topLat, leftLon, rightLon);
+ }
+ //System.err.println(" rectangle");
+ return new GeoRectangle(topLat, bottomLat, leftLon, rightLon);
+ }
}
Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseExtendedShape.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseExtendedShape.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseExtendedShape.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoBaseExtendedShape.java Mon May 4 13:19:02 2015
@@ -17,68 +17,76 @@ package org.apache.lucene.spatial.spatia
* limitations under the License.
*/
-/** Base extended shape object.
-*/
-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 GeoBaseExtendedShape()
- {
- }
+/**
+ * Base extended shape object.
+ */
+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 GeoBaseExtendedShape() {
+ }
+
+ /**
+ * 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 abstract boolean isWithin(final Vector point);
- /** 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 abstract boolean isWithin(final Vector point);
-
- /** 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 abstract boolean isWithin(final double x, final double y, final double z);
-
- /** Return a sample point that is on the edge of the shape.
- *@return a number of edge points, one for each disconnected edge.
- */
- @Override
- public abstract GeoPoint[] getEdgePoints();
-
- /** Assess whether a plane, within the provided bounds, intersects
- * with the shape.
- *@param plane is the plane to assess for intersection with the shape's edges or
- * bounding curves.
- *@param bounds are a set of bounds that define an area that an
- * intersection must be within in order to qualify (provided by a GeoArea).
- *@return true if there's such an intersection, false if not.
- */
- @Override
- public abstract boolean intersects(final Plane plane, final GeoPoint[] notablePoints, final Membership... bounds);
-
- /** Compute longitude/latitude bounds for the shape.
- *@param bounds is the optional input bounds object. If this is null,
- * a bounds object will be created. Otherwise, the input object will be modified.
- *@return a Bounds object describing the shape's bounds. If the bounds cannot
- * be computed, then return a Bounds object with noLongitudeBound,
- * noTopLatitudeBound, and noBottomLatitudeBound.
- */
- @Override
- public Bounds getBounds(Bounds bounds)
- {
- if (bounds == null)
- bounds = new Bounds();
- if (isWithin(NORTH_POLE)) {
- bounds.noTopLatitudeBound().noLongitudeBound();
- }
- if (isWithin(SOUTH_POLE)) {
- bounds.noBottomLatitudeBound().noLongitudeBound();
- }
- return bounds;
+ /**
+ * 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 abstract boolean isWithin(final double x, final double y, final double z);
+
+ /**
+ * Return a sample point that is on the edge of the shape.
+ *
+ * @return a number of edge points, one for each disconnected edge.
+ */
+ @Override
+ public abstract GeoPoint[] getEdgePoints();
+
+ /**
+ * Assess whether a plane, within the provided bounds, intersects
+ * with the shape.
+ *
+ * @param plane is the plane to assess for intersection with the shape's edges or
+ * bounding curves.
+ * @param bounds are a set of bounds that define an area that an
+ * intersection must be within in order to qualify (provided by a GeoArea).
+ * @return true if there's such an intersection, false if not.
+ */
+ @Override
+ public abstract boolean intersects(final Plane plane, final GeoPoint[] notablePoints, final Membership... bounds);
+
+ /**
+ * Compute longitude/latitude bounds for the shape.
+ *
+ * @param bounds is the optional input bounds object. If this is null,
+ * a bounds object will be created. Otherwise, the input object will be modified.
+ * @return a Bounds object describing the shape's bounds. If the bounds cannot
+ * be computed, then return a Bounds object with noLongitudeBound,
+ * noTopLatitudeBound, and noBottomLatitudeBound.
+ */
+ @Override
+ public Bounds getBounds(Bounds bounds) {
+ if (bounds == null)
+ bounds = new Bounds();
+ if (isWithin(NORTH_POLE)) {
+ bounds.noTopLatitudeBound().noLongitudeBound();
+ }
+ if (isWithin(SOUTH_POLE)) {
+ bounds.noBottomLatitudeBound().noLongitudeBound();
}
+ return bounds;
+ }
}
Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCircle.java Mon May 4 13:19:02 2015
@@ -17,244 +17,241 @@ package org.apache.lucene.spatial.spatia
* limitations under the License.
*/
-/** Circular area with a center and radius.
-*/
-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();
- 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.cutoffAngle = cutoffAngle;
- this.circlePlane = new SidedPlane(center, center, -cosAngle);
-
- // 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;
- }
- while (newLon > Math.PI) {
- newLon -= Math.PI * 2.0;
- }
- 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};
- }
- }
-
- @Override
- public double getRadius() {
- return cutoffAngle;
- }
-
- /** Returns the center of a circle into which the area will be inscribed.
- *@return the center.
- */
- @Override
- public GeoPoint getCenter() {
- return center;
- }
-
- /** Compute an estimate of "distance" to the GeoPoint.
- * A return value of Double.MAX_VALUE should be returned for
- * points outside of the shape.
- */
- @Override
- public double computeNormalDistance(final GeoPoint point)
- {
- double normalDistance = this.center.normalDistance(point);
- if (normalDistance > cutoffNormalDistance)
- return Double.MAX_VALUE;
- return normalDistance;
- }
-
- /** Compute an estimate of "distance" to the GeoPoint.
- * A return value of Double.MAX_VALUE should be returned for
- * points outside of the shape.
- */
- @Override
- public double computeNormalDistance(final double x, final double y, final double z)
- {
- double normalDistance = this.center.normalDistance(x,y,z);
- if (normalDistance > cutoffNormalDistance)
- return Double.MAX_VALUE;
- return normalDistance;
- }
-
- /** Compute a squared estimate of the "distance" to the
- * GeoPoint. Double.MAX_VALUE indicates a point outside of the
- * shape.
- */
- @Override
- public double computeSquaredNormalDistance(final GeoPoint point)
- {
- double normalDistanceSquared = this.center.normalDistanceSquared(point);
- if (normalDistanceSquared > cutoffNormalDistance * cutoffNormalDistance)
- return Double.MAX_VALUE;
- return normalDistanceSquared;
- }
-
- /** Compute a squared estimate of the "distance" to the
- * GeoPoint. Double.MAX_VALUE indicates a point outside of the
- * shape.
- */
- @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)
- return Double.MAX_VALUE;
- return normalDistanceSquared;
- }
-
- /** Compute a linear distance to the vector.
- * return Double.MAX_VALUE for points outside the shape.
- */
- @Override
- public double computeLinearDistance(final GeoPoint point)
- {
- double linearDistance = this.center.linearDistance(point);
- if (linearDistance > cutoffLinearDistance)
- return Double.MAX_VALUE;
- return linearDistance;
- }
-
- /** Compute a linear distance to the vector.
- * return Double.MAX_VALUE for points outside the shape.
- */
- @Override
- public double computeLinearDistance(final double x, final double y, final double z)
- {
- double linearDistance = this.center.linearDistance(x,y,z);
- if (linearDistance > cutoffLinearDistance)
- return Double.MAX_VALUE;
- return linearDistance;
- }
-
- /** Compute a squared linear distance to the vector.
- */
- @Override
- public double computeSquaredLinearDistance(final GeoPoint point)
- {
- double linearDistanceSquared = this.center.linearDistanceSquared(point);
- if (linearDistanceSquared > cutoffLinearDistance * cutoffLinearDistance)
- return Double.MAX_VALUE;
- return linearDistanceSquared;
- }
-
- /** Compute a squared linear distance to the vector.
- */
- @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)
- return Double.MAX_VALUE;
- return linearDistanceSquared;
- }
-
- /** Compute a true, accurate, great-circle distance.
- * Double.MAX_VALUE indicates a point is outside of the shape.
- */
- @Override
- public double computeArcDistance(final GeoPoint point)
- {
- double dist = this.center.arcDistance(point);
- if (dist > cutoffAngle)
- return Double.MAX_VALUE;
- return dist;
- }
-
- @Override
- public boolean isWithin(final Vector point)
- {
- // Fastest way of determining membership
- return circlePlane.isWithin(point);
- }
-
- @Override
- public boolean isWithin(final double x, final double y, final double z)
- {
- // Fastest way of determining membership
- return circlePlane.isWithin(x,y,z);
- }
-
- @Override
- public GeoPoint[] getEdgePoints()
- {
- return edgePoints;
- }
-
- @Override
- public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
- {
- return circlePlane.intersects(p, notablePoints, circlePoints, bounds);
- }
-
- /** Compute longitude/latitude bounds for the shape.
- *@param bounds is the optional input bounds object. If this is null,
- * a bounds object will be created. Otherwise, the input object will be modified.
- *@return a Bounds object describing the shape's bounds. If the bounds cannot
- * be computed, then return a Bounds object with noLongitudeBound,
- * noTopLatitudeBound, and noBottomLatitudeBound.
- */
- @Override
- public Bounds getBounds(Bounds bounds)
- {
- bounds = super.getBounds(bounds);
- bounds.addPoint(center);
- circlePlane.recordBounds(bounds);
- return bounds;
- }
-
- @Override
- public boolean equals(Object o)
- {
- if (!(o instanceof GeoCircle))
- return false;
- GeoCircle other = (GeoCircle)o;
- return other.center.equals(center) && other.cutoffAngle == cutoffAngle;
- }
-
- @Override
- public int hashCode() {
- int result;
- long temp;
- result = center.hashCode();
- 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+")}";
- }
+/**
+ * Circular area with a center and radius.
+ */
+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();
+ 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.cutoffAngle = cutoffAngle;
+ this.circlePlane = new SidedPlane(center, center, -cosAngle);
+
+ // 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;
+ }
+ while (newLon > Math.PI) {
+ newLon -= Math.PI * 2.0;
+ }
+ 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};
+ }
+ }
+
+ @Override
+ public double getRadius() {
+ return cutoffAngle;
+ }
+
+ /**
+ * Returns the center of a circle into which the area will be inscribed.
+ *
+ * @return the center.
+ */
+ @Override
+ public GeoPoint getCenter() {
+ return center;
+ }
+
+ /**
+ * Compute an estimate of "distance" to the GeoPoint.
+ * A return value of Double.MAX_VALUE should be returned for
+ * points outside of the shape.
+ */
+ @Override
+ public double computeNormalDistance(final GeoPoint point) {
+ double normalDistance = this.center.normalDistance(point);
+ if (normalDistance > cutoffNormalDistance)
+ return Double.MAX_VALUE;
+ return normalDistance;
+ }
+
+ /**
+ * Compute an estimate of "distance" to the GeoPoint.
+ * A return value of Double.MAX_VALUE should be returned for
+ * points outside of the shape.
+ */
+ @Override
+ public double computeNormalDistance(final double x, final double y, final double z) {
+ double normalDistance = this.center.normalDistance(x, y, z);
+ if (normalDistance > cutoffNormalDistance)
+ return Double.MAX_VALUE;
+ return normalDistance;
+ }
+
+ /**
+ * Compute a squared estimate of the "distance" to the
+ * GeoPoint. Double.MAX_VALUE indicates a point outside of the
+ * shape.
+ */
+ @Override
+ public double computeSquaredNormalDistance(final GeoPoint point) {
+ double normalDistanceSquared = this.center.normalDistanceSquared(point);
+ if (normalDistanceSquared > cutoffNormalDistance * cutoffNormalDistance)
+ return Double.MAX_VALUE;
+ return normalDistanceSquared;
+ }
+
+ /**
+ * Compute a squared estimate of the "distance" to the
+ * GeoPoint. Double.MAX_VALUE indicates a point outside of the
+ * shape.
+ */
+ @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)
+ return Double.MAX_VALUE;
+ return normalDistanceSquared;
+ }
+
+ /**
+ * Compute a linear distance to the vector.
+ * return Double.MAX_VALUE for points outside the shape.
+ */
+ @Override
+ public double computeLinearDistance(final GeoPoint point) {
+ double linearDistance = this.center.linearDistance(point);
+ if (linearDistance > cutoffLinearDistance)
+ return Double.MAX_VALUE;
+ return linearDistance;
+ }
+
+ /**
+ * Compute a linear distance to the vector.
+ * return Double.MAX_VALUE for points outside the shape.
+ */
+ @Override
+ public double computeLinearDistance(final double x, final double y, final double z) {
+ double linearDistance = this.center.linearDistance(x, y, z);
+ if (linearDistance > cutoffLinearDistance)
+ return Double.MAX_VALUE;
+ return linearDistance;
+ }
+
+ /**
+ * Compute a squared linear distance to the vector.
+ */
+ @Override
+ public double computeSquaredLinearDistance(final GeoPoint point) {
+ double linearDistanceSquared = this.center.linearDistanceSquared(point);
+ if (linearDistanceSquared > cutoffLinearDistance * cutoffLinearDistance)
+ return Double.MAX_VALUE;
+ return linearDistanceSquared;
+ }
+
+ /**
+ * Compute a squared linear distance to the vector.
+ */
+ @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)
+ return Double.MAX_VALUE;
+ return linearDistanceSquared;
+ }
+
+ /**
+ * Compute a true, accurate, great-circle distance.
+ * Double.MAX_VALUE indicates a point is outside of the shape.
+ */
+ @Override
+ public double computeArcDistance(final GeoPoint point) {
+ double dist = this.center.arcDistance(point);
+ if (dist > cutoffAngle)
+ return Double.MAX_VALUE;
+ return dist;
+ }
+
+ @Override
+ public boolean isWithin(final Vector point) {
+ // Fastest way of determining membership
+ return circlePlane.isWithin(point);
+ }
+
+ @Override
+ public boolean isWithin(final double x, final double y, final double z) {
+ // Fastest way of determining membership
+ return circlePlane.isWithin(x, y, z);
+ }
+
+ @Override
+ public GeoPoint[] getEdgePoints() {
+ return edgePoints;
+ }
+
+ @Override
+ public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
+ return circlePlane.intersects(p, notablePoints, circlePoints, bounds);
+ }
+
+ /**
+ * Compute longitude/latitude bounds for the shape.
+ *
+ * @param bounds is the optional input bounds object. If this is null,
+ * a bounds object will be created. Otherwise, the input object will be modified.
+ * @return a Bounds object describing the shape's bounds. If the bounds cannot
+ * be computed, then return a Bounds object with noLongitudeBound,
+ * noTopLatitudeBound, and noBottomLatitudeBound.
+ */
+ @Override
+ public Bounds getBounds(Bounds bounds) {
+ bounds = super.getBounds(bounds);
+ bounds.addPoint(center);
+ circlePlane.recordBounds(bounds);
+ return bounds;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof GeoCircle))
+ return false;
+ GeoCircle other = (GeoCircle) o;
+ return other.center.equals(center) && other.cutoffAngle == cutoffAngle;
+ }
+
+ @Override
+ public int hashCode() {
+ int result;
+ long temp;
+ result = center.hashCode();
+ 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 + ")}";
+ }
}
Modified: lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCompositeMembershipShape.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCompositeMembershipShape.java?rev=1677595&r1=1677594&r2=1677595&view=diff
==============================================================================
--- lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCompositeMembershipShape.java (original)
+++ lucene/dev/branches/lucene6196/lucene/spatial/src/java/org/apache/lucene/spatial/spatial4j/geo3d/GeoCompositeMembershipShape.java Mon May 4 13:19:02 2015
@@ -20,103 +20,99 @@ package org.apache.lucene.spatial.spatia
import java.util.ArrayList;
import java.util.List;
-/** GeoComposite is a set of GeoMembershipShape's, treated as a unit.
-*/
-public class GeoCompositeMembershipShape implements GeoMembershipShape
-{
- protected final List<GeoMembershipShape> shapes = new ArrayList<GeoMembershipShape>();
-
- public GeoCompositeMembershipShape()
- {
- }
-
- /** Add a shape to the composite.
- */
- public void addShape(final GeoMembershipShape shape) {
- shapes.add(shape);
- }
-
- @Override
- public boolean isWithin(final Vector point)
- {
- //System.err.println("Checking whether point "+point+" is within Composite");
- for (GeoMembershipShape shape : shapes) {
- if (shape.isWithin(point)) {
- //System.err.println(" Point is within "+shape);
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean isWithin(final double x, final double y, final double z)
- {
- for (GeoMembershipShape shape : shapes) {
- if (shape.isWithin(x,y,z))
- return true;
- }
- return false;
- }
-
- @Override
- public GeoPoint[] getEdgePoints()
- {
- return shapes.get(0).getEdgePoints();
- }
-
- @Override
- public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
- {
- for (GeoMembershipShape shape : shapes) {
- if (shape.intersects(p,notablePoints,bounds))
- return true;
- }
- return false;
+/**
+ * GeoComposite is a set of GeoMembershipShape's, treated as a unit.
+ */
+public class GeoCompositeMembershipShape implements GeoMembershipShape {
+ protected final List<GeoMembershipShape> shapes = new ArrayList<GeoMembershipShape>();
+
+ public GeoCompositeMembershipShape() {
+ }
+
+ /**
+ * Add a shape to the composite.
+ */
+ public void addShape(final GeoMembershipShape shape) {
+ shapes.add(shape);
+ }
+
+ @Override
+ public boolean isWithin(final Vector point) {
+ //System.err.println("Checking whether point "+point+" is within Composite");
+ for (GeoMembershipShape shape : shapes) {
+ if (shape.isWithin(point)) {
+ //System.err.println(" Point is within "+shape);
+ return true;
+ }
}
+ return false;
+ }
- /** Compute longitude/latitude bounds for the shape.
- *@param bounds is the optional input bounds object. If this is null,
- * a bounds object will be created. Otherwise, the input object will be modified.
- *@return a Bounds object describing the shape's bounds. If the bounds cannot
- * be computed, then return a Bounds object with noLongitudeBound,
- * noTopLatitudeBound, and noBottomLatitudeBound.
- */
- @Override
- public Bounds getBounds(Bounds bounds)
- {
- if (bounds == null)
- bounds = new Bounds();
- for (GeoMembershipShape shape : shapes) {
- bounds = shape.getBounds(bounds);
- }
- return bounds;
+ @Override
+ public boolean isWithin(final double x, final double y, final double z) {
+ for (GeoMembershipShape shape : shapes) {
+ if (shape.isWithin(x, y, z))
+ return true;
}
+ return false;
+ }
- @Override
- public boolean equals(Object o)
- {
- if (!(o instanceof GeoCompositeMembershipShape))
- return false;
- GeoCompositeMembershipShape other = (GeoCompositeMembershipShape)o;
- if (other.shapes.size() != shapes.size())
- return false;
-
- for (int i = 0; i < shapes.size(); i++) {
- if (!other.shapes.get(i).equals(shapes.get(i)))
- return false;
- }
+ @Override
+ public GeoPoint[] getEdgePoints() {
+ return shapes.get(0).getEdgePoints();
+ }
+
+ @Override
+ public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
+ for (GeoMembershipShape shape : shapes) {
+ if (shape.intersects(p, notablePoints, bounds))
return true;
}
+ return false;
+ }
- @Override
- public int hashCode() {
- return shapes.hashCode();//TODO cache
- }
+ /**
+ * Compute longitude/latitude bounds for the shape.
+ *
+ * @param bounds is the optional input bounds object. If this is null,
+ * a bounds object will be created. Otherwise, the input object will be modified.
+ * @return a Bounds object describing the shape's bounds. If the bounds cannot
+ * be computed, then return a Bounds object with noLongitudeBound,
+ * noTopLatitudeBound, and noBottomLatitudeBound.
+ */
+ @Override
+ public Bounds getBounds(Bounds bounds) {
+ if (bounds == null)
+ bounds = new Bounds();
+ for (GeoMembershipShape shape : shapes) {
+ bounds = shape.getBounds(bounds);
+ }
+ return bounds;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof GeoCompositeMembershipShape))
+ return false;
+ GeoCompositeMembershipShape other = (GeoCompositeMembershipShape) o;
+ if (other.shapes.size() != shapes.size())
+ return false;
- @Override
- public String toString() {
- return "GeoCompositeMembershipShape: {" + shapes + '}';
+ for (int i = 0; i < shapes.size(); i++) {
+ if (!other.shapes.get(i).equals(shapes.get(i)))
+ return false;
}
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return shapes.hashCode();//TODO cache
+ }
+
+ @Override
+ public String toString() {
+ return "GeoCompositeMembershipShape: {" + shapes + '}';
+ }
}