mirror of
https://github.com/apache/lucene.git
synced 2025-02-09 19:45:22 +00:00
LUCENE-6196: Reformat code. Removed System.err & legacy comments in test. Fixed test compile warning.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene6196@1677595 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1b901cab9a
commit
55d46dc6d3
@ -17,7 +17,8 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** An object for accumulating bounds information.
|
/**
|
||||||
|
* An object for accumulating bounds information.
|
||||||
* The bounds object is initially empty. Bounding points
|
* The bounds object is initially empty. Bounding points
|
||||||
* are then applied by supplying (x,y,z) tuples. It is also
|
* are then applied by supplying (x,y,z) tuples. It is also
|
||||||
* possible to indicate the following edge cases:
|
* possible to indicate the following edge cases:
|
||||||
@ -27,8 +28,7 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* When any of these have been applied, further application of
|
* When any of these have been applied, further application of
|
||||||
* points cannot override that decision.
|
* points cannot override that decision.
|
||||||
*/
|
*/
|
||||||
public class Bounds
|
public class Bounds {
|
||||||
{
|
|
||||||
protected boolean noLongitudeBound = false;
|
protected boolean noLongitudeBound = false;
|
||||||
protected boolean noTopLatitudeBound = false;
|
protected boolean noTopLatitudeBound = false;
|
||||||
protected boolean noBottomLatitudeBound = false;
|
protected boolean noBottomLatitudeBound = false;
|
||||||
|
@ -17,10 +17,12 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** A GeoArea represents a standard 2-D breakdown of a part of sphere. It can
|
/**
|
||||||
|
* 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
|
* 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
|
* bounded at all. The purpose of the interface is to describe bounding shapes used for
|
||||||
* computation of geo hashes. */
|
* computation of geo hashes.
|
||||||
|
*/
|
||||||
public interface GeoArea extends Membership {
|
public interface GeoArea extends Membership {
|
||||||
// Since we don't know what each GeoArea's constraints are,
|
// Since we don't know what each GeoArea's constraints are,
|
||||||
// we put the onus on the GeoArea implementation to do the right thing.
|
// we put the onus on the GeoArea implementation to do the right thing.
|
||||||
@ -32,7 +34,8 @@ public interface GeoArea extends Membership {
|
|||||||
public static final int OVERLAPS = 2;
|
public static final int OVERLAPS = 2;
|
||||||
public static final int DISJOINT = 3;
|
public static final int DISJOINT = 3;
|
||||||
|
|
||||||
/** Find the spatial relationship between a shape and the current geo area.
|
/**
|
||||||
|
* 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
|
* 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
|
* other way around. For example, if this GeoArea is entirely within the
|
||||||
* shape, then CONTAINS should be returned. If the shape is entirely enclosed
|
* shape, then CONTAINS should be returned. If the shape is entirely enclosed
|
||||||
@ -41,6 +44,7 @@ public interface GeoArea extends Membership {
|
|||||||
* it is sometimes impossible to determine the distinction between
|
* it is sometimes impossible to determine the distinction between
|
||||||
* OVERLAPS and CONTAINS. In that case, OVERLAPS may be returned even
|
* OVERLAPS and CONTAINS. In that case, OVERLAPS may be returned even
|
||||||
* though the proper result would in fact be CONTAINS. Code accordingly.
|
* though the proper result would in fact be CONTAINS. Code accordingly.
|
||||||
|
*
|
||||||
* @param shape is the shape to consider.
|
* @param shape is the shape to consider.
|
||||||
* @return the relationship, from the perspective of the shape.
|
* @return the relationship, from the perspective of the shape.
|
||||||
*/
|
*/
|
||||||
|
@ -17,12 +17,13 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class GeoAreaFactory
|
public class GeoAreaFactory {
|
||||||
{
|
|
||||||
private GeoAreaFactory() {
|
private GeoAreaFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a GeoArea of the right kind given the specified bounds.
|
/**
|
||||||
|
* Create a GeoArea of the right kind given the specified bounds.
|
||||||
|
*
|
||||||
* @param topLat is the top latitude
|
* @param topLat is the top latitude
|
||||||
* @param bottomLat is the bottom latitude
|
* @param bottomLat is the bottom latitude
|
||||||
* @param leftLon is the left longitude
|
* @param leftLon is the left longitude
|
||||||
|
@ -17,13 +17,16 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** All bounding box shapes have this interface in common.
|
/**
|
||||||
|
* All bounding box shapes have this interface in common.
|
||||||
* This describes methods that bounding boxes have above and beyond
|
* This describes methods that bounding boxes have above and beyond
|
||||||
* GeoMembershipShape's.
|
* GeoMembershipShape's.
|
||||||
*/
|
*/
|
||||||
public interface GeoBBox extends GeoMembershipShape, GeoSizeable, GeoArea {
|
public interface GeoBBox extends GeoMembershipShape, GeoSizeable, GeoArea {
|
||||||
|
|
||||||
/** Expand box by specified angle.
|
/**
|
||||||
|
* Expand box by specified angle.
|
||||||
|
*
|
||||||
* @param angle is the angle amount to expand the GeoBBox by.
|
* @param angle is the angle amount to expand the GeoBBox by.
|
||||||
* @return a new GeoBBox.
|
* @return a new GeoBBox.
|
||||||
*/
|
*/
|
||||||
|
@ -17,7 +17,8 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** All bounding box shapes can derive from this base class, which furnishes
|
/**
|
||||||
|
* All bounding box shapes can derive from this base class, which furnishes
|
||||||
* some common code
|
* some common code
|
||||||
*/
|
*/
|
||||||
public abstract class GeoBBoxBase implements GeoBBox {
|
public abstract class GeoBBoxBase implements GeoBBox {
|
||||||
|
@ -17,12 +17,13 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class GeoBBoxFactory
|
public class GeoBBoxFactory {
|
||||||
{
|
|
||||||
private GeoBBoxFactory() {
|
private GeoBBoxFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a geobbox of the right kind given the specified bounds.
|
/**
|
||||||
|
* Create a geobbox of the right kind given the specified bounds.
|
||||||
|
*
|
||||||
* @param topLat is the top latitude
|
* @param topLat is the top latitude
|
||||||
* @param bottomLat is the bottom latitude
|
* @param bottomLat is the bottom latitude
|
||||||
* @param leftLon is the left longitude
|
* @param leftLon is the left longitude
|
||||||
|
@ -17,25 +17,28 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Base extended shape object.
|
/**
|
||||||
|
* Base extended shape object.
|
||||||
*/
|
*/
|
||||||
public abstract class GeoBaseExtendedShape implements GeoShape
|
public abstract class GeoBaseExtendedShape implements GeoShape {
|
||||||
{
|
|
||||||
protected final static GeoPoint NORTH_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);
|
protected final static GeoPoint SOUTH_POLE = new GeoPoint(0.0, 0.0, -1.0);
|
||||||
|
|
||||||
public GeoBaseExtendedShape()
|
public GeoBaseExtendedShape() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if a point is within this shape.
|
/**
|
||||||
|
* Check if a point is within this shape.
|
||||||
|
*
|
||||||
* @param point is the point to check.
|
* @param point is the point to check.
|
||||||
* @return true if the point is within this shape
|
* @return true if the point is within this shape
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean isWithin(final Vector point);
|
public abstract boolean isWithin(final Vector point);
|
||||||
|
|
||||||
/** Check if a point is within this shape.
|
/**
|
||||||
|
* Check if a point is within this shape.
|
||||||
|
*
|
||||||
* @param x is x coordinate of point to check.
|
* @param x is x coordinate of point to check.
|
||||||
* @param y is y coordinate of point to check.
|
* @param y is y coordinate of point to check.
|
||||||
* @param z is z coordinate of point to check.
|
* @param z is z coordinate of point to check.
|
||||||
@ -44,14 +47,18 @@ public abstract class GeoBaseExtendedShape implements GeoShape
|
|||||||
@Override
|
@Override
|
||||||
public abstract boolean isWithin(final double x, final double y, final double z);
|
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 sample point that is on the edge of the shape.
|
||||||
|
*
|
||||||
* @return a number of edge points, one for each disconnected edge.
|
* @return a number of edge points, one for each disconnected edge.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public abstract GeoPoint[] getEdgePoints();
|
public abstract GeoPoint[] getEdgePoints();
|
||||||
|
|
||||||
/** Assess whether a plane, within the provided bounds, intersects
|
/**
|
||||||
|
* Assess whether a plane, within the provided bounds, intersects
|
||||||
* with the shape.
|
* with the shape.
|
||||||
|
*
|
||||||
* @param plane is the plane to assess for intersection with the shape's edges or
|
* @param plane is the plane to assess for intersection with the shape's edges or
|
||||||
* bounding curves.
|
* bounding curves.
|
||||||
* @param bounds are a set of bounds that define an area that an
|
* @param bounds are a set of bounds that define an area that an
|
||||||
@ -61,7 +68,9 @@ public abstract class GeoBaseExtendedShape implements GeoShape
|
|||||||
@Override
|
@Override
|
||||||
public abstract boolean intersects(final Plane plane, final GeoPoint[] notablePoints, final Membership... bounds);
|
public abstract boolean intersects(final Plane plane, final GeoPoint[] notablePoints, final Membership... bounds);
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -69,8 +78,7 @@ public abstract class GeoBaseExtendedShape implements GeoShape
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
if (isWithin(NORTH_POLE)) {
|
if (isWithin(NORTH_POLE)) {
|
||||||
|
@ -17,10 +17,10 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Circular area with a center and radius.
|
/**
|
||||||
|
* Circular area with a center and radius.
|
||||||
*/
|
*/
|
||||||
public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape, GeoSizeable
|
public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape, GeoSizeable {
|
||||||
{
|
|
||||||
public final GeoPoint center;
|
public final GeoPoint center;
|
||||||
public final double cutoffAngle;
|
public final double cutoffAngle;
|
||||||
public final double cutoffNormalDistance;
|
public final double cutoffNormalDistance;
|
||||||
@ -29,8 +29,7 @@ public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape,
|
|||||||
public final GeoPoint[] edgePoints;
|
public final GeoPoint[] edgePoints;
|
||||||
public static final GeoPoint[] circlePoints = new GeoPoint[0];
|
public static final GeoPoint[] circlePoints = new GeoPoint[0];
|
||||||
|
|
||||||
public GeoCircle(final double lat, final double lon, final double cutoffAngle)
|
public GeoCircle(final double lat, final double lon, final double cutoffAngle) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
if (lat < -Math.PI * 0.5 || lat > Math.PI * 0.5)
|
if (lat < -Math.PI * 0.5 || lat > Math.PI * 0.5)
|
||||||
throw new IllegalArgumentException("Latitude out of bounds");
|
throw new IllegalArgumentException("Latitude out of bounds");
|
||||||
@ -74,7 +73,9 @@ public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape,
|
|||||||
return cutoffAngle;
|
return cutoffAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -82,110 +83,110 @@ public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape,
|
|||||||
return center;
|
return center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute an estimate of "distance" to the GeoPoint.
|
/**
|
||||||
|
* Compute an estimate of "distance" to the GeoPoint.
|
||||||
* A return value of Double.MAX_VALUE should be returned for
|
* A return value of Double.MAX_VALUE should be returned for
|
||||||
* points outside of the shape.
|
* points outside of the shape.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeNormalDistance(final GeoPoint point)
|
public double computeNormalDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
double normalDistance = this.center.normalDistance(point);
|
double normalDistance = this.center.normalDistance(point);
|
||||||
if (normalDistance > cutoffNormalDistance)
|
if (normalDistance > cutoffNormalDistance)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return normalDistance;
|
return normalDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute an estimate of "distance" to the GeoPoint.
|
/**
|
||||||
|
* Compute an estimate of "distance" to the GeoPoint.
|
||||||
* A return value of Double.MAX_VALUE should be returned for
|
* A return value of Double.MAX_VALUE should be returned for
|
||||||
* points outside of the shape.
|
* points outside of the shape.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeNormalDistance(final double x, final double y, final double z)
|
public double computeNormalDistance(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
double normalDistance = this.center.normalDistance(x, y, z);
|
double normalDistance = this.center.normalDistance(x, y, z);
|
||||||
if (normalDistance > cutoffNormalDistance)
|
if (normalDistance > cutoffNormalDistance)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return normalDistance;
|
return normalDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a squared estimate of the "distance" to the
|
/**
|
||||||
|
* Compute a squared estimate of the "distance" to the
|
||||||
* GeoPoint. Double.MAX_VALUE indicates a point outside of the
|
* GeoPoint. Double.MAX_VALUE indicates a point outside of the
|
||||||
* shape.
|
* shape.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeSquaredNormalDistance(final GeoPoint point)
|
public double computeSquaredNormalDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
double normalDistanceSquared = this.center.normalDistanceSquared(point);
|
double normalDistanceSquared = this.center.normalDistanceSquared(point);
|
||||||
if (normalDistanceSquared > cutoffNormalDistance * cutoffNormalDistance)
|
if (normalDistanceSquared > cutoffNormalDistance * cutoffNormalDistance)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return normalDistanceSquared;
|
return normalDistanceSquared;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a squared estimate of the "distance" to the
|
/**
|
||||||
|
* Compute a squared estimate of the "distance" to the
|
||||||
* GeoPoint. Double.MAX_VALUE indicates a point outside of the
|
* GeoPoint. Double.MAX_VALUE indicates a point outside of the
|
||||||
* shape.
|
* shape.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeSquaredNormalDistance(final double x, final double y, final double z)
|
public double computeSquaredNormalDistance(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
double normalDistanceSquared = this.center.normalDistanceSquared(x, y, z);
|
double normalDistanceSquared = this.center.normalDistanceSquared(x, y, z);
|
||||||
if (normalDistanceSquared > cutoffNormalDistance * cutoffNormalDistance)
|
if (normalDistanceSquared > cutoffNormalDistance * cutoffNormalDistance)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return normalDistanceSquared;
|
return normalDistanceSquared;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a linear distance to the vector.
|
/**
|
||||||
|
* Compute a linear distance to the vector.
|
||||||
* return Double.MAX_VALUE for points outside the shape.
|
* return Double.MAX_VALUE for points outside the shape.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeLinearDistance(final GeoPoint point)
|
public double computeLinearDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
double linearDistance = this.center.linearDistance(point);
|
double linearDistance = this.center.linearDistance(point);
|
||||||
if (linearDistance > cutoffLinearDistance)
|
if (linearDistance > cutoffLinearDistance)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return linearDistance;
|
return linearDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a linear distance to the vector.
|
/**
|
||||||
|
* Compute a linear distance to the vector.
|
||||||
* return Double.MAX_VALUE for points outside the shape.
|
* return Double.MAX_VALUE for points outside the shape.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeLinearDistance(final double x, final double y, final double z)
|
public double computeLinearDistance(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
double linearDistance = this.center.linearDistance(x, y, z);
|
double linearDistance = this.center.linearDistance(x, y, z);
|
||||||
if (linearDistance > cutoffLinearDistance)
|
if (linearDistance > cutoffLinearDistance)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return linearDistance;
|
return linearDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a squared linear distance to the vector.
|
/**
|
||||||
|
* Compute a squared linear distance to the vector.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeSquaredLinearDistance(final GeoPoint point)
|
public double computeSquaredLinearDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
double linearDistanceSquared = this.center.linearDistanceSquared(point);
|
double linearDistanceSquared = this.center.linearDistanceSquared(point);
|
||||||
if (linearDistanceSquared > cutoffLinearDistance * cutoffLinearDistance)
|
if (linearDistanceSquared > cutoffLinearDistance * cutoffLinearDistance)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return linearDistanceSquared;
|
return linearDistanceSquared;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a squared linear distance to the vector.
|
/**
|
||||||
|
* Compute a squared linear distance to the vector.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeSquaredLinearDistance(final double x, final double y, final double z)
|
public double computeSquaredLinearDistance(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
double linearDistanceSquared = this.center.linearDistanceSquared(x, y, z);
|
double linearDistanceSquared = this.center.linearDistanceSquared(x, y, z);
|
||||||
if (linearDistanceSquared > cutoffLinearDistance * cutoffLinearDistance)
|
if (linearDistanceSquared > cutoffLinearDistance * cutoffLinearDistance)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return linearDistanceSquared;
|
return linearDistanceSquared;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a true, accurate, great-circle distance.
|
/**
|
||||||
|
* Compute a true, accurate, great-circle distance.
|
||||||
* Double.MAX_VALUE indicates a point is outside of the shape.
|
* Double.MAX_VALUE indicates a point is outside of the shape.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeArcDistance(final GeoPoint point)
|
public double computeArcDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
double dist = this.center.arcDistance(point);
|
double dist = this.center.arcDistance(point);
|
||||||
if (dist > cutoffAngle)
|
if (dist > cutoffAngle)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
@ -193,32 +194,30 @@ public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
// Fastest way of determining membership
|
// Fastest way of determining membership
|
||||||
return circlePlane.isWithin(point);
|
return circlePlane.isWithin(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
// Fastest way of determining membership
|
// Fastest way of determining membership
|
||||||
return circlePlane.isWithin(x, y, z);
|
return circlePlane.isWithin(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
return circlePlane.intersects(p, notablePoints, circlePoints, bounds);
|
return circlePlane.intersects(p, notablePoints, circlePoints, bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -226,8 +225,7 @@ public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape,
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
bounds = super.getBounds(bounds);
|
bounds = super.getBounds(bounds);
|
||||||
bounds.addPoint(center);
|
bounds.addPoint(center);
|
||||||
circlePlane.recordBounds(bounds);
|
circlePlane.recordBounds(bounds);
|
||||||
@ -235,8 +233,7 @@ public class GeoCircle extends GeoBaseExtendedShape implements GeoDistanceShape,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoCircle))
|
if (!(o instanceof GeoCircle))
|
||||||
return false;
|
return false;
|
||||||
GeoCircle other = (GeoCircle) o;
|
GeoCircle other = (GeoCircle) o;
|
||||||
|
@ -20,25 +20,24 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** GeoComposite is a set of GeoMembershipShape's, treated as a unit.
|
/**
|
||||||
|
* GeoComposite is a set of GeoMembershipShape's, treated as a unit.
|
||||||
*/
|
*/
|
||||||
public class GeoCompositeMembershipShape implements GeoMembershipShape
|
public class GeoCompositeMembershipShape implements GeoMembershipShape {
|
||||||
{
|
|
||||||
protected final List<GeoMembershipShape> shapes = new ArrayList<GeoMembershipShape>();
|
protected final List<GeoMembershipShape> shapes = new ArrayList<GeoMembershipShape>();
|
||||||
|
|
||||||
public GeoCompositeMembershipShape()
|
public GeoCompositeMembershipShape() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add a shape to the composite.
|
/**
|
||||||
|
* Add a shape to the composite.
|
||||||
*/
|
*/
|
||||||
public void addShape(final GeoMembershipShape shape) {
|
public void addShape(final GeoMembershipShape shape) {
|
||||||
shapes.add(shape);
|
shapes.add(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
//System.err.println("Checking whether point "+point+" is within Composite");
|
//System.err.println("Checking whether point "+point+" is within Composite");
|
||||||
for (GeoMembershipShape shape : shapes) {
|
for (GeoMembershipShape shape : shapes) {
|
||||||
if (shape.isWithin(point)) {
|
if (shape.isWithin(point)) {
|
||||||
@ -50,8 +49,7 @@ public class GeoCompositeMembershipShape implements GeoMembershipShape
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
for (GeoMembershipShape shape : shapes) {
|
for (GeoMembershipShape shape : shapes) {
|
||||||
if (shape.isWithin(x, y, z))
|
if (shape.isWithin(x, y, z))
|
||||||
return true;
|
return true;
|
||||||
@ -60,14 +58,12 @@ public class GeoCompositeMembershipShape implements GeoMembershipShape
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return shapes.get(0).getEdgePoints();
|
return shapes.get(0).getEdgePoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
for (GeoMembershipShape shape : shapes) {
|
for (GeoMembershipShape shape : shapes) {
|
||||||
if (shape.intersects(p, notablePoints, bounds))
|
if (shape.intersects(p, notablePoints, bounds))
|
||||||
return true;
|
return true;
|
||||||
@ -75,7 +71,9 @@ public class GeoCompositeMembershipShape implements GeoMembershipShape
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -83,8 +81,7 @@ public class GeoCompositeMembershipShape implements GeoMembershipShape
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
for (GeoMembershipShape shape : shapes) {
|
for (GeoMembershipShape shape : shapes) {
|
||||||
@ -94,8 +91,7 @@ public class GeoCompositeMembershipShape implements GeoMembershipShape
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoCompositeMembershipShape))
|
if (!(o instanceof GeoCompositeMembershipShape))
|
||||||
return false;
|
return false;
|
||||||
GeoCompositeMembershipShape other = (GeoCompositeMembershipShape) o;
|
GeoCompositeMembershipShape other = (GeoCompositeMembershipShape) o;
|
||||||
|
@ -21,13 +21,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** GeoConvexPolygon objects are generic building blocks of more complex structures.
|
/**
|
||||||
|
* GeoConvexPolygon objects are generic building blocks of more complex structures.
|
||||||
* The only restrictions on these objects are: (1) they must be convex; (2) they must have
|
* The only restrictions on these objects are: (1) they must be convex; (2) they must have
|
||||||
* a maximum extent no larger than PI. Violating either one of these limits will
|
* a maximum extent no larger than PI. Violating either one of these limits will
|
||||||
* cause the logic to fail.
|
* cause the logic to fail.
|
||||||
*/
|
*/
|
||||||
public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembershipShape
|
public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembershipShape {
|
||||||
{
|
|
||||||
protected final List<GeoPoint> points;
|
protected final List<GeoPoint> points;
|
||||||
protected final BitSet isInternalEdges;
|
protected final BitSet isInternalEdges;
|
||||||
|
|
||||||
@ -39,7 +39,8 @@ public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembers
|
|||||||
|
|
||||||
protected double fullDistance = 0.0;
|
protected double fullDistance = 0.0;
|
||||||
|
|
||||||
/** Create a convex polygon from a list of points. The first point must be on the
|
/**
|
||||||
|
* Create a convex polygon from a list of points. The first point must be on the
|
||||||
* external edge.
|
* external edge.
|
||||||
*/
|
*/
|
||||||
public GeoConvexPolygon(final List<GeoPoint> pointList) {
|
public GeoConvexPolygon(final List<GeoPoint> pointList) {
|
||||||
@ -48,7 +49,8 @@ public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembers
|
|||||||
donePoints(false);
|
donePoints(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a convex polygon from a list of points, keeping track of which boundaries
|
/**
|
||||||
|
* 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.
|
* 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 List<GeoPoint> pointList, final BitSet internalEdgeFlags, final boolean returnEdgeInternal) {
|
||||||
@ -57,11 +59,11 @@ public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembers
|
|||||||
donePoints(returnEdgeInternal);
|
donePoints(returnEdgeInternal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a convex polygon, with a starting latitude and longitude.
|
/**
|
||||||
|
* 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}
|
* 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 double startLatitude, final double startLongitude) {
|
||||||
{
|
|
||||||
points = new ArrayList<GeoPoint>();
|
points = new ArrayList<GeoPoint>();
|
||||||
isInternalEdges = new BitSet();
|
isInternalEdges = new BitSet();
|
||||||
// Argument checking
|
// Argument checking
|
||||||
@ -74,8 +76,10 @@ public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembers
|
|||||||
points.add(p);
|
points.add(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add a point to the polygon.
|
/**
|
||||||
|
* Add a point to the polygon.
|
||||||
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}
|
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}
|
||||||
|
*
|
||||||
* @param latitude is the latitude of the next point.
|
* @param latitude is the latitude of the next point.
|
||||||
* @param longitude is the longitude of the next point.
|
* @param longitude is the longitude of the next point.
|
||||||
* @param isInternalEdge is true if the edge just added should be considered "internal", and not
|
* @param isInternalEdge is true if the edge just added should be considered "internal", and not
|
||||||
@ -93,7 +97,8 @@ public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembers
|
|||||||
points.add(p);
|
points.add(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Finish the polygon, by connecting the last added point with the starting point.
|
/**
|
||||||
|
* Finish the polygon, by connecting the last added point with the starting point.
|
||||||
*/
|
*/
|
||||||
public void donePoints(final boolean isInternalReturnEdge) {
|
public void donePoints(final boolean isInternalReturnEdge) {
|
||||||
// If fewer than 3 points, can't do it.
|
// If fewer than 3 points, can't do it.
|
||||||
@ -145,8 +150,7 @@ public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembers
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
for (final SidedPlane edge : edges) {
|
for (final SidedPlane edge : edges) {
|
||||||
if (!edge.isWithin(point))
|
if (!edge.isWithin(point))
|
||||||
return false;
|
return false;
|
||||||
@ -155,8 +159,7 @@ public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembers
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
for (final SidedPlane edge : edges) {
|
for (final SidedPlane edge : edges) {
|
||||||
if (!edge.isWithin(x, y, z))
|
if (!edge.isWithin(x, y, z))
|
||||||
return false;
|
return false;
|
||||||
@ -165,14 +168,12 @@ public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembers
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
//System.err.println("Checking for polygon intersection with plane "+p+"...");
|
//System.err.println("Checking for polygon intersection with plane "+p+"...");
|
||||||
for (int edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
|
for (int edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
|
||||||
final SidedPlane edge = edges[edgeIndex];
|
final SidedPlane edge = edges[edgeIndex];
|
||||||
@ -198,7 +199,9 @@ public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembers
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -206,8 +209,7 @@ public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembers
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
bounds = super.getBounds(bounds);
|
bounds = super.getBounds(bounds);
|
||||||
|
|
||||||
// Add all the points
|
// Add all the points
|
||||||
@ -237,8 +239,7 @@ public class GeoConvexPolygon extends GeoBaseExtendedShape implements GeoMembers
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoConvexPolygon))
|
if (!(o instanceof GeoConvexPolygon))
|
||||||
return false;
|
return false;
|
||||||
GeoConvexPolygon other = (GeoConvexPolygon) o;
|
GeoConvexPolygon other = (GeoConvexPolygon) o;
|
||||||
|
@ -17,12 +17,12 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Degenerate bounding box limited on two sides (left lon, right lon).
|
/**
|
||||||
|
* Degenerate bounding box limited on two sides (left lon, right lon).
|
||||||
* The left-right maximum extent for this shape is PI; for anything larger, use
|
* The left-right maximum extent for this shape is PI; for anything larger, use
|
||||||
* GeoWideDegenerateHorizontalLine.
|
* GeoWideDegenerateHorizontalLine.
|
||||||
*/
|
*/
|
||||||
public class GeoDegenerateHorizontalLine extends GeoBBoxBase
|
public class GeoDegenerateHorizontalLine extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double latitude;
|
public final double latitude;
|
||||||
public final double leftLon;
|
public final double leftLon;
|
||||||
public final double rightLon;
|
public final double rightLon;
|
||||||
@ -39,9 +39,10 @@ public class GeoDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
public final GeoPoint centerPoint;
|
public final GeoPoint centerPoint;
|
||||||
public final GeoPoint[] edgePoints;
|
public final GeoPoint[] edgePoints;
|
||||||
|
|
||||||
/** 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)
|
* 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) {
|
||||||
// Argument checking
|
// Argument checking
|
||||||
if (latitude > Math.PI * 0.5 || latitude < -Math.PI * 0.5)
|
if (latitude > Math.PI * 0.5 || latitude < -Math.PI * 0.5)
|
||||||
throw new IllegalArgumentException("Latitude out of range");
|
throw new IllegalArgumentException("Latitude out of range");
|
||||||
@ -91,8 +92,7 @@ public class GeoDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
double newTopLat = latitude + angle;
|
double newTopLat = latitude + angle;
|
||||||
double newBottomLat = latitude - angle;
|
double newBottomLat = latitude - angle;
|
||||||
// Figuring out when we escalate to a special case requires some prefiguring
|
// Figuring out when we escalate to a special case requires some prefiguring
|
||||||
@ -109,30 +109,29 @@ public class GeoDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return plane.evaluateIsZero(point) &&
|
return plane.evaluateIsZero(point) &&
|
||||||
leftPlane.isWithin(point) &&
|
leftPlane.isWithin(point) &&
|
||||||
rightPlane.isWithin(point);
|
rightPlane.isWithin(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return plane.evaluateIsZero(x, y, z) &&
|
return plane.evaluateIsZero(x, y, z) &&
|
||||||
leftPlane.isWithin(x, y, z) &&
|
leftPlane.isWithin(x, y, z) &&
|
||||||
rightPlane.isWithin(x, y, z);
|
rightPlane.isWithin(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
double topAngle = centerPoint.arcDistance(RHC);
|
double topAngle = centerPoint.arcDistance(RHC);
|
||||||
double bottomAngle = centerPoint.arcDistance(LHC);
|
double bottomAngle = centerPoint.arcDistance(LHC);
|
||||||
return Math.max(topAngle, bottomAngle);
|
return Math.max(topAngle, bottomAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -141,18 +140,18 @@ public class GeoDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
return p.intersects(plane, notablePoints, planePoints, bounds, leftPlane, rightPlane);
|
return p.intersects(plane, notablePoints, planePoints, bounds, leftPlane, rightPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -160,8 +159,7 @@ public class GeoDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.addLatitudeZone(latitude).addLongitudeSlice(leftLon, rightLon);
|
bounds.addLatitudeZone(latitude).addLongitudeSlice(leftLon, rightLon);
|
||||||
@ -180,8 +178,7 @@ public class GeoDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoDegenerateHorizontalLine))
|
if (!(o instanceof GeoDegenerateHorizontalLine))
|
||||||
return false;
|
return false;
|
||||||
GeoDegenerateHorizontalLine other = (GeoDegenerateHorizontalLine) o;
|
GeoDegenerateHorizontalLine other = (GeoDegenerateHorizontalLine) o;
|
||||||
|
@ -17,11 +17,11 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** This GeoBBox represents an area rectangle of one specific latitude with
|
/**
|
||||||
|
* This GeoBBox represents an area rectangle of one specific latitude with
|
||||||
* no longitude bounds.
|
* no longitude bounds.
|
||||||
*/
|
*/
|
||||||
public class GeoDegenerateLatitudeZone extends GeoBBoxBase
|
public class GeoDegenerateLatitudeZone extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double latitude;
|
public final double latitude;
|
||||||
|
|
||||||
public final double sinLatitude;
|
public final double sinLatitude;
|
||||||
@ -30,8 +30,7 @@ public class GeoDegenerateLatitudeZone extends GeoBBoxBase
|
|||||||
public final GeoPoint[] edgePoints;
|
public final GeoPoint[] edgePoints;
|
||||||
public final static GeoPoint[] planePoints = new GeoPoint[0];
|
public final static GeoPoint[] planePoints = new GeoPoint[0];
|
||||||
|
|
||||||
public GeoDegenerateLatitudeZone(final double latitude)
|
public GeoDegenerateLatitudeZone(final double latitude) {
|
||||||
{
|
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
|
|
||||||
this.sinLatitude = Math.sin(latitude);
|
this.sinLatitude = Math.sin(latitude);
|
||||||
@ -43,32 +42,30 @@ public class GeoDegenerateLatitudeZone extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
double newTopLat = latitude + angle;
|
double newTopLat = latitude + angle;
|
||||||
double newBottomLat = latitude - angle;
|
double newBottomLat = latitude - angle;
|
||||||
return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, -Math.PI, Math.PI);
|
return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, -Math.PI, Math.PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return Math.abs(point.z - this.sinLatitude) < 1e-10;
|
return Math.abs(point.z - this.sinLatitude) < 1e-10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return Math.abs(z - this.sinLatitude) < 1e-10;
|
return Math.abs(z - this.sinLatitude) < 1e-10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
return Math.PI;
|
return Math.PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -78,18 +75,18 @@ public class GeoDegenerateLatitudeZone extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
return p.intersects(plane, notablePoints, planePoints, bounds);
|
return p.intersects(plane, notablePoints, planePoints, bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -97,8 +94,7 @@ public class GeoDegenerateLatitudeZone extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.noLongitudeBound().addLatitudeZone(latitude);
|
bounds.noLongitudeBound().addLatitudeZone(latitude);
|
||||||
@ -123,8 +119,7 @@ public class GeoDegenerateLatitudeZone extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoDegenerateLatitudeZone))
|
if (!(o instanceof GeoDegenerateLatitudeZone))
|
||||||
return false;
|
return false;
|
||||||
GeoDegenerateLatitudeZone other = (GeoDegenerateLatitudeZone) o;
|
GeoDegenerateLatitudeZone other = (GeoDegenerateLatitudeZone) o;
|
||||||
|
@ -17,10 +17,10 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Degenerate longitude slice.
|
/**
|
||||||
|
* Degenerate longitude slice.
|
||||||
*/
|
*/
|
||||||
public class GeoDegenerateLongitudeSlice extends GeoBBoxBase
|
public class GeoDegenerateLongitudeSlice extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double longitude;
|
public final double longitude;
|
||||||
|
|
||||||
public final double sinLongitude;
|
public final double sinLongitude;
|
||||||
@ -32,9 +32,10 @@ public class GeoDegenerateLongitudeSlice extends GeoBBoxBase
|
|||||||
|
|
||||||
public final static GeoPoint[] planePoints = new GeoPoint[]{NORTH_POLE, SOUTH_POLE};
|
public final static GeoPoint[] planePoints = new GeoPoint[]{NORTH_POLE, SOUTH_POLE};
|
||||||
|
|
||||||
/** Accepts only values in the following ranges: lon: {@code -PI -> PI} */
|
/**
|
||||||
public GeoDegenerateLongitudeSlice(final double longitude)
|
* Accepts only values in the following ranges: lon: {@code -PI -> PI}
|
||||||
{
|
*/
|
||||||
|
public GeoDegenerateLongitudeSlice(final double longitude) {
|
||||||
// Argument checking
|
// Argument checking
|
||||||
if (longitude < -Math.PI || longitude > Math.PI)
|
if (longitude < -Math.PI || longitude > Math.PI)
|
||||||
throw new IllegalArgumentException("Longitude out of range");
|
throw new IllegalArgumentException("Longitude out of range");
|
||||||
@ -51,8 +52,7 @@ public class GeoDegenerateLongitudeSlice extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
// Figuring out when we escalate to a special case requires some prefiguring
|
// Figuring out when we escalate to a special case requires some prefiguring
|
||||||
double newLeftLon = longitude - angle;
|
double newLeftLon = longitude - angle;
|
||||||
double newRightLon = longitude + angle;
|
double newRightLon = longitude + angle;
|
||||||
@ -65,26 +65,25 @@ public class GeoDegenerateLongitudeSlice extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return plane.evaluateIsZero(point) &&
|
return plane.evaluateIsZero(point) &&
|
||||||
boundingPlane.isWithin(point);
|
boundingPlane.isWithin(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return plane.evaluateIsZero(x, y, z) &&
|
return plane.evaluateIsZero(x, y, z) &&
|
||||||
boundingPlane.isWithin(x, y, z);
|
boundingPlane.isWithin(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
return Math.PI * 0.5;
|
return Math.PI * 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -93,18 +92,18 @@ public class GeoDegenerateLongitudeSlice extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
return p.intersects(plane, notablePoints, planePoints, bounds, boundingPlane);
|
return p.intersects(plane, notablePoints, planePoints, bounds, boundingPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -112,8 +111,7 @@ public class GeoDegenerateLongitudeSlice extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.noTopLatitudeBound().noBottomLatitudeBound();
|
bounds.noTopLatitudeBound().noBottomLatitudeBound();
|
||||||
@ -134,8 +132,7 @@ public class GeoDegenerateLongitudeSlice extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoDegenerateLongitudeSlice))
|
if (!(o instanceof GeoDegenerateLongitudeSlice))
|
||||||
return false;
|
return false;
|
||||||
GeoDegenerateLongitudeSlice other = (GeoDegenerateLongitudeSlice) o;
|
GeoDegenerateLongitudeSlice other = (GeoDegenerateLongitudeSlice) o;
|
||||||
|
@ -17,24 +17,25 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** This class represents a degenerate point bounding box.
|
/**
|
||||||
|
* This class represents a degenerate point bounding box.
|
||||||
* It is not a simple GeoPoint because we must have the latitude and longitude.
|
* It is not a simple GeoPoint because we must have the latitude and longitude.
|
||||||
*/
|
*/
|
||||||
public class GeoDegeneratePoint extends GeoPoint implements GeoBBox
|
public class GeoDegeneratePoint extends GeoPoint implements GeoBBox {
|
||||||
{
|
|
||||||
public final double latitude;
|
public final double latitude;
|
||||||
public final double longitude;
|
public final double longitude;
|
||||||
public final GeoPoint[] edgePoints;
|
public final GeoPoint[] edgePoints;
|
||||||
|
|
||||||
public GeoDegeneratePoint(final double lat, final double lon)
|
public GeoDegeneratePoint(final double lat, final double lon) {
|
||||||
{
|
|
||||||
super(lat, lon);
|
super(lat, lon);
|
||||||
this.latitude = lat;
|
this.latitude = lat;
|
||||||
this.longitude = lon;
|
this.longitude = lon;
|
||||||
this.edgePoints = new GeoPoint[]{this};
|
this.edgePoints = new GeoPoint[]{this};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Expand box by specified angle.
|
/**
|
||||||
|
* Expand box by specified angle.
|
||||||
|
*
|
||||||
* @param angle is the angle amount to expand the GeoBBox by.
|
* @param angle is the angle amount to expand the GeoBBox by.
|
||||||
* @return a new GeoBBox.
|
* @return a new GeoBBox.
|
||||||
*/
|
*/
|
||||||
@ -47,7 +48,9 @@ public class GeoDegeneratePoint extends GeoPoint implements GeoBBox
|
|||||||
return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, newLeftLon, newRightLon);
|
return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, newLeftLon, newRightLon);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return a sample point that is on the edge of the shape.
|
/**
|
||||||
|
* Return a sample point that is on the edge of the shape.
|
||||||
|
*
|
||||||
* @return an interior point.
|
* @return an interior point.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -55,8 +58,10 @@ public class GeoDegeneratePoint extends GeoPoint implements GeoBBox
|
|||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Assess whether a plane, within the provided bounds, intersects
|
/**
|
||||||
|
* Assess whether a plane, within the provided bounds, intersects
|
||||||
* with the shape.
|
* with the shape.
|
||||||
|
*
|
||||||
* @param plane is the plane to assess for intersection with the shape's edges or
|
* @param plane is the plane to assess for intersection with the shape's edges or
|
||||||
* bounding curves.
|
* bounding curves.
|
||||||
* @param bounds are a set of bounds that define an area that an
|
* @param bounds are a set of bounds that define an area that an
|
||||||
@ -75,7 +80,9 @@ public class GeoDegeneratePoint extends GeoPoint implements GeoBBox
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -90,7 +97,9 @@ public class GeoDegeneratePoint extends GeoPoint implements GeoBBox
|
|||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Equals */
|
/**
|
||||||
|
* Equals
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (!(o instanceof GeoDegeneratePoint))
|
if (!(o instanceof GeoDegeneratePoint))
|
||||||
@ -115,7 +124,9 @@ public class GeoDegeneratePoint extends GeoPoint implements GeoBBox
|
|||||||
return "GeoDegeneratePoint: {lat=" + latitude + "(" + latitude * 180.0 / Math.PI + "), lon=" + longitude + "(" + longitude * 180.0 / Math.PI + ")}";
|
return "GeoDegeneratePoint: {lat=" + latitude + "(" + latitude * 180.0 / Math.PI + "), lon=" + longitude + "(" + longitude * 180.0 / Math.PI + ")}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if a point is within this shape.
|
/**
|
||||||
|
* Check if a point is within this shape.
|
||||||
|
*
|
||||||
* @param point is the point to check.
|
* @param point is the point to check.
|
||||||
* @return true if the point is within this shape
|
* @return true if the point is within this shape
|
||||||
*/
|
*/
|
||||||
@ -124,7 +135,9 @@ public class GeoDegeneratePoint extends GeoPoint implements GeoBBox
|
|||||||
return isWithin(point.x, point.y, point.z);
|
return isWithin(point.x, point.y, point.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if a point is within this shape.
|
/**
|
||||||
|
* Check if a point is within this shape.
|
||||||
|
*
|
||||||
* @param x is x coordinate of point to check.
|
* @param x is x coordinate of point to check.
|
||||||
* @param y is y coordinate of point to check.
|
* @param y is y coordinate of point to check.
|
||||||
* @param z is z coordinate of point to check.
|
* @param z is z coordinate of point to check.
|
||||||
@ -135,8 +148,10 @@ public class GeoDegeneratePoint extends GeoPoint implements GeoBBox
|
|||||||
return x == this.x && y == this.y && z == this.z;
|
return x == this.x && y == this.y && z == this.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the radius of a circle into which the GeoSizeable area can
|
/**
|
||||||
|
* Returns the radius of a circle into which the GeoSizeable area can
|
||||||
* be inscribed.
|
* be inscribed.
|
||||||
|
*
|
||||||
* @return the radius.
|
* @return the radius.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -144,7 +159,9 @@ public class GeoDegeneratePoint extends GeoPoint implements GeoBBox
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -152,11 +169,13 @@ public class GeoDegeneratePoint extends GeoPoint implements GeoBBox
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Find the spatial relationship between a shape and the current geo area.
|
/**
|
||||||
|
* 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
|
* 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
|
* other way around. For example, if this GeoArea is entirely within the
|
||||||
* shape, then CONTAINS should be returned. If the shape is entirely enclosed
|
* shape, then CONTAINS should be returned. If the shape is entirely enclosed
|
||||||
* by this GeoArea, then WITHIN should be returned.
|
* by this GeoArea, then WITHIN should be returned.
|
||||||
|
*
|
||||||
* @param shape is the shape to consider.
|
* @param shape is the shape to consider.
|
||||||
* @return the relationship, from the perspective of the shape.
|
* @return the relationship, from the perspective of the shape.
|
||||||
*/
|
*/
|
||||||
|
@ -17,10 +17,10 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Degenerate bounding box limited on two sides (top lat, bottom lat).
|
/**
|
||||||
|
* Degenerate bounding box limited on two sides (top lat, bottom lat).
|
||||||
*/
|
*/
|
||||||
public class GeoDegenerateVerticalLine extends GeoBBoxBase
|
public class GeoDegenerateVerticalLine extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double topLat;
|
public final double topLat;
|
||||||
public final double bottomLat;
|
public final double bottomLat;
|
||||||
public final double longitude;
|
public final double longitude;
|
||||||
@ -38,9 +38,10 @@ public class GeoDegenerateVerticalLine extends GeoBBoxBase
|
|||||||
public final GeoPoint centerPoint;
|
public final GeoPoint centerPoint;
|
||||||
public final GeoPoint[] edgePoints;
|
public final GeoPoint[] edgePoints;
|
||||||
|
|
||||||
/** 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)
|
* 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) {
|
||||||
// Argument checking
|
// Argument checking
|
||||||
if (topLat > Math.PI * 0.5 || topLat < -Math.PI * 0.5)
|
if (topLat > Math.PI * 0.5 || topLat < -Math.PI * 0.5)
|
||||||
throw new IllegalArgumentException("Top latitude out of range");
|
throw new IllegalArgumentException("Top latitude out of range");
|
||||||
@ -85,8 +86,7 @@ public class GeoDegenerateVerticalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
final double newTopLat = topLat + angle;
|
final double newTopLat = topLat + angle;
|
||||||
final double newBottomLat = bottomLat - angle;
|
final double newBottomLat = bottomLat - angle;
|
||||||
double newLeftLon = longitude - angle;
|
double newLeftLon = longitude - angle;
|
||||||
@ -100,8 +100,7 @@ public class GeoDegenerateVerticalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return plane.evaluateIsZero(point) &&
|
return plane.evaluateIsZero(point) &&
|
||||||
boundingPlane.isWithin(point) &&
|
boundingPlane.isWithin(point) &&
|
||||||
topPlane.isWithin(point) &&
|
topPlane.isWithin(point) &&
|
||||||
@ -109,8 +108,7 @@ public class GeoDegenerateVerticalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return plane.evaluateIsZero(x, y, z) &&
|
return plane.evaluateIsZero(x, y, z) &&
|
||||||
boundingPlane.isWithin(x, y, z) &&
|
boundingPlane.isWithin(x, y, z) &&
|
||||||
topPlane.isWithin(x, y, z) &&
|
topPlane.isWithin(x, y, z) &&
|
||||||
@ -118,8 +116,7 @@ public class GeoDegenerateVerticalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
||||||
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
||||||
// the distance to the right or left edge from the center.
|
// the distance to the right or left edge from the center.
|
||||||
@ -128,7 +125,9 @@ public class GeoDegenerateVerticalLine extends GeoBBoxBase
|
|||||||
return Math.max(topAngle, bottomAngle);
|
return Math.max(topAngle, bottomAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -137,18 +136,18 @@ public class GeoDegenerateVerticalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
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(plane, notablePoints, planePoints, bounds, boundingPlane, topPlane, bottomPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -156,8 +155,7 @@ public class GeoDegenerateVerticalLine extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.addLatitudeZone(topLat).addLatitudeZone(bottomLat)
|
bounds.addLatitudeZone(topLat).addLatitudeZone(bottomLat)
|
||||||
@ -183,8 +181,7 @@ public class GeoDegenerateVerticalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoDegenerateVerticalLine))
|
if (!(o instanceof GeoDegenerateVerticalLine))
|
||||||
return false;
|
return false;
|
||||||
GeoDegenerateVerticalLine other = (GeoDegenerateVerticalLine) o;
|
GeoDegenerateVerticalLine other = (GeoDegenerateVerticalLine) o;
|
||||||
|
@ -17,15 +17,18 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Generic geo-distance-capable shape class description. An implementer
|
/**
|
||||||
|
* Generic geo-distance-capable shape class description. An implementer
|
||||||
* of this interface is capable of computing the described "distance" values,
|
* of this interface is capable of computing the described "distance" values,
|
||||||
* which are meant to provide both actual distance values, as well as
|
* which are meant to provide both actual distance values, as well as
|
||||||
* distance estimates that can be computed more cheaply.
|
* distance estimates that can be computed more cheaply.
|
||||||
*/
|
*/
|
||||||
public interface GeoDistance extends Membership {
|
public interface GeoDistance extends Membership {
|
||||||
/** Compute this shape's normal "distance" to the GeoPoint.
|
/**
|
||||||
|
* Compute this shape's normal "distance" to the GeoPoint.
|
||||||
* A return value of Double.MAX_VALUE should be returned for
|
* A return value of Double.MAX_VALUE should be returned for
|
||||||
* points outside of the shape.
|
* points outside of the shape.
|
||||||
|
*
|
||||||
* @param point is the point to compute the distance to.
|
* @param point is the point to compute the distance to.
|
||||||
* @return the normal distance, defined as the perpendicular distance from
|
* @return the normal distance, defined as the perpendicular distance from
|
||||||
* from the point to one of the shape's bounding plane. Normal
|
* from the point to one of the shape's bounding plane. Normal
|
||||||
@ -34,9 +37,11 @@ public interface GeoDistance extends Membership {
|
|||||||
*/
|
*/
|
||||||
public double computeNormalDistance(GeoPoint point);
|
public double computeNormalDistance(GeoPoint point);
|
||||||
|
|
||||||
/** Compute this shape's normal "distance" to the GeoPoint.
|
/**
|
||||||
|
* Compute this shape's normal "distance" to the GeoPoint.
|
||||||
* A return value of Double.MAX_VALUE should be returned for
|
* A return value of Double.MAX_VALUE should be returned for
|
||||||
* points outside of the shape.
|
* points outside of the shape.
|
||||||
|
*
|
||||||
* @param x is the point's unit x coordinate (using U.S. convention).
|
* @param x is the point's unit x coordinate (using U.S. convention).
|
||||||
* @param y is the point's unit y coordinate (using U.S. convention).
|
* @param y is the point's unit y coordinate (using U.S. convention).
|
||||||
* @param z is the point's unit z coordinate (using U.S. convention).
|
* @param z is the point's unit z coordinate (using U.S. convention).
|
||||||
@ -47,9 +52,11 @@ public interface GeoDistance extends Membership {
|
|||||||
*/
|
*/
|
||||||
public double computeNormalDistance(double x, double y, double z);
|
public double computeNormalDistance(double x, double y, double z);
|
||||||
|
|
||||||
/** Compute the square of this shape's normal "distance" to the GeoPoint.
|
/**
|
||||||
|
* Compute the square of this shape's normal "distance" to the GeoPoint.
|
||||||
* A return value of Double.MAX_VALUE should be returned for
|
* A return value of Double.MAX_VALUE should be returned for
|
||||||
* points outside of the shape.
|
* points outside of the shape.
|
||||||
|
*
|
||||||
* @param point is the point to compute the distance to.
|
* @param point is the point to compute the distance to.
|
||||||
* @return the square of the normal distance, defined as the perpendicular
|
* @return the square of the normal distance, defined as the perpendicular
|
||||||
* distance from
|
* distance from
|
||||||
@ -59,9 +66,11 @@ public interface GeoDistance extends Membership {
|
|||||||
*/
|
*/
|
||||||
public double computeSquaredNormalDistance(GeoPoint point);
|
public double computeSquaredNormalDistance(GeoPoint point);
|
||||||
|
|
||||||
/** Compute the square of this shape's normal "distance" to the GeoPoint.
|
/**
|
||||||
|
* Compute the square of this shape's normal "distance" to the GeoPoint.
|
||||||
* A return value of Double.MAX_VALUE should be returned for
|
* A return value of Double.MAX_VALUE should be returned for
|
||||||
* points outside of the shape.
|
* points outside of the shape.
|
||||||
|
*
|
||||||
* @param x is the point's unit x coordinate (using U.S. convention).
|
* @param x is the point's unit x coordinate (using U.S. convention).
|
||||||
* @param y is the point's unit y coordinate (using U.S. convention).
|
* @param y is the point's unit y coordinate (using U.S. convention).
|
||||||
* @param z is the point's unit z coordinate (using U.S. convention).
|
* @param z is the point's unit z coordinate (using U.S. convention).
|
||||||
@ -73,9 +82,11 @@ public interface GeoDistance extends Membership {
|
|||||||
*/
|
*/
|
||||||
public double computeSquaredNormalDistance(double x, double y, double z);
|
public double computeSquaredNormalDistance(double x, double y, double z);
|
||||||
|
|
||||||
/** Compute this shape's linear "distance" to the GeoPoint.
|
/**
|
||||||
|
* Compute this shape's linear "distance" to the GeoPoint.
|
||||||
* A return value of Double.MAX_VALUE should be returned for
|
* A return value of Double.MAX_VALUE should be returned for
|
||||||
* points outside of the shape.
|
* points outside of the shape.
|
||||||
|
*
|
||||||
* @param point is the point to compute the distance to.
|
* @param point is the point to compute the distance to.
|
||||||
* @return the linear (or chord) distance, defined as the distance from
|
* @return the linear (or chord) distance, defined as the distance from
|
||||||
* from the point to the nearest point on the unit sphere and on one of the shape's
|
* from the point to the nearest point on the unit sphere and on one of the shape's
|
||||||
@ -84,9 +95,11 @@ public interface GeoDistance extends Membership {
|
|||||||
*/
|
*/
|
||||||
public double computeLinearDistance(GeoPoint point);
|
public double computeLinearDistance(GeoPoint point);
|
||||||
|
|
||||||
/** Compute this shape's linear "distance" to the GeoPoint.
|
/**
|
||||||
|
* Compute this shape's linear "distance" to the GeoPoint.
|
||||||
* A return value of Double.MAX_VALUE should be returned for
|
* A return value of Double.MAX_VALUE should be returned for
|
||||||
* points outside of the shape.
|
* points outside of the shape.
|
||||||
|
*
|
||||||
* @param x is the point's unit x coordinate (using U.S. convention).
|
* @param x is the point's unit x coordinate (using U.S. convention).
|
||||||
* @param y is the point's unit y coordinate (using U.S. convention).
|
* @param y is the point's unit y coordinate (using U.S. convention).
|
||||||
* @param z is the point's unit z coordinate (using U.S. convention).
|
* @param z is the point's unit z coordinate (using U.S. convention).
|
||||||
@ -97,9 +110,11 @@ public interface GeoDistance extends Membership {
|
|||||||
*/
|
*/
|
||||||
public double computeLinearDistance(double x, double y, double z);
|
public double computeLinearDistance(double x, double y, double z);
|
||||||
|
|
||||||
/** Compute the square of this shape's linear "distance" to the GeoPoint.
|
/**
|
||||||
|
* Compute the square of this shape's linear "distance" to the GeoPoint.
|
||||||
* A return value of Double.MAX_VALUE should be returned for
|
* A return value of Double.MAX_VALUE should be returned for
|
||||||
* points outside of the shape.
|
* points outside of the shape.
|
||||||
|
*
|
||||||
* @param point is the point to compute the distance to.
|
* @param point is the point to compute the distance to.
|
||||||
* @return the square of the linear (or chord) distance, defined as the
|
* @return the square of the linear (or chord) distance, defined as the
|
||||||
* distance from
|
* distance from
|
||||||
@ -109,9 +124,11 @@ public interface GeoDistance extends Membership {
|
|||||||
*/
|
*/
|
||||||
public double computeSquaredLinearDistance(GeoPoint point);
|
public double computeSquaredLinearDistance(GeoPoint point);
|
||||||
|
|
||||||
/** Compute the square of this shape's linear "distance" to the GeoPoint.
|
/**
|
||||||
|
* Compute the square of this shape's linear "distance" to the GeoPoint.
|
||||||
* A return value of Double.MAX_VALUE should be returned for
|
* A return value of Double.MAX_VALUE should be returned for
|
||||||
* points outside of the shape.
|
* points outside of the shape.
|
||||||
|
*
|
||||||
* @param x is the point's unit x coordinate (using U.S. convention).
|
* @param x is the point's unit x coordinate (using U.S. convention).
|
||||||
* @param y is the point's unit y coordinate (using U.S. convention).
|
* @param y is the point's unit y coordinate (using U.S. convention).
|
||||||
* @param z is the point's unit z coordinate (using U.S. convention).
|
* @param z is the point's unit z coordinate (using U.S. convention).
|
||||||
@ -122,8 +139,10 @@ public interface GeoDistance extends Membership {
|
|||||||
*/
|
*/
|
||||||
public double computeSquaredLinearDistance(double x, double y, double z);
|
public double computeSquaredLinearDistance(double x, double y, double z);
|
||||||
|
|
||||||
/** Compute a true, accurate, great-circle distance to a point.
|
/**
|
||||||
|
* Compute a true, accurate, great-circle distance to a point.
|
||||||
* Double.MAX_VALUE indicates a point is outside of the shape.
|
* Double.MAX_VALUE indicates a point is outside of the shape.
|
||||||
|
*
|
||||||
* @param point is the point.
|
* @param point is the point.
|
||||||
* @return the distance.
|
* @return the distance.
|
||||||
*/
|
*/
|
||||||
|
@ -17,7 +17,8 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Distance shapes have capabilities of both geohashing and distance
|
/**
|
||||||
|
* Distance shapes have capabilities of both geohashing and distance
|
||||||
* computation (which also includes point membership determination).
|
* computation (which also includes point membership determination).
|
||||||
*/
|
*/
|
||||||
public interface GeoDistanceShape extends GeoMembershipShape, GeoDistance {
|
public interface GeoDistanceShape extends GeoMembershipShape, GeoDistance {
|
||||||
|
@ -17,10 +17,10 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** This GeoBBox represents an area rectangle limited only in latitude.
|
/**
|
||||||
|
* This GeoBBox represents an area rectangle limited only in latitude.
|
||||||
*/
|
*/
|
||||||
public class GeoLatitudeZone extends GeoBBoxBase
|
public class GeoLatitudeZone extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double topLat;
|
public final double topLat;
|
||||||
public final double bottomLat;
|
public final double bottomLat;
|
||||||
public final double cosTopLat;
|
public final double cosTopLat;
|
||||||
@ -38,8 +38,7 @@ public class GeoLatitudeZone extends GeoBBoxBase
|
|||||||
// Edge points
|
// Edge points
|
||||||
public final GeoPoint[] edgePoints;
|
public final GeoPoint[] edgePoints;
|
||||||
|
|
||||||
public GeoLatitudeZone(final double topLat, final double bottomLat)
|
public GeoLatitudeZone(final double topLat, final double bottomLat) {
|
||||||
{
|
|
||||||
this.topLat = topLat;
|
this.topLat = topLat;
|
||||||
this.bottomLat = bottomLat;
|
this.bottomLat = bottomLat;
|
||||||
|
|
||||||
@ -66,30 +65,26 @@ public class GeoLatitudeZone extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
final double newTopLat = topLat + angle;
|
final double newTopLat = topLat + angle;
|
||||||
final double newBottomLat = bottomLat - angle;
|
final double newBottomLat = bottomLat - angle;
|
||||||
return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, -Math.PI, Math.PI);
|
return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, -Math.PI, Math.PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return topPlane.isWithin(point) &&
|
return topPlane.isWithin(point) &&
|
||||||
bottomPlane.isWithin(point);
|
bottomPlane.isWithin(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return topPlane.isWithin(x, y, z) &&
|
return topPlane.isWithin(x, y, z) &&
|
||||||
bottomPlane.isWithin(x, y, z);
|
bottomPlane.isWithin(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// This is a bit tricky. I guess we should interpret this as meaning the angle of a circle that
|
// This is a bit tricky. I guess we should interpret this as meaning the angle of a circle that
|
||||||
// would contain all the bounding box points, when starting in the "center".
|
// would contain all the bounding box points, when starting in the "center".
|
||||||
if (topLat > 0.0 && bottomLat < 0.0)
|
if (topLat > 0.0 && bottomLat < 0.0)
|
||||||
@ -100,7 +95,9 @@ public class GeoLatitudeZone extends GeoBBoxBase
|
|||||||
return maxCosLat * Math.PI;
|
return maxCosLat * Math.PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -110,19 +107,19 @@ public class GeoLatitudeZone extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
return p.intersects(topPlane, notablePoints, planePoints, bounds, bottomPlane) ||
|
return p.intersects(topPlane, notablePoints, planePoints, bounds, bottomPlane) ||
|
||||||
p.intersects(bottomPlane, notablePoints, planePoints, bounds, topPlane);
|
p.intersects(bottomPlane, notablePoints, planePoints, bounds, topPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -130,8 +127,7 @@ public class GeoLatitudeZone extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.noLongitudeBound().addLatitudeZone(topLat).addLatitudeZone(bottomLat);
|
bounds.noLongitudeBound().addLatitudeZone(topLat).addLatitudeZone(bottomLat);
|
||||||
@ -179,8 +175,7 @@ public class GeoLatitudeZone extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoLatitudeZone))
|
if (!(o instanceof GeoLatitudeZone))
|
||||||
return false;
|
return false;
|
||||||
GeoLatitudeZone other = (GeoLatitudeZone) o;
|
GeoLatitudeZone other = (GeoLatitudeZone) o;
|
||||||
|
@ -17,12 +17,12 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Bounding box limited on left and right.
|
/**
|
||||||
|
* Bounding box limited on left and right.
|
||||||
* The left-right maximum extent for this shape is PI; for anything larger, use
|
* The left-right maximum extent for this shape is PI; for anything larger, use
|
||||||
* GeoWideLongitudeSlice.
|
* GeoWideLongitudeSlice.
|
||||||
*/
|
*/
|
||||||
public class GeoLongitudeSlice extends GeoBBoxBase
|
public class GeoLongitudeSlice extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double leftLon;
|
public final double leftLon;
|
||||||
public final double rightLon;
|
public final double rightLon;
|
||||||
|
|
||||||
@ -35,9 +35,10 @@ public class GeoLongitudeSlice extends GeoBBoxBase
|
|||||||
|
|
||||||
public final static GeoPoint[] edgePoints = new GeoPoint[]{NORTH_POLE};
|
public final static GeoPoint[] edgePoints = new GeoPoint[]{NORTH_POLE};
|
||||||
|
|
||||||
/** Accepts only values in the following ranges: lon: {@code -PI -> PI} */
|
/**
|
||||||
public GeoLongitudeSlice(final double leftLon, double rightLon)
|
* Accepts only values in the following ranges: lon: {@code -PI -> PI}
|
||||||
{
|
*/
|
||||||
|
public GeoLongitudeSlice(final double leftLon, double rightLon) {
|
||||||
// Argument checking
|
// Argument checking
|
||||||
if (leftLon < -Math.PI || leftLon > Math.PI)
|
if (leftLon < -Math.PI || leftLon > Math.PI)
|
||||||
throw new IllegalArgumentException("Left longitude out of range");
|
throw new IllegalArgumentException("Left longitude out of range");
|
||||||
@ -71,8 +72,7 @@ public class GeoLongitudeSlice extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
// Figuring out when we escalate to a special case requires some prefiguring
|
// Figuring out when we escalate to a special case requires some prefiguring
|
||||||
double currentLonSpan = rightLon - leftLon;
|
double currentLonSpan = rightLon - leftLon;
|
||||||
if (currentLonSpan < 0.0)
|
if (currentLonSpan < 0.0)
|
||||||
@ -87,22 +87,19 @@ public class GeoLongitudeSlice extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return leftPlane.isWithin(point) &&
|
return leftPlane.isWithin(point) &&
|
||||||
rightPlane.isWithin(point);
|
rightPlane.isWithin(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return leftPlane.isWithin(x, y, z) &&
|
return leftPlane.isWithin(x, y, z) &&
|
||||||
rightPlane.isWithin(x, y, z);
|
rightPlane.isWithin(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// Compute the extent and divide by two
|
// Compute the extent and divide by two
|
||||||
double extent = rightLon - leftLon;
|
double extent = rightLon - leftLon;
|
||||||
if (extent < 0.0)
|
if (extent < 0.0)
|
||||||
@ -110,7 +107,9 @@ public class GeoLongitudeSlice extends GeoBBoxBase
|
|||||||
return Math.max(Math.PI * 0.5, extent * 0.5);
|
return Math.max(Math.PI * 0.5, extent * 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -119,19 +118,19 @@ public class GeoLongitudeSlice extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
return p.intersects(leftPlane, notablePoints, planePoints, bounds, rightPlane) ||
|
return p.intersects(leftPlane, notablePoints, planePoints, bounds, rightPlane) ||
|
||||||
p.intersects(rightPlane, notablePoints, planePoints, bounds, leftPlane);
|
p.intersects(rightPlane, notablePoints, planePoints, bounds, leftPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -139,8 +138,7 @@ public class GeoLongitudeSlice extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.noTopLatitudeBound().noBottomLatitudeBound();
|
bounds.noTopLatitudeBound().noBottomLatitudeBound();
|
||||||
@ -176,8 +174,7 @@ public class GeoLongitudeSlice extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoLongitudeSlice))
|
if (!(o instanceof GeoLongitudeSlice))
|
||||||
return false;
|
return false;
|
||||||
GeoLongitudeSlice other = (GeoLongitudeSlice) o;
|
GeoLongitudeSlice other = (GeoLongitudeSlice) o;
|
||||||
|
@ -17,7 +17,8 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Membership shapes have capabilities of both geohashing and membership
|
/**
|
||||||
|
* Membership shapes have capabilities of both geohashing and membership
|
||||||
* determination.
|
* determination.
|
||||||
*/
|
*/
|
||||||
public interface GeoMembershipShape extends GeoShape, Membership {
|
public interface GeoMembershipShape extends GeoShape, Membership {
|
||||||
|
@ -17,10 +17,10 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** This GeoBBox represents an area rectangle limited only in south latitude.
|
/**
|
||||||
|
* This GeoBBox represents an area rectangle limited only in south latitude.
|
||||||
*/
|
*/
|
||||||
public class GeoNorthLatitudeZone extends GeoBBoxBase
|
public class GeoNorthLatitudeZone extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double bottomLat;
|
public final double bottomLat;
|
||||||
public final double cosBottomLat;
|
public final double cosBottomLat;
|
||||||
public final SidedPlane bottomPlane;
|
public final SidedPlane bottomPlane;
|
||||||
@ -32,8 +32,7 @@ public class GeoNorthLatitudeZone extends GeoBBoxBase
|
|||||||
// Edge points
|
// Edge points
|
||||||
public final GeoPoint[] edgePoints;
|
public final GeoPoint[] edgePoints;
|
||||||
|
|
||||||
public GeoNorthLatitudeZone(final double bottomLat)
|
public GeoNorthLatitudeZone(final double bottomLat) {
|
||||||
{
|
|
||||||
this.bottomLat = bottomLat;
|
this.bottomLat = bottomLat;
|
||||||
|
|
||||||
final double sinBottomLat = Math.sin(bottomLat);
|
final double sinBottomLat = Math.sin(bottomLat);
|
||||||
@ -54,30 +53,26 @@ public class GeoNorthLatitudeZone extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
final double newTopLat = Math.PI * 0.5;
|
final double newTopLat = Math.PI * 0.5;
|
||||||
final double newBottomLat = bottomLat - angle;
|
final double newBottomLat = bottomLat - angle;
|
||||||
return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, -Math.PI, Math.PI);
|
return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, -Math.PI, Math.PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return
|
return
|
||||||
bottomPlane.isWithin(point);
|
bottomPlane.isWithin(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return
|
return
|
||||||
bottomPlane.isWithin(x, y, z);
|
bottomPlane.isWithin(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// This is a bit tricky. I guess we should interpret this as meaning the angle of a circle that
|
// This is a bit tricky. I guess we should interpret this as meaning the angle of a circle that
|
||||||
// would contain all the bounding box points, when starting in the "center".
|
// would contain all the bounding box points, when starting in the "center".
|
||||||
if (bottomLat < 0.0)
|
if (bottomLat < 0.0)
|
||||||
@ -86,7 +81,9 @@ public class GeoNorthLatitudeZone extends GeoBBoxBase
|
|||||||
return maxCosLat * Math.PI;
|
return maxCosLat * Math.PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -95,19 +92,19 @@ public class GeoNorthLatitudeZone extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
return
|
return
|
||||||
p.intersects(bottomPlane, notablePoints, planePoints, bounds);
|
p.intersects(bottomPlane, notablePoints, planePoints, bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -115,8 +112,7 @@ public class GeoNorthLatitudeZone extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.noLongitudeBound().noTopLatitudeBound().addLatitudeZone(bottomLat);
|
bounds.noLongitudeBound().noTopLatitudeBound().addLatitudeZone(bottomLat);
|
||||||
@ -157,8 +153,7 @@ public class GeoNorthLatitudeZone extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoNorthLatitudeZone))
|
if (!(o instanceof GeoNorthLatitudeZone))
|
||||||
return false;
|
return false;
|
||||||
GeoNorthLatitudeZone other = (GeoNorthLatitudeZone) o;
|
GeoNorthLatitudeZone other = (GeoNorthLatitudeZone) o;
|
||||||
|
@ -17,13 +17,13 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Bounding box limited on three sides (bottom lat, left lon, right lon), including
|
/**
|
||||||
|
* Bounding box limited on three sides (bottom lat, left lon, right lon), including
|
||||||
* the north pole.
|
* the north pole.
|
||||||
* The left-right maximum extent for this shape is PI; for anything larger, use
|
* The left-right maximum extent for this shape is PI; for anything larger, use
|
||||||
* GeoWideNorthRectangle.
|
* GeoWideNorthRectangle.
|
||||||
*/
|
*/
|
||||||
public class GeoNorthRectangle extends GeoBBoxBase
|
public class GeoNorthRectangle extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double bottomLat;
|
public final double bottomLat;
|
||||||
public final double leftLon;
|
public final double leftLon;
|
||||||
public final double rightLon;
|
public final double rightLon;
|
||||||
@ -45,9 +45,10 @@ public class GeoNorthRectangle extends GeoBBoxBase
|
|||||||
|
|
||||||
public final GeoPoint[] edgePoints = new GeoPoint[]{NORTH_POLE};
|
public final GeoPoint[] edgePoints = new GeoPoint[]{NORTH_POLE};
|
||||||
|
|
||||||
/** 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)
|
* 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) {
|
||||||
// Argument checking
|
// Argument checking
|
||||||
if (bottomLat > Math.PI * 0.5 || bottomLat < -Math.PI * 0.5)
|
if (bottomLat > Math.PI * 0.5 || bottomLat < -Math.PI * 0.5)
|
||||||
throw new IllegalArgumentException("Bottom latitude out of range");
|
throw new IllegalArgumentException("Bottom latitude out of range");
|
||||||
@ -101,8 +102,7 @@ public class GeoNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
final double newTopLat = Math.PI * 0.5;
|
final double newTopLat = Math.PI * 0.5;
|
||||||
final double newBottomLat = bottomLat - angle;
|
final double newBottomLat = bottomLat - angle;
|
||||||
// Figuring out when we escalate to a special case requires some prefiguring
|
// Figuring out when we escalate to a special case requires some prefiguring
|
||||||
@ -119,8 +119,7 @@ public class GeoNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return
|
return
|
||||||
bottomPlane.isWithin(point) &&
|
bottomPlane.isWithin(point) &&
|
||||||
leftPlane.isWithin(point) &&
|
leftPlane.isWithin(point) &&
|
||||||
@ -128,8 +127,7 @@ public class GeoNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return
|
return
|
||||||
bottomPlane.isWithin(x, y, z) &&
|
bottomPlane.isWithin(x, y, z) &&
|
||||||
leftPlane.isWithin(x, y, z) &&
|
leftPlane.isWithin(x, y, z) &&
|
||||||
@ -137,8 +135,7 @@ public class GeoNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
||||||
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
||||||
// the distance to the right or left edge from the center.
|
// the distance to the right or left edge from the center.
|
||||||
@ -148,12 +145,13 @@ public class GeoNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -162,15 +160,16 @@ public class GeoNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
return
|
return
|
||||||
p.intersects(bottomPlane, notablePoints, bottomPlanePoints, bounds, leftPlane, rightPlane) ||
|
p.intersects(bottomPlane, notablePoints, bottomPlanePoints, bounds, leftPlane, rightPlane) ||
|
||||||
p.intersects(leftPlane, notablePoints, leftPlanePoints, bounds, rightPlane, bottomPlane) ||
|
p.intersects(leftPlane, notablePoints, leftPlanePoints, bounds, rightPlane, bottomPlane) ||
|
||||||
p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, leftPlane, bottomPlane);
|
p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, leftPlane, bottomPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -178,8 +177,7 @@ public class GeoNorthRectangle extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.noTopLatitudeBound().addLatitudeZone(bottomLat)
|
bounds.noTopLatitudeBound().addLatitudeZone(bottomLat)
|
||||||
@ -191,8 +189,7 @@ public class GeoNorthRectangle extends GeoBBoxBase
|
|||||||
public int getRelationship(final GeoShape path) {
|
public int getRelationship(final GeoShape path) {
|
||||||
//System.err.println(this+" getrelationship with "+path);
|
//System.err.println(this+" getrelationship with "+path);
|
||||||
final int insideRectangle = isShapeInsideBBox(path);
|
final int insideRectangle = isShapeInsideBBox(path);
|
||||||
if (insideRectangle == SOME_INSIDE)
|
if (insideRectangle == SOME_INSIDE) {
|
||||||
{
|
|
||||||
//System.err.println(" some inside");
|
//System.err.println(" some inside");
|
||||||
return OVERLAPS;
|
return OVERLAPS;
|
||||||
}
|
}
|
||||||
@ -212,8 +209,7 @@ public class GeoNorthRectangle extends GeoBBoxBase
|
|||||||
return OVERLAPS;
|
return OVERLAPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insideRectangle == ALL_INSIDE)
|
if (insideRectangle == ALL_INSIDE) {
|
||||||
{
|
|
||||||
//System.err.println(" shape inside rectangle");
|
//System.err.println(" shape inside rectangle");
|
||||||
return WITHIN;
|
return WITHIN;
|
||||||
}
|
}
|
||||||
@ -227,8 +223,7 @@ public class GeoNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoNorthRectangle))
|
if (!(o instanceof GeoNorthRectangle))
|
||||||
return false;
|
return false;
|
||||||
GeoNorthRectangle other = (GeoNorthRectangle) o;
|
GeoNorthRectangle other = (GeoNorthRectangle) o;
|
||||||
|
@ -20,13 +20,13 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** GeoSearchableShape representing a path across the surface of the globe,
|
/**
|
||||||
|
* GeoSearchableShape representing a path across the surface of the globe,
|
||||||
* with a specified half-width. Path is described by a series of points.
|
* with a specified half-width. Path is described by a series of points.
|
||||||
* Distances are measured from the starting point along the path, and then at right
|
* Distances are measured from the starting point along the path, and then at right
|
||||||
* angles to the path.
|
* angles to the path.
|
||||||
*/
|
*/
|
||||||
public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape {
|
||||||
{
|
|
||||||
public final double cutoffAngle;
|
public final double cutoffAngle;
|
||||||
public final double cutoffOffset;
|
public final double cutoffOffset;
|
||||||
public final double originDistance;
|
public final double originDistance;
|
||||||
@ -37,8 +37,7 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
|
|
||||||
public GeoPoint[] edgePoints = null;
|
public GeoPoint[] edgePoints = null;
|
||||||
|
|
||||||
public GeoPath(final double cutoffAngle)
|
public GeoPath(final double cutoffAngle) {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
if (cutoffAngle <= 0.0 || cutoffAngle > Math.PI * 0.5)
|
if (cutoffAngle <= 0.0 || cutoffAngle > Math.PI * 0.5)
|
||||||
throw new IllegalArgumentException("Cutoff angle out of bounds");
|
throw new IllegalArgumentException("Cutoff angle out of bounds");
|
||||||
@ -53,8 +52,7 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
this.chordDistance = Math.sqrt(xDiff * xDiff + sinAngle * sinAngle);
|
this.chordDistance = Math.sqrt(xDiff * xDiff + sinAngle * sinAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPoint(double lat, double lon)
|
public void addPoint(double lat, double lon) {
|
||||||
{
|
|
||||||
if (lat < -Math.PI * 0.5 || lat > Math.PI * 0.5)
|
if (lat < -Math.PI * 0.5 || lat > Math.PI * 0.5)
|
||||||
throw new IllegalArgumentException("Latitude out of range");
|
throw new IllegalArgumentException("Latitude out of range");
|
||||||
if (lon < -Math.PI || lon > Math.PI)
|
if (lon < -Math.PI || lon > Math.PI)
|
||||||
@ -112,13 +110,13 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute an estimate of "distance" to the GeoPoint.
|
/**
|
||||||
|
* Compute an estimate of "distance" to the GeoPoint.
|
||||||
* A return value of Double.MAX_VALUE should be returned for
|
* A return value of Double.MAX_VALUE should be returned for
|
||||||
* points outside of the shape.
|
* points outside of the shape.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeNormalDistance(final GeoPoint point)
|
public double computeNormalDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
// Algorithm:
|
// Algorithm:
|
||||||
// (1) If the point is within any of the segments along the path, return that value.
|
// (1) If the point is within any of the segments along the path, return that value.
|
||||||
// (2) If the point is within any of the segment end circles along the path, return that value.
|
// (2) If the point is within any of the segment end circles along the path, return that value.
|
||||||
@ -143,44 +141,44 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute an estimate of "distance" to the GeoPoint.
|
/**
|
||||||
|
* Compute an estimate of "distance" to the GeoPoint.
|
||||||
* A return value of Double.MAX_VALUE should be returned for
|
* A return value of Double.MAX_VALUE should be returned for
|
||||||
* points outside of the shape.
|
* points outside of the shape.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeNormalDistance(final double x, final double y, final double z)
|
public double computeNormalDistance(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return computeNormalDistance(new GeoPoint(x, y, z));
|
return computeNormalDistance(new GeoPoint(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a squared estimate of the "distance" to the
|
/**
|
||||||
|
* Compute a squared estimate of the "distance" to the
|
||||||
* GeoPoint. Double.MAX_VALUE indicates a point outside of the
|
* GeoPoint. Double.MAX_VALUE indicates a point outside of the
|
||||||
* shape.
|
* shape.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeSquaredNormalDistance(final GeoPoint point)
|
public double computeSquaredNormalDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
double pd = computeNormalDistance(point);
|
double pd = computeNormalDistance(point);
|
||||||
if (pd == Double.MAX_VALUE)
|
if (pd == Double.MAX_VALUE)
|
||||||
return pd;
|
return pd;
|
||||||
return pd * pd;
|
return pd * pd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a squared estimate of the "distance" to the
|
/**
|
||||||
|
* Compute a squared estimate of the "distance" to the
|
||||||
* GeoPoint. Double.MAX_VALUE indicates a point outside of the
|
* GeoPoint. Double.MAX_VALUE indicates a point outside of the
|
||||||
* shape.
|
* shape.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeSquaredNormalDistance(final double x, final double y, final double z)
|
public double computeSquaredNormalDistance(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return computeSquaredNormalDistance(new GeoPoint(x, y, z));
|
return computeSquaredNormalDistance(new GeoPoint(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a linear distance to the point.
|
/**
|
||||||
|
* Compute a linear distance to the point.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeLinearDistance(final GeoPoint point)
|
public double computeLinearDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
// Algorithm:
|
// Algorithm:
|
||||||
// (1) If the point is within any of the segments along the path, return that value.
|
// (1) If the point is within any of the segments along the path, return that value.
|
||||||
// (2) If the point is within any of the segment end circles along the path, return that value.
|
// (2) If the point is within any of the segment end circles along the path, return that value.
|
||||||
@ -205,39 +203,39 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a linear distance to the point.
|
/**
|
||||||
|
* Compute a linear distance to the point.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeLinearDistance(final double x, final double y, final double z)
|
public double computeLinearDistance(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return computeLinearDistance(new GeoPoint(x, y, z));
|
return computeLinearDistance(new GeoPoint(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a squared linear distance to the vector.
|
/**
|
||||||
|
* Compute a squared linear distance to the vector.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeSquaredLinearDistance(final GeoPoint point)
|
public double computeSquaredLinearDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
double pd = computeLinearDistance(point);
|
double pd = computeLinearDistance(point);
|
||||||
if (pd == Double.MAX_VALUE)
|
if (pd == Double.MAX_VALUE)
|
||||||
return pd;
|
return pd;
|
||||||
return pd * pd;
|
return pd * pd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a squared linear distance to the vector.
|
/**
|
||||||
|
* Compute a squared linear distance to the vector.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeSquaredLinearDistance(final double x, final double y, final double z)
|
public double computeSquaredLinearDistance(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return computeSquaredLinearDistance(new GeoPoint(x, y, z));
|
return computeSquaredLinearDistance(new GeoPoint(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a true, accurate, great-circle distance.
|
/**
|
||||||
|
* Compute a true, accurate, great-circle distance.
|
||||||
* Double.MAX_VALUE indicates a point is outside of the shape.
|
* Double.MAX_VALUE indicates a point is outside of the shape.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double computeArcDistance(final GeoPoint point)
|
public double computeArcDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
// Algorithm:
|
// Algorithm:
|
||||||
// (1) If the point is within any of the segments along the path, return that value.
|
// (1) If the point is within any of the segments along the path, return that value.
|
||||||
// (2) If the point is within any of the segment end circles along the path, return that value.
|
// (2) If the point is within any of the segment end circles along the path, return that value.
|
||||||
@ -263,8 +261,7 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
for (SegmentEndpoint pathPoint : points) {
|
for (SegmentEndpoint pathPoint : points) {
|
||||||
if (pathPoint.isWithin(point))
|
if (pathPoint.isWithin(point))
|
||||||
return true;
|
return true;
|
||||||
@ -277,8 +274,7 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
for (SegmentEndpoint pathPoint : points) {
|
for (SegmentEndpoint pathPoint : points) {
|
||||||
if (pathPoint.isWithin(x, y, z))
|
if (pathPoint.isWithin(x, y, z))
|
||||||
return true;
|
return true;
|
||||||
@ -291,14 +287,12 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane plane, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane plane, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
// We look for an intersection with any of the exterior edges of the path.
|
// We look for an intersection with any of the exterior edges of the path.
|
||||||
// We also have to look for intersections with the cones described by the endpoints.
|
// We also have to look for intersections with the cones described by the endpoints.
|
||||||
// Return "true" if any such intersections are found.
|
// Return "true" if any such intersections are found.
|
||||||
@ -324,7 +318,9 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -332,8 +328,7 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
bounds = super.getBounds(bounds);
|
bounds = super.getBounds(bounds);
|
||||||
// For building bounds, order matters. We want to traverse
|
// For building bounds, order matters. We want to traverse
|
||||||
// never more than 180 degrees longitude at a pop or we risk having the
|
// never more than 180 degrees longitude at a pop or we risk having the
|
||||||
@ -380,10 +375,10 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
return "GeoPath: {width=" + cutoffAngle + "(" + cutoffAngle * 180.0 / Math.PI + "), points={" + points + "}}";
|
return "GeoPath: {width=" + cutoffAngle + "(" + cutoffAngle * 180.0 / Math.PI + "), points={" + points + "}}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This is precalculated data for segment endpoint.
|
/**
|
||||||
|
* This is precalculated data for segment endpoint.
|
||||||
*/
|
*/
|
||||||
public static class SegmentEndpoint
|
public static class SegmentEndpoint {
|
||||||
{
|
|
||||||
public final GeoPoint point;
|
public final GeoPoint point;
|
||||||
public final SidedPlane circlePlane;
|
public final SidedPlane circlePlane;
|
||||||
public final double cutoffNormalDistance;
|
public final double cutoffNormalDistance;
|
||||||
@ -394,8 +389,7 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
|
|
||||||
public final static GeoPoint[] circlePoints = new GeoPoint[0];
|
public final static GeoPoint[] circlePoints = new GeoPoint[0];
|
||||||
|
|
||||||
public SegmentEndpoint(final GeoPoint point, final double originDistance, final double cutoffOffset, final double cutoffAngle, final double chordDistance)
|
public SegmentEndpoint(final GeoPoint point, final double originDistance, final double cutoffOffset, final double cutoffAngle, final double chordDistance) {
|
||||||
{
|
|
||||||
this.point = point;
|
this.point = point;
|
||||||
this.cutoffNormalDistance = cutoffOffset;
|
this.cutoffNormalDistance = cutoffOffset;
|
||||||
this.cutoffAngle = cutoffAngle;
|
this.cutoffAngle = cutoffAngle;
|
||||||
@ -427,47 +421,40 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return circlePlane.isWithin(point);
|
return circlePlane.isWithin(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return circlePlane.isWithin(x, y, z);
|
return circlePlane.isWithin(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double pathDistance(final GeoPoint point)
|
public double pathDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
double dist = this.point.arcDistance(point);
|
double dist = this.point.arcDistance(point);
|
||||||
if (dist > cutoffAngle)
|
if (dist > cutoffAngle)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double pathNormalDistance(final GeoPoint point)
|
public double pathNormalDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
double dist = this.point.normalDistance(point);
|
double dist = this.point.normalDistance(point);
|
||||||
if (dist > cutoffNormalDistance)
|
if (dist > cutoffNormalDistance)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double pathLinearDistance(final GeoPoint point)
|
public double pathLinearDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
double dist = this.point.linearDistance(point);
|
double dist = this.point.linearDistance(point);
|
||||||
if (dist > chordDistance)
|
if (dist > chordDistance)
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds) {
|
||||||
{
|
|
||||||
return circlePlane.intersects(p, notablePoints, this.notablePoints, bounds, this.cutoffPlanes);
|
return circlePlane.intersects(p, notablePoints, this.notablePoints, bounds, this.cutoffPlanes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getBounds(Bounds bounds)
|
public void getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
bounds.addPoint(point);
|
bounds.addPoint(point);
|
||||||
circlePlane.recordBounds(bounds);
|
circlePlane.recordBounds(bounds);
|
||||||
}
|
}
|
||||||
@ -491,10 +478,10 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This is the precalculated data for a path segment.
|
/**
|
||||||
|
* This is the precalculated data for a path segment.
|
||||||
*/
|
*/
|
||||||
public static class PathSegment
|
public static class PathSegment {
|
||||||
{
|
|
||||||
public final GeoPoint start;
|
public final GeoPoint start;
|
||||||
public final GeoPoint end;
|
public final GeoPoint end;
|
||||||
public final double fullDistance;
|
public final double fullDistance;
|
||||||
@ -517,8 +504,7 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
public final SidedPlane invertedStartCutoffPlane;
|
public final SidedPlane invertedStartCutoffPlane;
|
||||||
public final SidedPlane invertedEndCutoffPlane;
|
public final SidedPlane invertedEndCutoffPlane;
|
||||||
|
|
||||||
public PathSegment(final GeoPoint start, final GeoPoint end, final double planeBoundingOffset, final double arcWidth, final double chordDistance)
|
public PathSegment(final GeoPoint start, final GeoPoint end, final double planeBoundingOffset, final double arcWidth, final double chordDistance) {
|
||||||
{
|
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
this.planeBoundingOffset = planeBoundingOffset;
|
this.planeBoundingOffset = planeBoundingOffset;
|
||||||
@ -564,29 +550,25 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDegenerate()
|
public boolean isDegenerate() {
|
||||||
{
|
|
||||||
return normalizedConnectingPlane == null;
|
return normalizedConnectingPlane == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return startCutoffPlane.isWithin(point) &&
|
return startCutoffPlane.isWithin(point) &&
|
||||||
endCutoffPlane.isWithin(point) &&
|
endCutoffPlane.isWithin(point) &&
|
||||||
upperConnectingPlane.isWithin(point) &&
|
upperConnectingPlane.isWithin(point) &&
|
||||||
lowerConnectingPlane.isWithin(point);
|
lowerConnectingPlane.isWithin(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return startCutoffPlane.isWithin(x, y, z) &&
|
return startCutoffPlane.isWithin(x, y, z) &&
|
||||||
endCutoffPlane.isWithin(x, y, z) &&
|
endCutoffPlane.isWithin(x, y, z) &&
|
||||||
upperConnectingPlane.isWithin(x, y, z) &&
|
upperConnectingPlane.isWithin(x, y, z) &&
|
||||||
lowerConnectingPlane.isWithin(x, y, z);
|
lowerConnectingPlane.isWithin(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double pathDistance(final GeoPoint point)
|
public double pathDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
if (!isWithin(point))
|
if (!isWithin(point))
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
|
|
||||||
@ -597,8 +579,7 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
return perpDistance + pathDistance;
|
return perpDistance + pathDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double pathNormalDistance(final GeoPoint point)
|
public double pathNormalDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
if (!isWithin(point))
|
if (!isWithin(point))
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
|
|
||||||
@ -618,8 +599,7 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
return perpEval * normFactor + pointEval;
|
return perpEval * normFactor + pointEval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double pathLinearDistance(final GeoPoint point)
|
public double pathLinearDistance(final GeoPoint point) {
|
||||||
{
|
|
||||||
if (!isWithin(point))
|
if (!isWithin(point))
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
|
|
||||||
@ -648,8 +628,7 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
double normLineY = lineY * normalizer;
|
double normLineY = lineY * normalizer;
|
||||||
double normLineZ = lineZ * normalizer;
|
double normLineZ = lineZ * normalizer;
|
||||||
if (!startCutoffPlane.isWithin(normLineX, normLineY, normLineZ) ||
|
if (!startCutoffPlane.isWithin(normLineX, normLineY, normLineZ) ||
|
||||||
!endCutoffPlane.isWithin(normLineX,normLineY,normLineZ))
|
!endCutoffPlane.isWithin(normLineX, normLineY, normLineZ)) {
|
||||||
{
|
|
||||||
normLineX = -normLineX;
|
normLineX = -normLineX;
|
||||||
normLineY = -normLineY;
|
normLineY = -normLineY;
|
||||||
normLineZ = -normLineZ;
|
normLineZ = -normLineZ;
|
||||||
@ -659,14 +638,12 @@ public class GeoPath extends GeoBaseExtendedShape implements GeoDistanceShape
|
|||||||
return point.linearDistance(normLineX, normLineY, normLineZ) + start.linearDistance(normLineX, normLineY, normLineZ);
|
return point.linearDistance(normLineX, normLineY, normLineZ) + start.linearDistance(normLineX, normLineY, normLineZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds) {
|
||||||
{
|
|
||||||
return upperConnectingPlane.intersects(p, notablePoints, upperConnectingPlanePoints, bounds, lowerConnectingPlane, startCutoffPlane, endCutoffPlane) ||
|
return upperConnectingPlane.intersects(p, notablePoints, upperConnectingPlanePoints, bounds, lowerConnectingPlane, startCutoffPlane, endCutoffPlane) ||
|
||||||
lowerConnectingPlane.intersects(p, notablePoints, lowerConnectingPlanePoints, bounds, upperConnectingPlane, startCutoffPlane, endCutoffPlane);
|
lowerConnectingPlane.intersects(p, notablePoints, lowerConnectingPlanePoints, bounds, upperConnectingPlane, startCutoffPlane, endCutoffPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getBounds(Bounds bounds)
|
public void getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
// We need to do all bounding planes as well as corner points
|
// We need to do all bounding planes as well as corner points
|
||||||
bounds.addPoint(start).addPoint(end);
|
bounds.addPoint(start).addPoint(end);
|
||||||
upperConnectingPlane.recordBounds(startCutoffPlane, bounds, lowerConnectingPlane, endCutoffPlane);
|
upperConnectingPlane.recordBounds(startCutoffPlane, bounds, lowerConnectingPlane, endCutoffPlane);
|
||||||
|
@ -17,27 +17,23 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** This class represents a point on the surface of a unit sphere.
|
/**
|
||||||
|
* This class represents a point on the surface of a unit sphere.
|
||||||
*/
|
*/
|
||||||
public class GeoPoint extends Vector
|
public class GeoPoint extends Vector {
|
||||||
{
|
public GeoPoint(final double sinLat, final double sinLon, final double cosLat, final double cosLon) {
|
||||||
public GeoPoint(final double sinLat, final double sinLon, final double cosLat, final double cosLon)
|
|
||||||
{
|
|
||||||
super(cosLat * cosLon, cosLat * sinLon, sinLat);
|
super(cosLat * cosLon, cosLat * sinLon, sinLat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeoPoint(final double lat, final double lon)
|
public GeoPoint(final double lat, final double lon) {
|
||||||
{
|
|
||||||
this(Math.sin(lat), Math.sin(lon), Math.cos(lat), Math.cos(lon));
|
this(Math.sin(lat), Math.sin(lon), Math.cos(lat), Math.cos(lon));
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeoPoint(final double x, final double y, final double z)
|
public GeoPoint(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
super(x, y, z);
|
super(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double arcDistance(final GeoPoint v)
|
public double arcDistance(final GeoPoint v) {
|
||||||
{
|
|
||||||
return Tools.safeAcos(dotProduct(v));
|
return Tools.safeAcos(dotProduct(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,14 +21,16 @@ import java.util.ArrayList;
|
|||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** Class which constructs a GeoMembershipShape representing an arbitrary polygon.
|
/**
|
||||||
|
* Class which constructs a GeoMembershipShape representing an arbitrary polygon.
|
||||||
*/
|
*/
|
||||||
public class GeoPolygonFactory
|
public class GeoPolygonFactory {
|
||||||
{
|
|
||||||
private GeoPolygonFactory() {
|
private GeoPolygonFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a GeoMembershipShape of the right kind given the specified bounds.
|
/**
|
||||||
|
* Create a GeoMembershipShape of the right kind given the specified bounds.
|
||||||
|
*
|
||||||
* @param pointList is a list of the GeoPoints to build an arbitrary polygon out of.
|
* @param pointList is a list of the GeoPoints to build an arbitrary polygon out of.
|
||||||
* @param convexPointIndex is the index of a single convex point whose conformation with
|
* @param convexPointIndex is the index of a single convex point whose conformation with
|
||||||
* its neighbors determines inside/outside for the entire polygon.
|
* its neighbors determines inside/outside for the entire polygon.
|
||||||
|
@ -17,12 +17,12 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Bounding box limited on four sides (top lat, bottom lat, left lon, right lon).
|
/**
|
||||||
|
* Bounding box limited on four sides (top lat, bottom lat, left lon, right lon).
|
||||||
* The left-right maximum extent for this shape is PI; for anything larger, use
|
* The left-right maximum extent for this shape is PI; for anything larger, use
|
||||||
* GeoWideRectangle.
|
* GeoWideRectangle.
|
||||||
*/
|
*/
|
||||||
public class GeoRectangle extends GeoBBoxBase
|
public class GeoRectangle extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double topLat;
|
public final double topLat;
|
||||||
public final double bottomLat;
|
public final double bottomLat;
|
||||||
public final double leftLon;
|
public final double leftLon;
|
||||||
@ -49,9 +49,10 @@ public class GeoRectangle extends GeoBBoxBase
|
|||||||
|
|
||||||
public final GeoPoint[] edgePoints;
|
public final GeoPoint[] edgePoints;
|
||||||
|
|
||||||
/** Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI} */
|
/**
|
||||||
public GeoRectangle(final double topLat, final double bottomLat, final double leftLon, double rightLon)
|
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}
|
||||||
{
|
*/
|
||||||
|
public GeoRectangle(final double topLat, final double bottomLat, final double leftLon, double rightLon) {
|
||||||
// Argument checking
|
// Argument checking
|
||||||
if (topLat > Math.PI * 0.5 || topLat < -Math.PI * 0.5)
|
if (topLat > Math.PI * 0.5 || topLat < -Math.PI * 0.5)
|
||||||
throw new IllegalArgumentException("Top latitude out of range");
|
throw new IllegalArgumentException("Top latitude out of range");
|
||||||
@ -117,8 +118,7 @@ public class GeoRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
final double newTopLat = topLat + angle;
|
final double newTopLat = topLat + angle;
|
||||||
final double newBottomLat = bottomLat - angle;
|
final double newBottomLat = bottomLat - angle;
|
||||||
// Figuring out when we escalate to a special case requires some prefiguring
|
// Figuring out when we escalate to a special case requires some prefiguring
|
||||||
@ -135,8 +135,7 @@ public class GeoRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return topPlane.isWithin(point) &&
|
return topPlane.isWithin(point) &&
|
||||||
bottomPlane.isWithin(point) &&
|
bottomPlane.isWithin(point) &&
|
||||||
leftPlane.isWithin(point) &&
|
leftPlane.isWithin(point) &&
|
||||||
@ -144,8 +143,7 @@ public class GeoRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return topPlane.isWithin(x, y, z) &&
|
return topPlane.isWithin(x, y, z) &&
|
||||||
bottomPlane.isWithin(x, y, z) &&
|
bottomPlane.isWithin(x, y, z) &&
|
||||||
leftPlane.isWithin(x, y, z) &&
|
leftPlane.isWithin(x, y, z) &&
|
||||||
@ -153,8 +151,7 @@ public class GeoRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
||||||
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
||||||
// the distance to the right or left edge from the center.
|
// the distance to the right or left edge from the center.
|
||||||
@ -169,7 +166,9 @@ public class GeoRectangle extends GeoBBoxBase
|
|||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -178,15 +177,16 @@ public class GeoRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
return p.intersects(topPlane, notablePoints, topPlanePoints, bounds, bottomPlane, leftPlane, rightPlane) ||
|
return p.intersects(topPlane, notablePoints, topPlanePoints, bounds, bottomPlane, leftPlane, rightPlane) ||
|
||||||
p.intersects(bottomPlane, notablePoints, bottomPlanePoints, bounds, topPlane, leftPlane, rightPlane) ||
|
p.intersects(bottomPlane, notablePoints, bottomPlanePoints, bounds, topPlane, leftPlane, rightPlane) ||
|
||||||
p.intersects(leftPlane, notablePoints, leftPlanePoints, bounds, rightPlane, topPlane, bottomPlane) ||
|
p.intersects(leftPlane, notablePoints, leftPlanePoints, bounds, rightPlane, topPlane, bottomPlane) ||
|
||||||
p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, leftPlane, topPlane, bottomPlane);
|
p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, leftPlane, topPlane, bottomPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -194,8 +194,7 @@ public class GeoRectangle extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.addLatitudeZone(topLat).addLatitudeZone(bottomLat)
|
bounds.addLatitudeZone(topLat).addLatitudeZone(bottomLat)
|
||||||
@ -207,8 +206,7 @@ public class GeoRectangle extends GeoBBoxBase
|
|||||||
public int getRelationship(final GeoShape path) {
|
public int getRelationship(final GeoShape path) {
|
||||||
//System.err.println(this+" getrelationship with "+path);
|
//System.err.println(this+" getrelationship with "+path);
|
||||||
final int insideRectangle = isShapeInsideBBox(path);
|
final int insideRectangle = isShapeInsideBBox(path);
|
||||||
if (insideRectangle == SOME_INSIDE)
|
if (insideRectangle == SOME_INSIDE) {
|
||||||
{
|
|
||||||
//System.err.println(" some inside");
|
//System.err.println(" some inside");
|
||||||
return OVERLAPS;
|
return OVERLAPS;
|
||||||
}
|
}
|
||||||
@ -228,8 +226,7 @@ public class GeoRectangle extends GeoBBoxBase
|
|||||||
return OVERLAPS;
|
return OVERLAPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insideRectangle == ALL_INSIDE)
|
if (insideRectangle == ALL_INSIDE) {
|
||||||
{
|
|
||||||
//System.err.println(" shape inside rectangle");
|
//System.err.println(" shape inside rectangle");
|
||||||
return WITHIN;
|
return WITHIN;
|
||||||
}
|
}
|
||||||
@ -243,8 +240,7 @@ public class GeoRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoRectangle))
|
if (!(o instanceof GeoRectangle))
|
||||||
return false;
|
return false;
|
||||||
GeoRectangle other = (GeoRectangle) o;
|
GeoRectangle other = (GeoRectangle) o;
|
||||||
|
@ -17,24 +17,29 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Generic shape. This describes methods that help GeoAreas figure out
|
/**
|
||||||
|
* Generic shape. This describes methods that help GeoAreas figure out
|
||||||
* how they interact with a shape, for the purposes of coming up with a
|
* how they interact with a shape, for the purposes of coming up with a
|
||||||
* set of geo hash values.
|
* set of geo hash values.
|
||||||
*/
|
*/
|
||||||
public interface GeoShape extends Membership {
|
public interface GeoShape extends Membership {
|
||||||
|
|
||||||
/** Return a sample point that is on the outside edge/boundary of the shape.
|
/**
|
||||||
|
* Return a sample point that is on the outside edge/boundary of the shape.
|
||||||
|
*
|
||||||
* @return samples of all edge points from distinct edge sections. Typically one point
|
* @return samples of all edge points from distinct edge sections. Typically one point
|
||||||
* is returned, but zero or two are also possible.
|
* is returned, but zero or two are also possible.
|
||||||
*/
|
*/
|
||||||
public GeoPoint[] getEdgePoints();
|
public GeoPoint[] getEdgePoints();
|
||||||
|
|
||||||
/** Assess whether a plane, within the provided bounds, intersects
|
/**
|
||||||
|
* Assess whether a plane, within the provided bounds, intersects
|
||||||
* with the shape. Note well that this method is allowed to return "true"
|
* with the shape. Note well that this method is allowed to return "true"
|
||||||
* if there are internal edges of a composite shape which intersect the plane.
|
* if there are internal edges of a composite shape which intersect the plane.
|
||||||
* Doing this can cause getRelationship() for most GeoBBox shapes to return
|
* Doing this can cause getRelationship() for most GeoBBox shapes to return
|
||||||
* OVERLAPS rather than the more correct CONTAINS, but that cannot be
|
* OVERLAPS rather than the more correct CONTAINS, but that cannot be
|
||||||
* helped for some complex shapes that are built out of overlapping parts.
|
* helped for some complex shapes that are built out of overlapping parts.
|
||||||
|
*
|
||||||
* @param plane is the plane to assess for intersection with the shape's edges or
|
* @param plane is the plane to assess for intersection with the shape's edges or
|
||||||
* bounding curves.
|
* bounding curves.
|
||||||
* @param notablePoints represents the intersections of the plane with the supplied
|
* @param notablePoints represents the intersections of the plane with the supplied
|
||||||
@ -46,7 +51,9 @@ public interface GeoShape extends Membership {
|
|||||||
*/
|
*/
|
||||||
public boolean intersects(final Plane plane, final GeoPoint[] notablePoints, final Membership... bounds);
|
public boolean intersects(final Plane plane, final GeoPoint[] notablePoints, final Membership... bounds);
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -55,6 +62,8 @@ public interface GeoShape extends Membership {
|
|||||||
*/
|
*/
|
||||||
public Bounds getBounds(final Bounds bounds);
|
public Bounds getBounds(final Bounds bounds);
|
||||||
|
|
||||||
/** Equals */
|
/**
|
||||||
|
* Equals
|
||||||
|
*/
|
||||||
public boolean equals(Object o);
|
public boolean equals(Object o);
|
||||||
}
|
}
|
||||||
|
@ -17,17 +17,21 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Some shapes can compute radii of a geocircle in which they are inscribed.
|
/**
|
||||||
|
* Some shapes can compute radii of a geocircle in which they are inscribed.
|
||||||
*/
|
*/
|
||||||
public interface GeoSizeable
|
public interface GeoSizeable {
|
||||||
{
|
/**
|
||||||
/** Returns the radius of a circle into which the GeoSizeable area can
|
* Returns the radius of a circle into which the GeoSizeable area can
|
||||||
* be inscribed.
|
* be inscribed.
|
||||||
|
*
|
||||||
* @return the radius.
|
* @return the radius.
|
||||||
*/
|
*/
|
||||||
public double getRadius();
|
public double getRadius();
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
public GeoPoint getCenter();
|
public GeoPoint getCenter();
|
||||||
|
@ -17,10 +17,10 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** This GeoBBox represents an area rectangle limited only in north latitude.
|
/**
|
||||||
|
* This GeoBBox represents an area rectangle limited only in north latitude.
|
||||||
*/
|
*/
|
||||||
public class GeoSouthLatitudeZone extends GeoBBoxBase
|
public class GeoSouthLatitudeZone extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double topLat;
|
public final double topLat;
|
||||||
public final double cosTopLat;
|
public final double cosTopLat;
|
||||||
public final SidedPlane topPlane;
|
public final SidedPlane topPlane;
|
||||||
@ -32,8 +32,7 @@ public class GeoSouthLatitudeZone extends GeoBBoxBase
|
|||||||
// Edge points
|
// Edge points
|
||||||
public final GeoPoint[] edgePoints;
|
public final GeoPoint[] edgePoints;
|
||||||
|
|
||||||
public GeoSouthLatitudeZone(final double topLat)
|
public GeoSouthLatitudeZone(final double topLat) {
|
||||||
{
|
|
||||||
this.topLat = topLat;
|
this.topLat = topLat;
|
||||||
|
|
||||||
final double sinTopLat = Math.sin(topLat);
|
final double sinTopLat = Math.sin(topLat);
|
||||||
@ -54,28 +53,24 @@ public class GeoSouthLatitudeZone extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
final double newTopLat = topLat + angle;
|
final double newTopLat = topLat + angle;
|
||||||
final double newBottomLat = -Math.PI * 0.5;
|
final double newBottomLat = -Math.PI * 0.5;
|
||||||
return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, -Math.PI, Math.PI);
|
return GeoBBoxFactory.makeGeoBBox(newTopLat, newBottomLat, -Math.PI, Math.PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return topPlane.isWithin(point);
|
return topPlane.isWithin(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return topPlane.isWithin(x, y, z);
|
return topPlane.isWithin(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// This is a bit tricky. I guess we should interpret this as meaning the angle of a circle that
|
// This is a bit tricky. I guess we should interpret this as meaning the angle of a circle that
|
||||||
// would contain all the bounding box points, when starting in the "center".
|
// would contain all the bounding box points, when starting in the "center".
|
||||||
if (topLat > 0.0)
|
if (topLat > 0.0)
|
||||||
@ -84,7 +79,9 @@ public class GeoSouthLatitudeZone extends GeoBBoxBase
|
|||||||
return maxCosLat * Math.PI;
|
return maxCosLat * Math.PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -93,18 +90,18 @@ public class GeoSouthLatitudeZone extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
return p.intersects(topPlane, notablePoints, planePoints, bounds);
|
return p.intersects(topPlane, notablePoints, planePoints, bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -112,8 +109,7 @@ public class GeoSouthLatitudeZone extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.noLongitudeBound().addLatitudeZone(topLat).noBottomLatitudeBound();
|
bounds.noLongitudeBound().addLatitudeZone(topLat).noBottomLatitudeBound();
|
||||||
@ -153,8 +149,7 @@ public class GeoSouthLatitudeZone extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoSouthLatitudeZone))
|
if (!(o instanceof GeoSouthLatitudeZone))
|
||||||
return false;
|
return false;
|
||||||
GeoSouthLatitudeZone other = (GeoSouthLatitudeZone) o;
|
GeoSouthLatitudeZone other = (GeoSouthLatitudeZone) o;
|
||||||
|
@ -17,13 +17,13 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Bounding box limited on three sides (top lat, left lon, right lon). The
|
/**
|
||||||
|
* Bounding box limited on three sides (top lat, left lon, right lon). The
|
||||||
* other corner is the south pole.
|
* other corner is the south pole.
|
||||||
* The left-right maximum extent for this shape is PI; for anything larger, use
|
* The left-right maximum extent for this shape is PI; for anything larger, use
|
||||||
* GeoWideSouthRectangle.
|
* GeoWideSouthRectangle.
|
||||||
*/
|
*/
|
||||||
public class GeoSouthRectangle extends GeoBBoxBase
|
public class GeoSouthRectangle extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double topLat;
|
public final double topLat;
|
||||||
public final double leftLon;
|
public final double leftLon;
|
||||||
public final double rightLon;
|
public final double rightLon;
|
||||||
@ -45,9 +45,10 @@ public class GeoSouthRectangle extends GeoBBoxBase
|
|||||||
|
|
||||||
public final GeoPoint[] edgePoints = new GeoPoint[]{SOUTH_POLE};
|
public final GeoPoint[] edgePoints = new GeoPoint[]{SOUTH_POLE};
|
||||||
|
|
||||||
/** Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI} */
|
/**
|
||||||
public GeoSouthRectangle(final double topLat, final double leftLon, double rightLon)
|
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}
|
||||||
{
|
*/
|
||||||
|
public GeoSouthRectangle(final double topLat, final double leftLon, double rightLon) {
|
||||||
// Argument checking
|
// Argument checking
|
||||||
if (topLat > Math.PI * 0.5 || topLat < -Math.PI * 0.5)
|
if (topLat > Math.PI * 0.5 || topLat < -Math.PI * 0.5)
|
||||||
throw new IllegalArgumentException("Top latitude out of range");
|
throw new IllegalArgumentException("Top latitude out of range");
|
||||||
@ -100,8 +101,7 @@ public class GeoSouthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
final double newTopLat = topLat + angle;
|
final double newTopLat = topLat + angle;
|
||||||
final double newBottomLat = -Math.PI * 0.5;
|
final double newBottomLat = -Math.PI * 0.5;
|
||||||
// Figuring out when we escalate to a special case requires some prefiguring
|
// Figuring out when we escalate to a special case requires some prefiguring
|
||||||
@ -118,24 +118,21 @@ public class GeoSouthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return topPlane.isWithin(point) &&
|
return topPlane.isWithin(point) &&
|
||||||
leftPlane.isWithin(point) &&
|
leftPlane.isWithin(point) &&
|
||||||
rightPlane.isWithin(point);
|
rightPlane.isWithin(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return topPlane.isWithin(x, y, z) &&
|
return topPlane.isWithin(x, y, z) &&
|
||||||
leftPlane.isWithin(x, y, z) &&
|
leftPlane.isWithin(x, y, z) &&
|
||||||
rightPlane.isWithin(x, y, z);
|
rightPlane.isWithin(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
||||||
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
||||||
// the distance to the right or left edge from the center.
|
// the distance to the right or left edge from the center.
|
||||||
@ -145,12 +142,13 @@ public class GeoSouthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -159,14 +157,15 @@ public class GeoSouthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
return p.intersects(topPlane, notablePoints, topPlanePoints, bounds, leftPlane, rightPlane) ||
|
return p.intersects(topPlane, notablePoints, topPlanePoints, bounds, leftPlane, rightPlane) ||
|
||||||
p.intersects(leftPlane, notablePoints, leftPlanePoints, bounds, rightPlane, topPlane) ||
|
p.intersects(leftPlane, notablePoints, leftPlanePoints, bounds, rightPlane, topPlane) ||
|
||||||
p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, leftPlane, topPlane);
|
p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, leftPlane, topPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -174,8 +173,7 @@ public class GeoSouthRectangle extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.addLatitudeZone(topLat).noBottomLatitudeBound()
|
bounds.addLatitudeZone(topLat).noBottomLatitudeBound()
|
||||||
@ -187,8 +185,7 @@ public class GeoSouthRectangle extends GeoBBoxBase
|
|||||||
public int getRelationship(final GeoShape path) {
|
public int getRelationship(final GeoShape path) {
|
||||||
//System.err.println(this+" getrelationship with "+path);
|
//System.err.println(this+" getrelationship with "+path);
|
||||||
final int insideRectangle = isShapeInsideBBox(path);
|
final int insideRectangle = isShapeInsideBBox(path);
|
||||||
if (insideRectangle == SOME_INSIDE)
|
if (insideRectangle == SOME_INSIDE) {
|
||||||
{
|
|
||||||
//System.err.println(" some inside");
|
//System.err.println(" some inside");
|
||||||
return OVERLAPS;
|
return OVERLAPS;
|
||||||
}
|
}
|
||||||
@ -207,8 +204,7 @@ public class GeoSouthRectangle extends GeoBBoxBase
|
|||||||
return OVERLAPS;
|
return OVERLAPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insideRectangle == ALL_INSIDE)
|
if (insideRectangle == ALL_INSIDE) {
|
||||||
{
|
|
||||||
//System.err.println(" shape inside rectangle");
|
//System.err.println(" shape inside rectangle");
|
||||||
return WITHIN;
|
return WITHIN;
|
||||||
}
|
}
|
||||||
@ -222,8 +218,7 @@ public class GeoSouthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoSouthRectangle))
|
if (!(o instanceof GeoSouthRectangle))
|
||||||
return false;
|
return false;
|
||||||
GeoSouthRectangle other = (GeoSouthRectangle) o;
|
GeoSouthRectangle other = (GeoSouthRectangle) o;
|
||||||
|
@ -17,10 +17,10 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Degenerate bounding box wider than PI and limited on two sides (left lon, right lon).
|
/**
|
||||||
|
* Degenerate bounding box wider than PI and limited on two sides (left lon, right lon).
|
||||||
*/
|
*/
|
||||||
public class GeoWideDegenerateHorizontalLine extends GeoBBoxBase
|
public class GeoWideDegenerateHorizontalLine extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double latitude;
|
public final double latitude;
|
||||||
public final double leftLon;
|
public final double leftLon;
|
||||||
public final double rightLon;
|
public final double rightLon;
|
||||||
@ -40,11 +40,11 @@ public class GeoWideDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
|
|
||||||
public final GeoPoint[] edgePoints;
|
public final GeoPoint[] edgePoints;
|
||||||
|
|
||||||
/** Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}.
|
/**
|
||||||
|
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}.
|
||||||
* Horizontal angle must be greater than or equal to PI.
|
* Horizontal angle must be greater than or equal to PI.
|
||||||
*/
|
*/
|
||||||
public GeoWideDegenerateHorizontalLine(final double latitude, final double leftLon, double rightLon)
|
public GeoWideDegenerateHorizontalLine(final double latitude, final double leftLon, double rightLon) {
|
||||||
{
|
|
||||||
// Argument checking
|
// Argument checking
|
||||||
if (latitude > Math.PI * 0.5 || latitude < -Math.PI * 0.5)
|
if (latitude > Math.PI * 0.5 || latitude < -Math.PI * 0.5)
|
||||||
throw new IllegalArgumentException("Latitude out of range");
|
throw new IllegalArgumentException("Latitude out of range");
|
||||||
@ -97,8 +97,7 @@ public class GeoWideDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
final double newTopLat = latitude + angle;
|
final double newTopLat = latitude + angle;
|
||||||
final double newBottomLat = latitude - angle;
|
final double newBottomLat = latitude - angle;
|
||||||
// Figuring out when we escalate to a special case requires some prefiguring
|
// Figuring out when we escalate to a special case requires some prefiguring
|
||||||
@ -115,8 +114,7 @@ public class GeoWideDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
if (point == null)
|
if (point == null)
|
||||||
return false;
|
return false;
|
||||||
return plane.evaluateIsZero(point) &&
|
return plane.evaluateIsZero(point) &&
|
||||||
@ -125,16 +123,14 @@ public class GeoWideDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return plane.evaluateIsZero(x, y, z) &&
|
return plane.evaluateIsZero(x, y, z) &&
|
||||||
(leftPlane.isWithin(x, y, z) ||
|
(leftPlane.isWithin(x, y, z) ||
|
||||||
rightPlane.isWithin(x, y, z));
|
rightPlane.isWithin(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
||||||
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
||||||
// the distance to the right or left edge from the center.
|
// the distance to the right or left edge from the center.
|
||||||
@ -143,7 +139,9 @@ public class GeoWideDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
return Math.max(topAngle, bottomAngle);
|
return Math.max(topAngle, bottomAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -152,20 +150,20 @@ public class GeoWideDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
// Right and left bounds are essentially independent hemispheres; crossing into the wrong part of one
|
// Right and left bounds are essentially independent hemispheres; crossing into the wrong part of one
|
||||||
// requires crossing into the right part of the other. So intersection can ignore the left/right bounds.
|
// requires crossing into the right part of the other. So intersection can ignore the left/right bounds.
|
||||||
return p.intersects(plane, notablePoints, planePoints, bounds, eitherBound);
|
return p.intersects(plane, notablePoints, planePoints, bounds, eitherBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -173,8 +171,7 @@ public class GeoWideDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.addLatitudeZone(latitude)
|
bounds.addLatitudeZone(latitude)
|
||||||
@ -196,8 +193,7 @@ public class GeoWideDegenerateHorizontalLine extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoWideDegenerateHorizontalLine))
|
if (!(o instanceof GeoWideDegenerateHorizontalLine))
|
||||||
return false;
|
return false;
|
||||||
GeoWideDegenerateHorizontalLine other = (GeoWideDegenerateHorizontalLine) o;
|
GeoWideDegenerateHorizontalLine other = (GeoWideDegenerateHorizontalLine) o;
|
||||||
|
@ -17,11 +17,11 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Bounding box wider than PI but limited on left and right sides (
|
/**
|
||||||
|
* Bounding box wider than PI but limited on left and right sides (
|
||||||
* left lon, right lon).
|
* left lon, right lon).
|
||||||
*/
|
*/
|
||||||
public class GeoWideLongitudeSlice extends GeoBBoxBase
|
public class GeoWideLongitudeSlice extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double leftLon;
|
public final double leftLon;
|
||||||
public final double rightLon;
|
public final double rightLon;
|
||||||
|
|
||||||
@ -34,11 +34,11 @@ public class GeoWideLongitudeSlice extends GeoBBoxBase
|
|||||||
|
|
||||||
public final static GeoPoint[] edgePoints = new GeoPoint[]{NORTH_POLE};
|
public final static GeoPoint[] edgePoints = new GeoPoint[]{NORTH_POLE};
|
||||||
|
|
||||||
/** Accepts only values in the following ranges: lon: {@code -PI -> PI}.
|
/**
|
||||||
|
* Accepts only values in the following ranges: lon: {@code -PI -> PI}.
|
||||||
* Horizantal angle must be greater than or equal to PI.
|
* Horizantal angle must be greater than or equal to PI.
|
||||||
*/
|
*/
|
||||||
public GeoWideLongitudeSlice(final double leftLon, double rightLon)
|
public GeoWideLongitudeSlice(final double leftLon, double rightLon) {
|
||||||
{
|
|
||||||
// Argument checking
|
// Argument checking
|
||||||
if (leftLon < -Math.PI || leftLon > Math.PI)
|
if (leftLon < -Math.PI || leftLon > Math.PI)
|
||||||
throw new IllegalArgumentException("Left longitude out of range");
|
throw new IllegalArgumentException("Left longitude out of range");
|
||||||
@ -71,8 +71,7 @@ public class GeoWideLongitudeSlice extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
// Figuring out when we escalate to a special case requires some prefiguring
|
// Figuring out when we escalate to a special case requires some prefiguring
|
||||||
double currentLonSpan = rightLon - leftLon;
|
double currentLonSpan = rightLon - leftLon;
|
||||||
if (currentLonSpan < 0.0)
|
if (currentLonSpan < 0.0)
|
||||||
@ -87,22 +86,19 @@ public class GeoWideLongitudeSlice extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return leftPlane.isWithin(point) ||
|
return leftPlane.isWithin(point) ||
|
||||||
rightPlane.isWithin(point);
|
rightPlane.isWithin(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return leftPlane.isWithin(x, y, z) ||
|
return leftPlane.isWithin(x, y, z) ||
|
||||||
rightPlane.isWithin(x, y, z);
|
rightPlane.isWithin(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// Compute the extent and divide by two
|
// Compute the extent and divide by two
|
||||||
double extent = rightLon - leftLon;
|
double extent = rightLon - leftLon;
|
||||||
if (extent < 0.0)
|
if (extent < 0.0)
|
||||||
@ -110,7 +106,9 @@ public class GeoWideLongitudeSlice extends GeoBBoxBase
|
|||||||
return Math.max(Math.PI * 0.5, extent * 0.5);
|
return Math.max(Math.PI * 0.5, extent * 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -119,21 +117,21 @@ public class GeoWideLongitudeSlice extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
// Right and left bounds are essentially independent hemispheres; crossing into the wrong part of one
|
// Right and left bounds are essentially independent hemispheres; crossing into the wrong part of one
|
||||||
// requires crossing into the right part of the other. So intersection can ignore the left/right bounds.
|
// requires crossing into the right part of the other. So intersection can ignore the left/right bounds.
|
||||||
return p.intersects(leftPlane, notablePoints, planePoints, bounds) ||
|
return p.intersects(leftPlane, notablePoints, planePoints, bounds) ||
|
||||||
p.intersects(rightPlane, notablePoints, planePoints, bounds);
|
p.intersects(rightPlane, notablePoints, planePoints, bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -141,8 +139,7 @@ public class GeoWideLongitudeSlice extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.noTopLatitudeBound().noBottomLatitudeBound();
|
bounds.noTopLatitudeBound().noBottomLatitudeBound();
|
||||||
@ -175,8 +172,7 @@ public class GeoWideLongitudeSlice extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoWideLongitudeSlice))
|
if (!(o instanceof GeoWideLongitudeSlice))
|
||||||
return false;
|
return false;
|
||||||
GeoWideLongitudeSlice other = (GeoWideLongitudeSlice) o;
|
GeoWideLongitudeSlice other = (GeoWideLongitudeSlice) o;
|
||||||
|
@ -17,11 +17,11 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Bounding box wider than PI but limited on three sides (
|
/**
|
||||||
|
* Bounding box wider than PI but limited on three sides (
|
||||||
* bottom lat, left lon, right lon).
|
* bottom lat, left lon, right lon).
|
||||||
*/
|
*/
|
||||||
public class GeoWideNorthRectangle extends GeoBBoxBase
|
public class GeoWideNorthRectangle extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double bottomLat;
|
public final double bottomLat;
|
||||||
public final double leftLon;
|
public final double leftLon;
|
||||||
public final double rightLon;
|
public final double rightLon;
|
||||||
@ -45,11 +45,11 @@ public class GeoWideNorthRectangle extends GeoBBoxBase
|
|||||||
|
|
||||||
public final GeoPoint[] edgePoints = new GeoPoint[]{NORTH_POLE};
|
public final GeoPoint[] edgePoints = new GeoPoint[]{NORTH_POLE};
|
||||||
|
|
||||||
/** Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}.
|
/**
|
||||||
|
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}.
|
||||||
* Horizontal angle must be greater than or equal to PI.
|
* Horizontal angle must be greater than or equal to PI.
|
||||||
*/
|
*/
|
||||||
public GeoWideNorthRectangle(final double bottomLat, final double leftLon, double rightLon)
|
public GeoWideNorthRectangle(final double bottomLat, final double leftLon, double rightLon) {
|
||||||
{
|
|
||||||
// Argument checking
|
// Argument checking
|
||||||
if (bottomLat > Math.PI * 0.5 || bottomLat < -Math.PI * 0.5)
|
if (bottomLat > Math.PI * 0.5 || bottomLat < -Math.PI * 0.5)
|
||||||
throw new IllegalArgumentException("Bottom latitude out of range");
|
throw new IllegalArgumentException("Bottom latitude out of range");
|
||||||
@ -104,8 +104,7 @@ public class GeoWideNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
final double newTopLat = Math.PI * 0.5;
|
final double newTopLat = Math.PI * 0.5;
|
||||||
final double newBottomLat = bottomLat - angle;
|
final double newBottomLat = bottomLat - angle;
|
||||||
// Figuring out when we escalate to a special case requires some prefiguring
|
// Figuring out when we escalate to a special case requires some prefiguring
|
||||||
@ -122,8 +121,7 @@ public class GeoWideNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return
|
return
|
||||||
bottomPlane.isWithin(point) &&
|
bottomPlane.isWithin(point) &&
|
||||||
(leftPlane.isWithin(point) ||
|
(leftPlane.isWithin(point) ||
|
||||||
@ -131,8 +129,7 @@ public class GeoWideNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return
|
return
|
||||||
bottomPlane.isWithin(x, y, z) &&
|
bottomPlane.isWithin(x, y, z) &&
|
||||||
(leftPlane.isWithin(x, y, z) ||
|
(leftPlane.isWithin(x, y, z) ||
|
||||||
@ -140,8 +137,7 @@ public class GeoWideNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
||||||
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
||||||
// the distance to the right or left edge from the center.
|
// the distance to the right or left edge from the center.
|
||||||
@ -150,7 +146,9 @@ public class GeoWideNorthRectangle extends GeoBBoxBase
|
|||||||
return Math.max(centerAngle, bottomAngle);
|
return Math.max(centerAngle, bottomAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -159,14 +157,12 @@ public class GeoWideNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
// Right and left bounds are essentially independent hemispheres; crossing into the wrong part of one
|
// Right and left bounds are essentially independent hemispheres; crossing into the wrong part of one
|
||||||
// requires crossing into the right part of the other. So intersection can ignore the left/right bounds.
|
// requires crossing into the right part of the other. So intersection can ignore the left/right bounds.
|
||||||
return
|
return
|
||||||
@ -175,7 +171,9 @@ public class GeoWideNorthRectangle extends GeoBBoxBase
|
|||||||
p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, bottomPlane);
|
p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, bottomPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -183,8 +181,7 @@ public class GeoWideNorthRectangle extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.noTopLatitudeBound().addLatitudeZone(bottomLat)
|
bounds.noTopLatitudeBound().addLatitudeZone(bottomLat)
|
||||||
@ -203,8 +200,7 @@ public class GeoWideNorthRectangle extends GeoBBoxBase
|
|||||||
|
|
||||||
final boolean insideShape = path.isWithin(NORTH_POLE);
|
final boolean insideShape = path.isWithin(NORTH_POLE);
|
||||||
|
|
||||||
if (insideRectangle == ALL_INSIDE && insideShape)
|
if (insideRectangle == ALL_INSIDE && insideShape) {
|
||||||
{
|
|
||||||
//System.err.println(" both inside each other");
|
//System.err.println(" both inside each other");
|
||||||
return OVERLAPS;
|
return OVERLAPS;
|
||||||
}
|
}
|
||||||
@ -232,8 +228,7 @@ public class GeoWideNorthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoWideNorthRectangle))
|
if (!(o instanceof GeoWideNorthRectangle))
|
||||||
return false;
|
return false;
|
||||||
GeoWideNorthRectangle other = (GeoWideNorthRectangle) o;
|
GeoWideNorthRectangle other = (GeoWideNorthRectangle) o;
|
||||||
|
@ -17,11 +17,11 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Bounding box wider than PI but limited on four sides (top lat,
|
/**
|
||||||
|
* Bounding box wider than PI but limited on four sides (top lat,
|
||||||
* bottom lat, left lon, right lon).
|
* bottom lat, left lon, right lon).
|
||||||
*/
|
*/
|
||||||
public class GeoWideRectangle extends GeoBBoxBase
|
public class GeoWideRectangle extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double topLat;
|
public final double topLat;
|
||||||
public final double bottomLat;
|
public final double bottomLat;
|
||||||
public final double leftLon;
|
public final double leftLon;
|
||||||
@ -50,11 +50,11 @@ public class GeoWideRectangle extends GeoBBoxBase
|
|||||||
|
|
||||||
public final GeoPoint[] edgePoints;
|
public final GeoPoint[] edgePoints;
|
||||||
|
|
||||||
/** Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}.
|
/**
|
||||||
|
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}.
|
||||||
* Horizontal angle must be greater than or equal to PI.
|
* Horizontal angle must be greater than or equal to PI.
|
||||||
*/
|
*/
|
||||||
public GeoWideRectangle(final double topLat, final double bottomLat, final double leftLon, double rightLon)
|
public GeoWideRectangle(final double topLat, final double bottomLat, final double leftLon, double rightLon) {
|
||||||
{
|
|
||||||
// Argument checking
|
// Argument checking
|
||||||
if (topLat > Math.PI * 0.5 || topLat < -Math.PI * 0.5)
|
if (topLat > Math.PI * 0.5 || topLat < -Math.PI * 0.5)
|
||||||
throw new IllegalArgumentException("Top latitude out of range");
|
throw new IllegalArgumentException("Top latitude out of range");
|
||||||
@ -122,8 +122,7 @@ public class GeoWideRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
final double newTopLat = topLat + angle;
|
final double newTopLat = topLat + angle;
|
||||||
final double newBottomLat = bottomLat - angle;
|
final double newBottomLat = bottomLat - angle;
|
||||||
// Figuring out when we escalate to a special case requires some prefiguring
|
// Figuring out when we escalate to a special case requires some prefiguring
|
||||||
@ -140,8 +139,7 @@ public class GeoWideRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return topPlane.isWithin(point) &&
|
return topPlane.isWithin(point) &&
|
||||||
bottomPlane.isWithin(point) &&
|
bottomPlane.isWithin(point) &&
|
||||||
(leftPlane.isWithin(point) ||
|
(leftPlane.isWithin(point) ||
|
||||||
@ -149,8 +147,7 @@ public class GeoWideRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return topPlane.isWithin(x, y, z) &&
|
return topPlane.isWithin(x, y, z) &&
|
||||||
bottomPlane.isWithin(x, y, z) &&
|
bottomPlane.isWithin(x, y, z) &&
|
||||||
(leftPlane.isWithin(x, y, z) ||
|
(leftPlane.isWithin(x, y, z) ||
|
||||||
@ -158,8 +155,7 @@ public class GeoWideRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
||||||
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
||||||
// the distance to the right or left edge from the center.
|
// the distance to the right or left edge from the center.
|
||||||
@ -170,12 +166,13 @@ public class GeoWideRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -184,8 +181,7 @@ public class GeoWideRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
// Right and left bounds are essentially independent hemispheres; crossing into the wrong part of one
|
// Right and left bounds are essentially independent hemispheres; crossing into the wrong part of one
|
||||||
// requires crossing into the right part of the other. So intersection can ignore the left/right bounds.
|
// requires crossing into the right part of the other. So intersection can ignore the left/right bounds.
|
||||||
return p.intersects(topPlane, notablePoints, topPlanePoints, bounds, bottomPlane, eitherBound) ||
|
return p.intersects(topPlane, notablePoints, topPlanePoints, bounds, bottomPlane, eitherBound) ||
|
||||||
@ -194,7 +190,9 @@ public class GeoWideRectangle extends GeoBBoxBase
|
|||||||
p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, topPlane, bottomPlane);
|
p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, topPlane, bottomPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -202,8 +200,7 @@ public class GeoWideRectangle extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.addLatitudeZone(topLat).addLatitudeZone(bottomLat)
|
bounds.addLatitudeZone(topLat).addLatitudeZone(bottomLat)
|
||||||
@ -222,8 +219,7 @@ public class GeoWideRectangle extends GeoBBoxBase
|
|||||||
|
|
||||||
final boolean insideShape = path.isWithin(ULHC);
|
final boolean insideShape = path.isWithin(ULHC);
|
||||||
|
|
||||||
if (insideRectangle == ALL_INSIDE && insideShape)
|
if (insideRectangle == ALL_INSIDE && insideShape) {
|
||||||
{
|
|
||||||
//System.err.println(" both inside each other");
|
//System.err.println(" both inside each other");
|
||||||
return OVERLAPS;
|
return OVERLAPS;
|
||||||
}
|
}
|
||||||
@ -251,8 +247,7 @@ public class GeoWideRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoWideRectangle))
|
if (!(o instanceof GeoWideRectangle))
|
||||||
return false;
|
return false;
|
||||||
GeoWideRectangle other = (GeoWideRectangle) o;
|
GeoWideRectangle other = (GeoWideRectangle) o;
|
||||||
|
@ -17,11 +17,11 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Bounding box wider than PI but limited on three sides (top lat,
|
/**
|
||||||
|
* Bounding box wider than PI but limited on three sides (top lat,
|
||||||
* left lon, right lon).
|
* left lon, right lon).
|
||||||
*/
|
*/
|
||||||
public class GeoWideSouthRectangle extends GeoBBoxBase
|
public class GeoWideSouthRectangle extends GeoBBoxBase {
|
||||||
{
|
|
||||||
public final double topLat;
|
public final double topLat;
|
||||||
public final double leftLon;
|
public final double leftLon;
|
||||||
public final double rightLon;
|
public final double rightLon;
|
||||||
@ -45,11 +45,11 @@ public class GeoWideSouthRectangle extends GeoBBoxBase
|
|||||||
|
|
||||||
public final GeoPoint[] edgePoints = new GeoPoint[]{SOUTH_POLE};
|
public final GeoPoint[] edgePoints = new GeoPoint[]{SOUTH_POLE};
|
||||||
|
|
||||||
/** Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}.
|
/**
|
||||||
|
* Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}.
|
||||||
* Horizontal angle must be greater than or equal to PI.
|
* Horizontal angle must be greater than or equal to PI.
|
||||||
*/
|
*/
|
||||||
public GeoWideSouthRectangle(final double topLat, final double leftLon, double rightLon)
|
public GeoWideSouthRectangle(final double topLat, final double leftLon, double rightLon) {
|
||||||
{
|
|
||||||
// Argument checking
|
// Argument checking
|
||||||
if (topLat > Math.PI * 0.5 || topLat < -Math.PI * 0.5)
|
if (topLat > Math.PI * 0.5 || topLat < -Math.PI * 0.5)
|
||||||
throw new IllegalArgumentException("Top latitude out of range");
|
throw new IllegalArgumentException("Top latitude out of range");
|
||||||
@ -104,8 +104,7 @@ public class GeoWideSouthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
final double newTopLat = topLat + angle;
|
final double newTopLat = topLat + angle;
|
||||||
final double newBottomLat = -Math.PI * 0.5;
|
final double newBottomLat = -Math.PI * 0.5;
|
||||||
// Figuring out when we escalate to a special case requires some prefiguring
|
// Figuring out when we escalate to a special case requires some prefiguring
|
||||||
@ -122,24 +121,21 @@ public class GeoWideSouthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return topPlane.isWithin(point) &&
|
return topPlane.isWithin(point) &&
|
||||||
(leftPlane.isWithin(point) ||
|
(leftPlane.isWithin(point) ||
|
||||||
rightPlane.isWithin(point));
|
rightPlane.isWithin(point));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return topPlane.isWithin(x, y, z) &&
|
return topPlane.isWithin(x, y, z) &&
|
||||||
(leftPlane.isWithin(x, y, z) ||
|
(leftPlane.isWithin(x, y, z) ||
|
||||||
rightPlane.isWithin(x, y, z));
|
rightPlane.isWithin(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
// Here we compute the distance from the middle point to one of the corners. However, we need to be careful
|
||||||
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
// to use the longest of three distances: the distance to a corner on the top; the distnace to a corner on the bottom, and
|
||||||
// the distance to the right or left edge from the center.
|
// the distance to the right or left edge from the center.
|
||||||
@ -148,7 +144,9 @@ public class GeoWideSouthRectangle extends GeoBBoxBase
|
|||||||
return Math.max(centerAngle, topAngle);
|
return Math.max(centerAngle, topAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -157,14 +155,12 @@ public class GeoWideSouthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
// Right and left bounds are essentially independent hemispheres; crossing into the wrong part of one
|
// Right and left bounds are essentially independent hemispheres; crossing into the wrong part of one
|
||||||
// requires crossing into the right part of the other. So intersection can ignore the left/right bounds.
|
// requires crossing into the right part of the other. So intersection can ignore the left/right bounds.
|
||||||
return p.intersects(topPlane, notablePoints, topPlanePoints, bounds, eitherBound) ||
|
return p.intersects(topPlane, notablePoints, topPlanePoints, bounds, eitherBound) ||
|
||||||
@ -172,7 +168,9 @@ public class GeoWideSouthRectangle extends GeoBBoxBase
|
|||||||
p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, topPlane);
|
p.intersects(rightPlane, notablePoints, rightPlanePoints, bounds, topPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -180,8 +178,7 @@ public class GeoWideSouthRectangle extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.addLatitudeZone(topLat).noBottomLatitudeBound()
|
bounds.addLatitudeZone(topLat).noBottomLatitudeBound()
|
||||||
@ -200,8 +197,7 @@ public class GeoWideSouthRectangle extends GeoBBoxBase
|
|||||||
|
|
||||||
final boolean insideShape = path.isWithin(SOUTH_POLE);
|
final boolean insideShape = path.isWithin(SOUTH_POLE);
|
||||||
|
|
||||||
if (insideRectangle == ALL_INSIDE && insideShape)
|
if (insideRectangle == ALL_INSIDE && insideShape) {
|
||||||
{
|
|
||||||
//System.err.println(" both inside each other");
|
//System.err.println(" both inside each other");
|
||||||
return OVERLAPS;
|
return OVERLAPS;
|
||||||
}
|
}
|
||||||
@ -228,8 +224,7 @@ public class GeoWideSouthRectangle extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoWideSouthRectangle))
|
if (!(o instanceof GeoWideSouthRectangle))
|
||||||
return false;
|
return false;
|
||||||
GeoWideSouthRectangle other = (GeoWideSouthRectangle) o;
|
GeoWideSouthRectangle other = (GeoWideSouthRectangle) o;
|
||||||
|
@ -17,30 +17,29 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Bounding box including the entire world.
|
/**
|
||||||
|
* Bounding box including the entire world.
|
||||||
*/
|
*/
|
||||||
public class GeoWorld extends GeoBBoxBase
|
public class GeoWorld extends GeoBBoxBase {
|
||||||
{
|
|
||||||
protected final static GeoPoint originPoint = new GeoPoint(1.0, 0.0, 0.0);
|
protected final static GeoPoint originPoint = new GeoPoint(1.0, 0.0, 0.0);
|
||||||
protected final static GeoPoint[] edgePoints = new GeoPoint[0];
|
protected final static GeoPoint[] edgePoints = new GeoPoint[0];
|
||||||
|
|
||||||
public GeoWorld()
|
public GeoWorld() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoBBox expand(final double angle)
|
public GeoBBox expand(final double angle) {
|
||||||
{
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getRadius()
|
public double getRadius() {
|
||||||
{
|
|
||||||
return Math.PI;
|
return Math.PI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the center of a circle into which the area will be inscribed.
|
/**
|
||||||
|
* Returns the center of a circle into which the area will be inscribed.
|
||||||
|
*
|
||||||
* @return the center.
|
* @return the center.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -50,30 +49,28 @@ public class GeoWorld extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final Vector point)
|
public boolean isWithin(final Vector point) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(final double x, final double y, final double z)
|
public boolean isWithin(final double x, final double y, final double z) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoPoint[] getEdgePoints()
|
public GeoPoint[] getEdgePoints() {
|
||||||
{
|
|
||||||
return edgePoints;
|
return edgePoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds)
|
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute longitude/latitude bounds for the shape.
|
/**
|
||||||
|
* Compute longitude/latitude bounds for the shape.
|
||||||
|
*
|
||||||
* @param bounds is the optional input bounds object. If this is null,
|
* @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.
|
* 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
|
* @return a Bounds object describing the shape's bounds. If the bounds cannot
|
||||||
@ -81,8 +78,7 @@ public class GeoWorld extends GeoBBoxBase
|
|||||||
* noTopLatitudeBound, and noBottomLatitudeBound.
|
* noTopLatitudeBound, and noBottomLatitudeBound.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bounds getBounds(Bounds bounds)
|
public Bounds getBounds(Bounds bounds) {
|
||||||
{
|
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
bounds = new Bounds();
|
bounds = new Bounds();
|
||||||
bounds.noLongitudeBound().noTopLatitudeBound().noBottomLatitudeBound();
|
bounds.noLongitudeBound().noTopLatitudeBound().noBottomLatitudeBound();
|
||||||
@ -99,8 +95,7 @@ public class GeoWorld extends GeoBBoxBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (!(o instanceof GeoWorld))
|
if (!(o instanceof GeoWorld))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -17,17 +17,22 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Interface describing 3d shape membership methods.
|
/**
|
||||||
|
* Interface describing 3d shape membership methods.
|
||||||
*/
|
*/
|
||||||
public interface Membership {
|
public interface Membership {
|
||||||
|
|
||||||
/** Check if a point is within this shape.
|
/**
|
||||||
|
* Check if a point is within this shape.
|
||||||
|
*
|
||||||
* @param point is the point to check.
|
* @param point is the point to check.
|
||||||
* @return true if the point is within this shape
|
* @return true if the point is within this shape
|
||||||
*/
|
*/
|
||||||
public boolean isWithin(final Vector point);
|
public boolean isWithin(final Vector point);
|
||||||
|
|
||||||
/** Check if a point is within this shape.
|
/**
|
||||||
|
* Check if a point is within this shape.
|
||||||
|
*
|
||||||
* @param x is x coordinate of point to check.
|
* @param x is x coordinate of point to check.
|
||||||
* @param y is y coordinate of point to check.
|
* @param y is y coordinate of point to check.
|
||||||
* @param z is z coordinate of point to check.
|
* @param z is z coordinate of point to check.
|
||||||
|
@ -17,24 +17,27 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** We know about three kinds of planes. First kind: general plain through two points and origin
|
/**
|
||||||
|
* We know about three kinds of planes. First kind: general plain through two points and origin
|
||||||
* Second kind: horizontal plane at specified height. Third kind: vertical plane with specified x and y value, through origin.
|
* Second kind: horizontal plane at specified height. Third kind: vertical plane with specified x and y value, through origin.
|
||||||
*/
|
*/
|
||||||
public class Plane extends Vector
|
public class Plane extends Vector {
|
||||||
{
|
|
||||||
protected final static GeoPoint[] NO_POINTS = new GeoPoint[0];
|
protected final static GeoPoint[] NO_POINTS = new GeoPoint[0];
|
||||||
protected final static Membership[] NO_BOUNDS = new Membership[0];
|
protected final static Membership[] NO_BOUNDS = new Membership[0];
|
||||||
|
|
||||||
public final double D;
|
public final double D;
|
||||||
|
|
||||||
/** Construct a plane with all four coefficients defined.
|
/**
|
||||||
|
* Construct a plane with all four coefficients defined.
|
||||||
*/
|
*/
|
||||||
public Plane(final double A, final double B, final double C, final double D) {
|
public Plane(final double A, final double B, final double C, final double D) {
|
||||||
super(A, B, C);
|
super(A, B, C);
|
||||||
this.D = D;
|
this.D = D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct a plane through two points and origin.
|
/**
|
||||||
|
* Construct a plane through two points and origin.
|
||||||
|
*
|
||||||
* @param A is the first point (origin based).
|
* @param A is the first point (origin based).
|
||||||
* @param B is the second point (origin based).
|
* @param B is the second point (origin based).
|
||||||
*/
|
*/
|
||||||
@ -43,7 +46,9 @@ public class Plane extends Vector
|
|||||||
D = 0.0;
|
D = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct a horizontal plane at a specified Z.
|
/**
|
||||||
|
* Construct a horizontal plane at a specified Z.
|
||||||
|
*
|
||||||
* @param height is the specified Z coordinate.
|
* @param height is the specified Z coordinate.
|
||||||
*/
|
*/
|
||||||
public Plane(final double height) {
|
public Plane(final double height) {
|
||||||
@ -51,8 +56,10 @@ public class Plane extends Vector
|
|||||||
D = -height;
|
D = -height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct a vertical plane through a specified
|
/**
|
||||||
|
* Construct a vertical plane through a specified
|
||||||
* x, y and origin.
|
* x, y and origin.
|
||||||
|
*
|
||||||
* @param x is the specified x value.
|
* @param x is the specified x value.
|
||||||
* @param y is the specified y value.
|
* @param y is the specified y value.
|
||||||
*/
|
*/
|
||||||
@ -61,8 +68,10 @@ public class Plane extends Vector
|
|||||||
D = 0.0;
|
D = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct a plane with a specific vector, and D offset
|
/**
|
||||||
|
* Construct a plane with a specific vector, and D offset
|
||||||
* from origin.
|
* from origin.
|
||||||
|
*
|
||||||
* @param D is the D offset from the origin.
|
* @param D is the D offset from the origin.
|
||||||
*/
|
*/
|
||||||
public Plane(final Vector v, final double D) {
|
public Plane(final Vector v, final double D) {
|
||||||
@ -70,8 +79,10 @@ public class Plane extends Vector
|
|||||||
this.D = D;
|
this.D = D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Evaluate the plane equation for a given point, as represented
|
/**
|
||||||
|
* Evaluate the plane equation for a given point, as represented
|
||||||
* by a vector.
|
* by a vector.
|
||||||
|
*
|
||||||
* @param v is the vector.
|
* @param v is the vector.
|
||||||
* @return the result of the evaluation.
|
* @return the result of the evaluation.
|
||||||
*/
|
*/
|
||||||
@ -79,8 +90,10 @@ public class Plane extends Vector
|
|||||||
return dotProduct(v) + D;
|
return dotProduct(v) + D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Evaluate the plane equation for a given point, as represented
|
/**
|
||||||
|
* Evaluate the plane equation for a given point, as represented
|
||||||
* by a vector.
|
* by a vector.
|
||||||
|
*
|
||||||
* @param x,y,z is the vector.
|
* @param x,y,z is the vector.
|
||||||
* @return the result of the evaluation.
|
* @return the result of the evaluation.
|
||||||
*/
|
*/
|
||||||
@ -88,8 +101,10 @@ public class Plane extends Vector
|
|||||||
return dotProduct(x, y, z) + D;
|
return dotProduct(x, y, z) + D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Evaluate the plane equation for a given point, as represented
|
/**
|
||||||
|
* Evaluate the plane equation for a given point, as represented
|
||||||
* by a vector.
|
* by a vector.
|
||||||
|
*
|
||||||
* @param v is the vector.
|
* @param v is the vector.
|
||||||
* @return true if the result is on the plane.
|
* @return true if the result is on the plane.
|
||||||
*/
|
*/
|
||||||
@ -97,8 +112,10 @@ public class Plane extends Vector
|
|||||||
return Math.abs(evaluate(v)) < MINIMUM_RESOLUTION;
|
return Math.abs(evaluate(v)) < MINIMUM_RESOLUTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Evaluate the plane equation for a given point, as represented
|
/**
|
||||||
|
* Evaluate the plane equation for a given point, as represented
|
||||||
* by a vector.
|
* by a vector.
|
||||||
|
*
|
||||||
* @param x,y,z is the vector.
|
* @param x,y,z is the vector.
|
||||||
* @return true if the result is on the plane.
|
* @return true if the result is on the plane.
|
||||||
*/
|
*/
|
||||||
@ -106,7 +123,9 @@ public class Plane extends Vector
|
|||||||
return Math.abs(evaluate(x, y, z)) < MINIMUM_RESOLUTION;
|
return Math.abs(evaluate(x, y, z)) < MINIMUM_RESOLUTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Build a normalized plane, so that the vector is normalized.
|
/**
|
||||||
|
* Build a normalized plane, so that the vector is normalized.
|
||||||
|
*
|
||||||
* @return the normalized plane object, or null if the plane is indeterminate.
|
* @return the normalized plane object, or null if the plane is indeterminate.
|
||||||
*/
|
*/
|
||||||
public Plane normalize() {
|
public Plane normalize() {
|
||||||
@ -116,7 +135,8 @@ public class Plane extends Vector
|
|||||||
return new Plane(normVect, this.D);
|
return new Plane(normVect, this.D);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Find points on the boundary of the intersection of a plane and the unit sphere,
|
/**
|
||||||
|
* Find points on the boundary of the intersection of a plane and the unit sphere,
|
||||||
* given a starting point, and ending point, and a list of proportions of the arc (e.g. 0.25, 0.5, 0.75).
|
* given a starting point, and ending point, and a list of proportions of the arc (e.g. 0.25, 0.5, 0.75).
|
||||||
* The angle between the starting point and ending point is assumed to be less than pi.
|
* The angle between the starting point and ending point is assumed to be less than pi.
|
||||||
*/
|
*/
|
||||||
@ -254,14 +274,16 @@ public class Plane extends Vector
|
|||||||
return returnValues;
|
return returnValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Modify a point to produce a vector in translated/rotated space.
|
/**
|
||||||
|
* Modify a point to produce a vector in translated/rotated space.
|
||||||
*/
|
*/
|
||||||
protected static Vector modify(final GeoPoint start, final double transX, final double transY, final double transZ,
|
protected static Vector modify(final GeoPoint start, final double transX, final double transY, final double transZ,
|
||||||
final double sinRA, final double cosRA, final double sinHA, final double cosHA) {
|
final double sinRA, final double cosRA, final double sinHA, final double cosHA) {
|
||||||
return start.translate(transX, transY, transZ).rotateXY(sinRA, cosRA).rotateXZ(sinHA, cosHA);
|
return start.translate(transX, transY, transZ).rotateXY(sinRA, cosRA).rotateXZ(sinHA, cosHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reverse modify a point to produce a GeoPoint in normal space.
|
/**
|
||||||
|
* Reverse modify a point to produce a GeoPoint in normal space.
|
||||||
*/
|
*/
|
||||||
protected static GeoPoint reverseModify(final Vector point, final double transX, final double transY, final double transZ,
|
protected static GeoPoint reverseModify(final Vector point, final double transX, final double transY, final double transZ,
|
||||||
final double sinRA, final double cosRA, final double sinHA, final double cosHA) {
|
final double sinRA, final double cosRA, final double sinHA, final double cosHA) {
|
||||||
@ -269,7 +291,9 @@ public class Plane extends Vector
|
|||||||
return new GeoPoint(result.x, result.y, result.z);
|
return new GeoPoint(result.x, result.y, result.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Find the intersection points between two planes, given a set of bounds.
|
/**
|
||||||
|
* Find the intersection points between two planes, given a set of bounds.
|
||||||
|
*
|
||||||
* @param q is the plane to intersect with.
|
* @param q is the plane to intersect with.
|
||||||
* @param bounds is the set of bounds.
|
* @param bounds is the set of bounds.
|
||||||
* @param moreBounds is another set of bounds.
|
* @param moreBounds is another set of bounds.
|
||||||
@ -386,10 +410,12 @@ public class Plane extends Vector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Accumulate bounds information for this plane, intersected with another plane
|
/**
|
||||||
|
* Accumulate bounds information for this plane, intersected with another plane
|
||||||
* and with the unit sphere.
|
* and with the unit sphere.
|
||||||
* Updates both latitude and longitude information, using max/min points found
|
* Updates both latitude and longitude information, using max/min points found
|
||||||
* within the specified bounds.
|
* within the specified bounds.
|
||||||
|
*
|
||||||
* @param q is the plane to intersect with.
|
* @param q is the plane to intersect with.
|
||||||
* @param boundsInfo is the info to update with additional bounding information.
|
* @param boundsInfo is the info to update with additional bounding information.
|
||||||
* @param bounds are the surfaces delineating what's inside the shape.
|
* @param bounds are the surfaces delineating what's inside the shape.
|
||||||
@ -401,9 +427,11 @@ public class Plane extends Vector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Accumulate bounds information for this plane, intersected with the unit sphere.
|
/**
|
||||||
|
* Accumulate bounds information for this plane, intersected with the unit sphere.
|
||||||
* Updates both latitude and longitude information, using max/min points found
|
* Updates both latitude and longitude information, using max/min points found
|
||||||
* within the specified bounds.
|
* within the specified bounds.
|
||||||
|
*
|
||||||
* @param boundsInfo is the info to update with additional bounding information.
|
* @param boundsInfo is the info to update with additional bounding information.
|
||||||
* @param bounds are the surfaces delineating what's inside the shape.
|
* @param bounds are the surfaces delineating what's inside the shape.
|
||||||
*/
|
*/
|
||||||
@ -937,8 +965,10 @@ public class Plane extends Vector
|
|||||||
boundsInfo.addPoint(x, y, z);
|
boundsInfo.addPoint(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Determine whether the plane intersects another plane within the
|
/**
|
||||||
|
* Determine whether the plane intersects another plane within the
|
||||||
* bounds provided.
|
* bounds provided.
|
||||||
|
*
|
||||||
* @param q is the other plane.
|
* @param q is the other plane.
|
||||||
* @param notablePoints are points to look at to disambiguate cases when the two planes are identical.
|
* @param notablePoints are points to look at to disambiguate cases when the two planes are identical.
|
||||||
* @param moreNotablePoints are additional points to look at to disambiguate cases when the two planes are identical.
|
* @param moreNotablePoints are additional points to look at to disambiguate cases when the two planes are identical.
|
||||||
@ -974,7 +1004,8 @@ public class Plane extends Vector
|
|||||||
return findIntersections(q, bounds, moreBounds).length > 0;
|
return findIntersections(q, bounds, moreBounds).length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true if this plane and the other plane are identical within the margin of error.
|
/**
|
||||||
|
* Returns true if this plane and the other plane are identical within the margin of error.
|
||||||
*/
|
*/
|
||||||
protected boolean isNumericallyIdentical(final Plane p) {
|
protected boolean isNumericallyIdentical(final Plane p) {
|
||||||
// We can get the correlation by just doing a parallel plane check. If that passes, then compute a point on the plane
|
// We can get the correlation by just doing a parallel plane check. If that passes, then compute a point on the plane
|
||||||
@ -1015,7 +1046,8 @@ public class Plane extends Vector
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Find a sample point on the intersection between two planes and the unit sphere.
|
/**
|
||||||
|
* Find a sample point on the intersection between two planes and the unit sphere.
|
||||||
*/
|
*/
|
||||||
public GeoPoint getSampleIntersectionPoint(final Plane q) {
|
public GeoPoint getSampleIntersectionPoint(final Plane q) {
|
||||||
final GeoPoint[] intersections = findIntersections(q, NO_BOUNDS, NO_BOUNDS);
|
final GeoPoint[] intersections = findIntersections(q, NO_BOUNDS, NO_BOUNDS);
|
||||||
|
@ -17,14 +17,16 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Combination of a plane, and a sign value indicating what evaluation values are on the correct
|
/**
|
||||||
|
* Combination of a plane, and a sign value indicating what evaluation values are on the correct
|
||||||
* side of the plane.
|
* side of the plane.
|
||||||
*/
|
*/
|
||||||
public class SidedPlane extends Plane implements Membership
|
public class SidedPlane extends Plane implements Membership {
|
||||||
{
|
|
||||||
public final double sigNum;
|
public final double sigNum;
|
||||||
|
|
||||||
/** Construct a SidedPlane identical to an existing one, but reversed.
|
/**
|
||||||
|
* Construct a SidedPlane identical to an existing one, but reversed.
|
||||||
|
*
|
||||||
* @param sidedPlane is the existing plane.
|
* @param sidedPlane is the existing plane.
|
||||||
*/
|
*/
|
||||||
public SidedPlane(SidedPlane sidedPlane) {
|
public SidedPlane(SidedPlane sidedPlane) {
|
||||||
@ -32,8 +34,10 @@ public class SidedPlane extends Plane implements Membership
|
|||||||
this.sigNum = -sidedPlane.sigNum;
|
this.sigNum = -sidedPlane.sigNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct a sided plane from a pair of vectors describing points, and including
|
/**
|
||||||
|
* Construct a sided plane from a pair of vectors describing points, and including
|
||||||
* origin, plus a point p which describes the side.
|
* origin, plus a point p which describes the side.
|
||||||
|
*
|
||||||
* @param p point to evaluate
|
* @param p point to evaluate
|
||||||
* @param A is the first in-plane point
|
* @param A is the first in-plane point
|
||||||
* @param B is the second in-plane point
|
* @param B is the second in-plane point
|
||||||
@ -43,7 +47,9 @@ public class SidedPlane extends Plane implements Membership
|
|||||||
sigNum = Math.signum(evaluate(p));
|
sigNum = Math.signum(evaluate(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct a sided plane from a point and a Z coordinate.
|
/**
|
||||||
|
* Construct a sided plane from a point and a Z coordinate.
|
||||||
|
*
|
||||||
* @param p point to evaluate.
|
* @param p point to evaluate.
|
||||||
* @param height is the Z coordinate of the plane.
|
* @param height is the Z coordinate of the plane.
|
||||||
*/
|
*/
|
||||||
@ -52,7 +58,9 @@ public class SidedPlane extends Plane implements Membership
|
|||||||
sigNum = Math.signum(evaluate(p));
|
sigNum = Math.signum(evaluate(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct a sided vertical plane from a point and specified x and y coordinates.
|
/**
|
||||||
|
* Construct a sided vertical plane from a point and specified x and y coordinates.
|
||||||
|
*
|
||||||
* @param p point to evaluate.
|
* @param p point to evaluate.
|
||||||
* @param x is the specified x.
|
* @param x is the specified x.
|
||||||
* @param y is the specified y.
|
* @param y is the specified y.
|
||||||
@ -62,7 +70,9 @@ public class SidedPlane extends Plane implements Membership
|
|||||||
sigNum = Math.signum(evaluate(p));
|
sigNum = Math.signum(evaluate(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct a sided plane with a normal vector and offset.
|
/**
|
||||||
|
* Construct a sided plane with a normal vector and offset.
|
||||||
|
*
|
||||||
* @param p point to evaluate.
|
* @param p point to evaluate.
|
||||||
* @param v is the normal vector.
|
* @param v is the normal vector.
|
||||||
* @param D is the origin offset for the plan.
|
* @param D is the origin offset for the plan.
|
||||||
@ -72,13 +82,14 @@ public class SidedPlane extends Plane implements Membership
|
|||||||
sigNum = Math.signum(evaluate(p));
|
sigNum = Math.signum(evaluate(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if a point is within this shape.
|
/**
|
||||||
|
* Check if a point is within this shape.
|
||||||
|
*
|
||||||
* @param point is the point to check.
|
* @param point is the point to check.
|
||||||
* @return true if the point is within this shape
|
* @return true if the point is within this shape
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(Vector point)
|
public boolean isWithin(Vector point) {
|
||||||
{
|
|
||||||
double evalResult = evaluate(point);
|
double evalResult = evaluate(point);
|
||||||
if (Math.abs(evalResult) < MINIMUM_RESOLUTION)
|
if (Math.abs(evalResult) < MINIMUM_RESOLUTION)
|
||||||
return true;
|
return true;
|
||||||
@ -86,15 +97,16 @@ public class SidedPlane extends Plane implements Membership
|
|||||||
return sigNum == this.sigNum;
|
return sigNum == this.sigNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if a point is within this shape.
|
/**
|
||||||
|
* Check if a point is within this shape.
|
||||||
|
*
|
||||||
* @param x is x coordinate of point to check.
|
* @param x is x coordinate of point to check.
|
||||||
* @param y is y coordinate of point to check.
|
* @param y is y coordinate of point to check.
|
||||||
* @param z is z coordinate of point to check.
|
* @param z is z coordinate of point to check.
|
||||||
* @return true if the point is within this shape
|
* @return true if the point is within this shape
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isWithin(double x, double y, double z)
|
public boolean isWithin(double x, double y, double z) {
|
||||||
{
|
|
||||||
double evalResult = evaluate(x, y, z);
|
double evalResult = evaluate(x, y, z);
|
||||||
if (Math.abs(evalResult) < MINIMUM_RESOLUTION)
|
if (Math.abs(evalResult) < MINIMUM_RESOLUTION)
|
||||||
return true;
|
return true;
|
||||||
|
@ -17,15 +17,15 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Static methods globally useful for 3d geometric work.
|
/**
|
||||||
|
* Static methods globally useful for 3d geometric work.
|
||||||
*/
|
*/
|
||||||
public class Tools
|
public class Tools {
|
||||||
{
|
private Tools() {
|
||||||
private Tools()
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Java acos yields a NAN if you take an arc-cos of an
|
/**
|
||||||
|
* Java acos yields a NAN if you take an arc-cos of an
|
||||||
* angle that's just a tiny bit greater than 1.0, so
|
* angle that's just a tiny bit greater than 1.0, so
|
||||||
* here's a more resilient version.
|
* here's a more resilient version.
|
||||||
*/
|
*/
|
||||||
|
@ -17,14 +17,18 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** A 3d vector in space, not necessarily
|
/**
|
||||||
* going through the origin. */
|
* A 3d vector in space, not necessarily
|
||||||
public class Vector
|
* going through the origin.
|
||||||
{
|
*/
|
||||||
/** Values that are all considered to be essentially zero have a magnitude
|
public class Vector {
|
||||||
* less than this. */
|
/**
|
||||||
|
* Values that are all considered to be essentially zero have a magnitude
|
||||||
|
* less than this.
|
||||||
|
*/
|
||||||
public static final double MINIMUM_RESOLUTION = 1e-12;
|
public static final double MINIMUM_RESOLUTION = 1e-12;
|
||||||
/** For squared quantities, the bound is squared too.
|
/**
|
||||||
|
* For squared quantities, the bound is squared too.
|
||||||
*/
|
*/
|
||||||
public static final double MINIMUM_RESOLUTION_SQUARED = MINIMUM_RESOLUTION * MINIMUM_RESOLUTION;
|
public static final double MINIMUM_RESOLUTION_SQUARED = MINIMUM_RESOLUTION * MINIMUM_RESOLUTION;
|
||||||
|
|
||||||
@ -32,18 +36,20 @@ public class Vector
|
|||||||
public final double y;
|
public final double y;
|
||||||
public final double z;
|
public final double z;
|
||||||
|
|
||||||
/** Construct from (U.S.) x,y,z coordinates.
|
/**
|
||||||
|
* Construct from (U.S.) x,y,z coordinates.
|
||||||
*/
|
*/
|
||||||
public Vector(double x, double y, double z)
|
public Vector(double x, double y, double z) {
|
||||||
{
|
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct a vector that is perpendicular to
|
/**
|
||||||
|
* Construct a vector that is perpendicular to
|
||||||
* two other (non-zero) vectors. If the vectors are parallel,
|
* two other (non-zero) vectors. If the vectors are parallel,
|
||||||
* the result vector will have magnitude 0.
|
* the result vector will have magnitude 0.
|
||||||
|
*
|
||||||
* @param A is the first vector
|
* @param A is the first vector
|
||||||
* @param B is the second
|
* @param B is the second
|
||||||
*/
|
*/
|
||||||
@ -57,7 +63,9 @@ public class Vector
|
|||||||
A.x * B.y - A.y * B.x);
|
A.x * B.y - A.y * B.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute a normalized unit vector based on the current vector.
|
/**
|
||||||
|
* Compute a normalized unit vector based on the current vector.
|
||||||
|
*
|
||||||
* @return the normalized vector, or null if the current vector has
|
* @return the normalized vector, or null if the current vector has
|
||||||
* a magnitude of zero.
|
* a magnitude of zero.
|
||||||
*/
|
*/
|
||||||
@ -70,7 +78,9 @@ public class Vector
|
|||||||
return new Vector(x * normFactor, y * normFactor, z * normFactor);
|
return new Vector(x * normFactor, y * normFactor, z * normFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Do a dot product.
|
/**
|
||||||
|
* Do a dot product.
|
||||||
|
*
|
||||||
* @param v is the vector to multiply.
|
* @param v is the vector to multiply.
|
||||||
* @return the result.
|
* @return the result.
|
||||||
*/
|
*/
|
||||||
@ -78,7 +88,9 @@ public class Vector
|
|||||||
return this.x * v.x + this.y * v.y + this.z * v.z;
|
return this.x * v.x + this.y * v.y + this.z * v.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Do a dot product.
|
/**
|
||||||
|
* Do a dot product.
|
||||||
|
*
|
||||||
* @param x is the x value of the vector to multiply.
|
* @param x is the x value of the vector to multiply.
|
||||||
* @param y is the y value of the vector to multiply.
|
* @param y is the y value of the vector to multiply.
|
||||||
* @param z is the z value of the vector to multiply.
|
* @param z is the z value of the vector to multiply.
|
||||||
@ -88,8 +100,10 @@ public class Vector
|
|||||||
return this.x * x + this.y * y + this.z * z;
|
return this.x * x + this.y * y + this.z * z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Determine if this vector, taken from the origin,
|
/**
|
||||||
|
* Determine if this vector, taken from the origin,
|
||||||
* describes a point within a set of planes.
|
* describes a point within a set of planes.
|
||||||
|
*
|
||||||
* @param bounds is the first part of the set of planes.
|
* @param bounds is the first part of the set of planes.
|
||||||
* @param moreBounds is the second part of the set of planes.
|
* @param moreBounds is the second part of the set of planes.
|
||||||
* @return true if the point is within the bounds.
|
* @return true if the point is within the bounds.
|
||||||
@ -107,51 +121,60 @@ public class Vector
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Translate vector.
|
/**
|
||||||
|
* Translate vector.
|
||||||
*/
|
*/
|
||||||
public Vector translate(final double xOffset, final double yOffset, final double zOffset) {
|
public Vector translate(final double xOffset, final double yOffset, final double zOffset) {
|
||||||
return new Vector(x - xOffset, y - yOffset, z - zOffset);
|
return new Vector(x - xOffset, y - yOffset, z - zOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Rotate vector counter-clockwise in x-y by an angle.
|
/**
|
||||||
|
* Rotate vector counter-clockwise in x-y by an angle.
|
||||||
*/
|
*/
|
||||||
public Vector rotateXY(final double angle) {
|
public Vector rotateXY(final double angle) {
|
||||||
return rotateXY(Math.sin(angle), Math.cos(angle));
|
return rotateXY(Math.sin(angle), Math.cos(angle));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Rotate vector counter-clockwise in x-y by an angle, expressed as sin and cos.
|
/**
|
||||||
|
* Rotate vector counter-clockwise in x-y by an angle, expressed as sin and cos.
|
||||||
*/
|
*/
|
||||||
public Vector rotateXY(final double sinAngle, final double cosAngle) {
|
public Vector rotateXY(final double sinAngle, final double cosAngle) {
|
||||||
return new Vector(x * cosAngle - y * sinAngle, x * sinAngle + y * cosAngle, z);
|
return new Vector(x * cosAngle - y * sinAngle, x * sinAngle + y * cosAngle, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Rotate vector counter-clockwise in x-z by an angle.
|
/**
|
||||||
|
* Rotate vector counter-clockwise in x-z by an angle.
|
||||||
*/
|
*/
|
||||||
public Vector rotateXZ(final double angle) {
|
public Vector rotateXZ(final double angle) {
|
||||||
return rotateXZ(Math.sin(angle), Math.cos(angle));
|
return rotateXZ(Math.sin(angle), Math.cos(angle));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Rotate vector counter-clockwise in x-z by an angle, expressed as sin and cos.
|
/**
|
||||||
|
* Rotate vector counter-clockwise in x-z by an angle, expressed as sin and cos.
|
||||||
*/
|
*/
|
||||||
public Vector rotateXZ(final double sinAngle, final double cosAngle) {
|
public Vector rotateXZ(final double sinAngle, final double cosAngle) {
|
||||||
return new Vector(x * cosAngle - z * sinAngle, y, x * sinAngle + z * cosAngle);
|
return new Vector(x * cosAngle - z * sinAngle, y, x * sinAngle + z * cosAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Rotate vector counter-clockwise in z-y by an angle.
|
/**
|
||||||
|
* Rotate vector counter-clockwise in z-y by an angle.
|
||||||
*/
|
*/
|
||||||
public Vector rotateZY(final double angle) {
|
public Vector rotateZY(final double angle) {
|
||||||
return rotateZY(Math.sin(angle), Math.cos(angle));
|
return rotateZY(Math.sin(angle), Math.cos(angle));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Rotate vector counter-clockwise in z-y by an angle, expressed as sin and cos.
|
/**
|
||||||
|
* Rotate vector counter-clockwise in z-y by an angle, expressed as sin and cos.
|
||||||
*/
|
*/
|
||||||
public Vector rotateZY(final double sinAngle, final double cosAngle) {
|
public Vector rotateZY(final double sinAngle, final double cosAngle) {
|
||||||
return new Vector(x, z * sinAngle + y * cosAngle, z * cosAngle - y * sinAngle);
|
return new Vector(x, z * sinAngle + y * cosAngle, z * cosAngle - y * sinAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute the square of a straight-line distance to a point described by the
|
/**
|
||||||
|
* Compute the square of a straight-line distance to a point described by the
|
||||||
* vector taken from the origin.
|
* vector taken from the origin.
|
||||||
* Monotonically increasing for arc distances up to PI.
|
* Monotonically increasing for arc distances up to PI.
|
||||||
|
*
|
||||||
* @param v is the vector to compute a distance to.
|
* @param v is the vector to compute a distance to.
|
||||||
* @return the square of the linear distance.
|
* @return the square of the linear distance.
|
||||||
*/
|
*/
|
||||||
@ -162,9 +185,11 @@ public class Vector
|
|||||||
return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
|
return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute the square of a straight-line distance to a point described by the
|
/**
|
||||||
|
* Compute the square of a straight-line distance to a point described by the
|
||||||
* vector taken from the origin.
|
* vector taken from the origin.
|
||||||
* Monotonically increasing for arc distances up to PI.
|
* Monotonically increasing for arc distances up to PI.
|
||||||
|
*
|
||||||
* @param x is the x part of the vector to compute a distance to.
|
* @param x is the x part of the vector to compute a distance to.
|
||||||
* @param y is the y part of the vector to compute a distance to.
|
* @param y is the y part of the vector to compute a distance to.
|
||||||
* @param z is the z part of the vector to compute a distance to.
|
* @param z is the z part of the vector to compute a distance to.
|
||||||
@ -177,9 +202,11 @@ public class Vector
|
|||||||
return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
|
return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute the straight-line distance to a point described by the
|
/**
|
||||||
|
* Compute the straight-line distance to a point described by the
|
||||||
* vector taken from the origin.
|
* vector taken from the origin.
|
||||||
* Monotonically increasing for arc distances up to PI.
|
* Monotonically increasing for arc distances up to PI.
|
||||||
|
*
|
||||||
* @param v is the vector to compute a distance to.
|
* @param v is the vector to compute a distance to.
|
||||||
* @return the linear distance.
|
* @return the linear distance.
|
||||||
*/
|
*/
|
||||||
@ -187,9 +214,11 @@ public class Vector
|
|||||||
return Math.sqrt(linearDistanceSquared(v));
|
return Math.sqrt(linearDistanceSquared(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute the straight-line distance to a point described by the
|
/**
|
||||||
|
* Compute the straight-line distance to a point described by the
|
||||||
* vector taken from the origin.
|
* vector taken from the origin.
|
||||||
* Monotonically increasing for arc distances up to PI.
|
* Monotonically increasing for arc distances up to PI.
|
||||||
|
*
|
||||||
* @param x is the x part of the vector to compute a distance to.
|
* @param x is the x part of the vector to compute a distance to.
|
||||||
* @param y is the y part of the vector to compute a distance to.
|
* @param y is the y part of the vector to compute a distance to.
|
||||||
* @param z is the z part of the vector to compute a distance to.
|
* @param z is the z part of the vector to compute a distance to.
|
||||||
@ -199,9 +228,11 @@ public class Vector
|
|||||||
return Math.sqrt(linearDistanceSquared(x, y, z));
|
return Math.sqrt(linearDistanceSquared(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute the square of the normal distance to a vector described by a
|
/**
|
||||||
|
* Compute the square of the normal distance to a vector described by a
|
||||||
* vector taken from the origin.
|
* vector taken from the origin.
|
||||||
* Monotonically increasing for arc distances up to PI/2.
|
* Monotonically increasing for arc distances up to PI/2.
|
||||||
|
*
|
||||||
* @param v is the vector to compute a distance to.
|
* @param v is the vector to compute a distance to.
|
||||||
* @return the square of the normal distance.
|
* @return the square of the normal distance.
|
||||||
*/
|
*/
|
||||||
@ -213,9 +244,11 @@ public class Vector
|
|||||||
return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
|
return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute the square of the normal distance to a vector described by a
|
/**
|
||||||
|
* Compute the square of the normal distance to a vector described by a
|
||||||
* vector taken from the origin.
|
* vector taken from the origin.
|
||||||
* Monotonically increasing for arc distances up to PI/2.
|
* Monotonically increasing for arc distances up to PI/2.
|
||||||
|
*
|
||||||
* @param x is the x part of the vector to compute a distance to.
|
* @param x is the x part of the vector to compute a distance to.
|
||||||
* @param y is the y part of the vector to compute a distance to.
|
* @param y is the y part of the vector to compute a distance to.
|
||||||
* @param z is the z part of the vector to compute a distance to.
|
* @param z is the z part of the vector to compute a distance to.
|
||||||
@ -229,9 +262,11 @@ public class Vector
|
|||||||
return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
|
return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute the normal (perpendicular) distance to a vector described by a
|
/**
|
||||||
|
* Compute the normal (perpendicular) distance to a vector described by a
|
||||||
* vector taken from the origin.
|
* vector taken from the origin.
|
||||||
* Monotonically increasing for arc distances up to PI/2.
|
* Monotonically increasing for arc distances up to PI/2.
|
||||||
|
*
|
||||||
* @param v is the vector to compute a distance to.
|
* @param v is the vector to compute a distance to.
|
||||||
* @return the normal distance.
|
* @return the normal distance.
|
||||||
*/
|
*/
|
||||||
@ -239,9 +274,11 @@ public class Vector
|
|||||||
return Math.sqrt(normalDistanceSquared(v));
|
return Math.sqrt(normalDistanceSquared(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute the normal (perpendicular) distance to a vector described by a
|
/**
|
||||||
|
* Compute the normal (perpendicular) distance to a vector described by a
|
||||||
* vector taken from the origin.
|
* vector taken from the origin.
|
||||||
* Monotonically increasing for arc distances up to PI/2.
|
* Monotonically increasing for arc distances up to PI/2.
|
||||||
|
*
|
||||||
* @param x is the x part of the vector to compute a distance to.
|
* @param x is the x part of the vector to compute a distance to.
|
||||||
* @param y is the y part of the vector to compute a distance to.
|
* @param y is the y part of the vector to compute a distance to.
|
||||||
* @param z is the z part of the vector to compute a distance to.
|
* @param z is the z part of the vector to compute a distance to.
|
||||||
@ -251,7 +288,9 @@ public class Vector
|
|||||||
return Math.sqrt(normalDistanceSquared(x, y, z));
|
return Math.sqrt(normalDistanceSquared(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute the magnitude of this vector.
|
/**
|
||||||
|
* Compute the magnitude of this vector.
|
||||||
|
*
|
||||||
* @return the magnitude.
|
* @return the magnitude.
|
||||||
*/
|
*/
|
||||||
public double magnitude() {
|
public double magnitude() {
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
/** Shapes implemented using 3D planar geometry. */
|
/**
|
||||||
|
* Shapes implemented using 3D planar geometry.
|
||||||
|
*/
|
||||||
package org.apache.lucene.spatial.spatial4j.geo3d;
|
package org.apache.lucene.spatial.spatial4j.geo3d;
|
@ -78,24 +78,8 @@ public class Geo3dRptTest extends RandomSpatialOpStrategyTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure() throws IOException {
|
public void testFailure1() throws IOException {
|
||||||
setupStrategy();
|
setupStrategy();
|
||||||
// [junit4] > Throwable #1: java.lang.AssertionError: [Intersects] qIdx:25 Shouldn't match I#1:Rect(minX=-49.0,maxX=-45.0,minY=73.0,maxY=86.0)
|
|
||||||
// Q:Geo3dShape{GeoCompositeMembershipShape: {[GeoCompositeMembershipShape: {[GeoConvexPolygon: {[
|
|
||||||
// [X=-0.8606462131055999, Y=0.4385211485883089, Z=-0.25881904510252074],
|
|
||||||
// [X=-0.4668467715008339, Y=0.28050984011500923, Z=-0.838670567945424],
|
|
||||||
// [X=-0.9702957262759965, Y=1.1882695554102554E-16, Z=0.24192189559966773]]}]},
|
|
||||||
// GeoConvexPolygon: {[[X=0.8473975608908426, Y=-0.43177062311338915, Z=0.3090169943749474],
|
|
||||||
//[X=-0.4668467715008339, Y=0.28050984011500923, Z=-0.838670567945424],
|
|
||||||
// [X=-0.8606462131055999, Y=0.4385211485883089, Z=-0.25881904510252074]]}]}}
|
|
||||||
//
|
|
||||||
// Points in order (I think):
|
|
||||||
//
|
|
||||||
// [X=0.8473975608908426, Y=-0.43177062311338915, Z=0.3090169943749474],
|
|
||||||
//[X=-0.4668467715008339, Y=0.28050984011500923, Z=-0.838670567945424],
|
|
||||||
// [X=-0.9702957262759965, Y=1.1882695554102554E-16, Z=0.24192189559966773],
|
|
||||||
// [X=-0.8606462131055999, Y=0.4385211485883089, Z=-0.25881904510252074],
|
|
||||||
// Index: 0
|
|
||||||
final List<GeoPoint> points = new ArrayList<GeoPoint>();
|
final List<GeoPoint> points = new ArrayList<GeoPoint>();
|
||||||
points.add(new GeoPoint(18 * DEGREES_TO_RADIANS, -27 * DEGREES_TO_RADIANS));
|
points.add(new GeoPoint(18 * DEGREES_TO_RADIANS, -27 * DEGREES_TO_RADIANS));
|
||||||
points.add(new GeoPoint(-57 * DEGREES_TO_RADIANS, 146 * DEGREES_TO_RADIANS));
|
points.add(new GeoPoint(-57 * DEGREES_TO_RADIANS, 146 * DEGREES_TO_RADIANS));
|
||||||
@ -108,8 +92,7 @@ public class Geo3dRptTest extends RandomSpatialOpStrategyTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Repeat(iterations = 2000)
|
@Repeat(iterations = 10)
|
||||||
//@Seed("B808B88D6F8E285C")
|
|
||||||
public void testOperations() throws IOException {
|
public void testOperations() throws IOException {
|
||||||
setupStrategy();
|
setupStrategy();
|
||||||
|
|
||||||
|
@ -54,26 +54,7 @@ public class Geo3dShapeRectRelationTest extends RandomizedShapeTest {
|
|||||||
protected final static double RADIANS_PER_DEGREE = Math.PI/180.0;
|
protected final static double RADIANS_PER_DEGREE = Math.PI/180.0;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure() {
|
public void testFailure1() {
|
||||||
/*
|
|
||||||
[junit4] 1> S-R Rel: {}, Shape {}, Rectangle {} [WITHIN, Geo3dShape{GeoCompositeMembershipShape: {[
|
|
||||||
GeoConvexPolygon: {points=[
|
|
||||||
[X=0.35168818443386646, Y=-0.19637966197066342, Z=0.9152870857244183],
|
|
||||||
[X=0.5003343189532654, Y=0.522128543226148, Z=0.6906861469771293],
|
|
||||||
[X=0.8344549994139991, Y=0.216175219373972, Z=0.5069054433339593]]
|
|
||||||
edges={
|
|
||||||
[A=-0.6135342247741855, B=0.21504338363863665, C=0.28188192383666794, D=0.0, side=-1.0] internal? false;
|
|
||||||
[A=0.11536057134002048, B=0.32272431860685813, C=-0.3275328920717585, D=0.0, side=-1.0] internal? false;
|
|
||||||
[A=0.29740830615965186, B=-0.5854932295360462, C=-0.2398962611358763, D=0.0, side=-1.0] internal? false; }}]}},
|
|
||||||
Rect(minX=-30.0,maxX=62.0,minY=30.0,maxY=88.0)](no slf4j subst; sorry)
|
|
||||||
[junit4] FAILURE 1.85s J2 | Geo3dShapeRectRelationTest.testGeoPolygonRect <<<
|
|
||||||
[junit4] > Throwable #1: java.lang.AssertionError: Rect(minX=-30.0,maxX=62.0,minY=30.0,maxY=88.0) intersect Pt(x=82.75500168892472,y=34.2730264413182)
|
|
||||||
[junit4] > at __randomizedtesting.SeedInfo.seed([3EBD2127AF6641F7:3A64BDAC8843B64]:0)
|
|
||||||
[junit4] > at org.apache.lucene.spatial.spatial4j.RandomizedShapeTest._assertIntersect(RandomizedShapeTest.java:167)
|
|
||||||
[junit4] > at org.apache.lucene.spatial.spatial4j.RandomizedShapeTest.assertRelation(RandomizedShapeTest.java:152)
|
|
||||||
[junit4] > at org.apache.lucene.spatial.spatial4j.RectIntersectionTestHelper.testRelateWithRectangle(RectIntersectionTestHelper.java:105)
|
|
||||||
[junit4] > at org.apache.lucene.spatial.spatial4j.Geo3dShapeRectRelationTest.testGeoPolygonRect(Geo3dShapeRectRelationTest.java:219)
|
|
||||||
*/
|
|
||||||
final GeoBBox rect = GeoBBoxFactory.makeGeoBBox(88 * RADIANS_PER_DEGREE, 30 * RADIANS_PER_DEGREE, -30 * RADIANS_PER_DEGREE, 62 * RADIANS_PER_DEGREE);
|
final GeoBBox rect = GeoBBoxFactory.makeGeoBBox(88 * RADIANS_PER_DEGREE, 30 * RADIANS_PER_DEGREE, -30 * RADIANS_PER_DEGREE, 62 * RADIANS_PER_DEGREE);
|
||||||
final List<GeoPoint> points = new ArrayList<GeoPoint>();
|
final List<GeoPoint> points = new ArrayList<GeoPoint>();
|
||||||
points.add(new GeoPoint(66.2465299717 * RADIANS_PER_DEGREE, -29.1786158537 * RADIANS_PER_DEGREE));
|
points.add(new GeoPoint(66.2465299717 * RADIANS_PER_DEGREE, -29.1786158537 * RADIANS_PER_DEGREE));
|
||||||
@ -83,19 +64,6 @@ public class Geo3dShapeRectRelationTest extends RandomizedShapeTest {
|
|||||||
|
|
||||||
final GeoPoint point = new GeoPoint(34.2730264413182 * RADIANS_PER_DEGREE, 82.75500168892472 * RADIANS_PER_DEGREE);
|
final GeoPoint point = new GeoPoint(34.2730264413182 * RADIANS_PER_DEGREE, 82.75500168892472 * RADIANS_PER_DEGREE);
|
||||||
|
|
||||||
System.err.println("Rectangle = "+rect+"; path = "+path+"; point = "+point);
|
|
||||||
|
|
||||||
/*
|
|
||||||
[junit4] 2> Rectangle = GeoRectangle: {toplat=1.53588974175501(87.99999999999999), bottomlat=0.5235987755982988(29.999999999999996), leftlon=-0.5235987755982988(-29.999999999999996), rightlon=1.0821041362364843(62.0)};
|
|
||||||
path = GeoCompositeMembershipShape: {[GeoConvexPolygon: {points=[
|
|
||||||
[X=0.3516881844340107, Y=-0.1963796619709742, Z=0.9152870857242963],
|
|
||||||
[X=0.500334318953081, Y=0.5221285432268337, Z=0.6906861469767445],
|
|
||||||
[X=0.8344549994140144, Y=0.21617521937373424, Z=0.5069054433340355]]
|
|
||||||
edges={[A=-0.6135342247748885, B=0.21504338363844255, C=0.28188192383710364, D=0.0, side=-1.0] internal? false;
|
|
||||||
[A=0.1153605713406553, B=0.32272431860660283, C=-0.3275328920724975, D=0.0, side=-1.0] internal? false;
|
|
||||||
[A=0.29740830615958036, B=-0.5854932295358584, C=-0.2398962611360862, D=0.0, side=-1.0] internal? false; }}]};
|
|
||||||
point = [X=0.10421465978661167, Y=0.8197657811637465, Z=0.5631370780889439]
|
|
||||||
*/
|
|
||||||
// Apparently the rectangle thinks the polygon is completely within it... "shape inside rectangle"
|
// Apparently the rectangle thinks the polygon is completely within it... "shape inside rectangle"
|
||||||
assertTrue(GeoArea.WITHIN == rect.getRelationship(path));
|
assertTrue(GeoArea.WITHIN == rect.getRelationship(path));
|
||||||
|
|
||||||
@ -135,7 +103,6 @@ public class Geo3dShapeRectRelationTest extends RandomizedShapeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
//@Seed("FAD1BAB12B6DCCFE")
|
|
||||||
public void testGeoCircleRect() {
|
public void testGeoCircleRect() {
|
||||||
new RectIntersectionTestHelper<Geo3dShape>(ctx) {
|
new RectIntersectionTestHelper<Geo3dShape>(ctx) {
|
||||||
|
|
||||||
|
@ -54,8 +54,9 @@ public abstract class RandomizedShapeTest extends RandomizedTest {
|
|||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkShapesImplementEquals( Class[] classes ) {
|
@SuppressWarnings("unchecked")
|
||||||
for( Class clazz : classes ) {
|
public static void checkShapesImplementEquals( Class<?>[] classes ) {
|
||||||
|
for( Class<?> clazz : classes ) {
|
||||||
try {
|
try {
|
||||||
clazz.getDeclaredMethod( "equals", Object.class );
|
clazz.getDeclaredMethod( "equals", Object.class );
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -29,6 +29,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
public class GeoBBoxTest {
|
public class GeoBBoxTest {
|
||||||
|
|
||||||
protected final double DEGREES_TO_RADIANS = Math.PI / 180.0;
|
protected final double DEGREES_TO_RADIANS = Math.PI / 180.0;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBBoxDegenerate() {
|
public void testBBoxDegenerate() {
|
||||||
GeoBBox box;
|
GeoBBox box;
|
||||||
|
@ -17,10 +17,12 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class GeoCircleTest {
|
public class GeoCircleTest {
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,12 +17,15 @@ package org.apache.lucene.spatial.spatial4j.geo3d;
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class GeoPolygonTest {
|
public class GeoPolygonTest {
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,8 @@ import org.junit.Test;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/** Test basic plane functionality.
|
/**
|
||||||
|
* Test basic plane functionality.
|
||||||
*/
|
*/
|
||||||
public class PlaneTest {
|
public class PlaneTest {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user