You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2016/03/09 17:00:32 UTC
[21/50] [abbrv] lucene-solr git commit: LUCENE-7056: Geo3D package
re-org
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f7f81c32/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPath.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPath.java b/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPath.java
deleted file mode 100755
index bc5b9cf..0000000
--- a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPath.java
+++ /dev/null
@@ -1,797 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.geo3d;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * GeoShape representing a path across the surface of the globe,
- * 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
- * angles to the path.
- *
- * @lucene.experimental
- */
-public class GeoPath extends GeoBaseDistanceShape {
- /** The cutoff angle (width) */
- protected final double cutoffAngle;
-
- /** Sine of cutoff angle */
- protected final double sinAngle;
- /** Cosine of cutoff angle */
- protected final double cosAngle;
-
- /** The original list of path points */
- protected final List<GeoPoint> points = new ArrayList<GeoPoint>();
-
- /** A list of SegmentEndpoints */
- protected List<SegmentEndpoint> endPoints;
- /** A list of PathSegments */
- protected List<PathSegment> segments;
-
- /** A point on the edge */
- protected GeoPoint[] edgePoints;
-
- /** Set to true if path has been completely constructed */
- protected boolean isDone = false;
-
- /** Constructor.
- *@param planetModel is the planet model.
- *@param maxCutoffAngle is the width of the path, measured as an angle.
- *@param pathPoints are the points in the path.
- */
- public GeoPath(final PlanetModel planetModel, final double maxCutoffAngle, final GeoPoint[] pathPoints) {
- this(planetModel, maxCutoffAngle);
- Collections.addAll(points, pathPoints);
- done();
- }
-
- /** Piece-wise constructor. Use in conjunction with addPoint() and done().
- *@param planetModel is the planet model.
- *@param maxCutoffAngle is the width of the path, measured as an angle.
- */
- public GeoPath(final PlanetModel planetModel, final double maxCutoffAngle) {
- super(planetModel);
- if (maxCutoffAngle <= 0.0 || maxCutoffAngle > Math.PI * 0.5)
- throw new IllegalArgumentException("Cutoff angle out of bounds");
- this.cutoffAngle = maxCutoffAngle;
- this.cosAngle = Math.cos(maxCutoffAngle);
- this.sinAngle = Math.sin(maxCutoffAngle);
- }
-
- /** Add a point to the path.
- *@param lat is the latitude of the point.
- *@param lon is the longitude of the point.
- */
- public void addPoint(final double lat, final double lon) {
- if (isDone)
- throw new IllegalStateException("Can't call addPoint() if done() already called");
- points.add(new GeoPoint(planetModel, lat, lon));
- }
-
- /** Complete the path.
- */
- public void done() {
- if (isDone)
- throw new IllegalStateException("Can't call done() twice");
- if (points.size() == 0)
- throw new IllegalArgumentException("Path must have at least one point");
- isDone = true;
-
- endPoints = new ArrayList<>(points.size());
- segments = new ArrayList<>(points.size());
- // Compute an offset to use for all segments. This will be based on the minimum magnitude of
- // the entire ellipsoid.
- final double cutoffOffset = this.sinAngle * planetModel.getMinimumMagnitude();
-
- // First, build all segments. We'll then go back and build corresponding segment endpoints.
- GeoPoint lastPoint = null;
- for (final GeoPoint end : points) {
- if (lastPoint != null) {
- final Plane normalizedConnectingPlane = new Plane(lastPoint, end);
- if (normalizedConnectingPlane == null) {
- continue;
- }
- segments.add(new PathSegment(planetModel, lastPoint, end, normalizedConnectingPlane, cutoffOffset));
- }
- lastPoint = end;
- }
-
- if (segments.size() == 0) {
- // Simple circle
- double lat = points.get(0).getLatitude();
- double lon = points.get(0).getLongitude();
- // Compute two points on the circle, with the right angle from the center. We'll use these
- // to obtain the perpendicular plane to the circle.
- double upperLat = lat + cutoffAngle;
- double upperLon = lon;
- if (upperLat > Math.PI * 0.5) {
- upperLon += Math.PI;
- if (upperLon > Math.PI)
- upperLon -= 2.0 * Math.PI;
- upperLat = Math.PI - upperLat;
- }
- double lowerLat = lat - cutoffAngle;
- double lowerLon = lon;
- if (lowerLat < -Math.PI * 0.5) {
- lowerLon += Math.PI;
- if (lowerLon > Math.PI)
- lowerLon -= 2.0 * Math.PI;
- lowerLat = -Math.PI - lowerLat;
- }
- final GeoPoint upperPoint = new GeoPoint(planetModel, upperLat, upperLon);
- final GeoPoint lowerPoint = new GeoPoint(planetModel, lowerLat, lowerLon);
- final GeoPoint point = points.get(0);
-
- // Construct normal plane
- final Plane normalPlane = Plane.constructNormalizedZPlane(upperPoint, lowerPoint, point);
-
- final SegmentEndpoint onlyEndpoint = new SegmentEndpoint(point, normalPlane, upperPoint, lowerPoint);
- endPoints.add(onlyEndpoint);
- this.edgePoints = new GeoPoint[]{onlyEndpoint.circlePlane.getSampleIntersectionPoint(planetModel, normalPlane)};
- return;
- }
-
- // Create segment endpoints. Use an appropriate constructor for the start and end of the path.
- for (int i = 0; i < segments.size(); i++) {
- final PathSegment currentSegment = segments.get(i);
-
- if (i == 0) {
- // Starting endpoint
- final SegmentEndpoint startEndpoint = new SegmentEndpoint(currentSegment.start,
- currentSegment.startCutoffPlane, currentSegment.ULHC, currentSegment.LLHC);
- endPoints.add(startEndpoint);
- this.edgePoints = new GeoPoint[]{currentSegment.ULHC};
- continue;
- }
-
- // General intersection case
- final PathSegment prevSegment = segments.get(i-1);
- // We construct four separate planes, and evaluate which one includes all interior points with least overlap
- final SidedPlane candidate1 = SidedPlane.constructNormalizedThreePointSidedPlane(currentSegment.start, prevSegment.URHC, currentSegment.ULHC, currentSegment.LLHC);
- final SidedPlane candidate2 = SidedPlane.constructNormalizedThreePointSidedPlane(currentSegment.start, currentSegment.ULHC, currentSegment.LLHC, prevSegment.LRHC);
- final SidedPlane candidate3 = SidedPlane.constructNormalizedThreePointSidedPlane(currentSegment.start, currentSegment.LLHC, prevSegment.LRHC, prevSegment.URHC);
- final SidedPlane candidate4 = SidedPlane.constructNormalizedThreePointSidedPlane(currentSegment.start, prevSegment.LRHC, prevSegment.URHC, currentSegment.ULHC);
-
- if (candidate1 == null && candidate2 == null && candidate3 == null && candidate4 == null) {
- // The planes are identical. We wouldn't need a circle at all except for the possibility of
- // backing up, which is hard to detect here.
- final SegmentEndpoint midEndpoint = new SegmentEndpoint(currentSegment.start,
- prevSegment.endCutoffPlane, currentSegment.startCutoffPlane, currentSegment.ULHC, currentSegment.LLHC);
- //don't need a circle at all. Special constructor...
- endPoints.add(midEndpoint);
- } else {
- endPoints.add(new SegmentEndpoint(currentSegment.start,
- prevSegment.endCutoffPlane, currentSegment.startCutoffPlane,
- prevSegment.URHC, prevSegment.LRHC,
- currentSegment.ULHC, currentSegment.LLHC,
- candidate1, candidate2, candidate3, candidate4));
- }
- }
- // Do final endpoint
- final PathSegment lastSegment = segments.get(segments.size()-1);
- endPoints.add(new SegmentEndpoint(lastSegment.end,
- lastSegment.endCutoffPlane, lastSegment.URHC, lastSegment.LRHC));
-
- }
-
- @Override
- protected double distance(final DistanceStyle distanceStyle, final double x, final double y, final double z) {
- // Algorithm:
- // (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.
- double currentDistance = 0.0;
- for (PathSegment segment : segments) {
- double distance = segment.pathDistance(planetModel, distanceStyle, x,y,z);
- if (distance != Double.MAX_VALUE)
- return currentDistance + distance;
- currentDistance += segment.fullPathDistance(distanceStyle);
- }
-
- int segmentIndex = 0;
- currentDistance = 0.0;
- for (SegmentEndpoint endpoint : endPoints) {
- double distance = endpoint.pathDistance(distanceStyle, x, y, z);
- if (distance != Double.MAX_VALUE)
- return currentDistance + distance;
- if (segmentIndex < segments.size())
- currentDistance += segments.get(segmentIndex++).fullPathDistance(distanceStyle);
- }
-
- return Double.MAX_VALUE;
- }
-
- @Override
- protected double outsideDistance(final DistanceStyle distanceStyle, final double x, final double y, final double z) {
- double minDistance = Double.MAX_VALUE;
- for (final SegmentEndpoint endpoint : endPoints) {
- final double newDistance = endpoint.outsideDistance(distanceStyle, x,y,z);
- if (newDistance < minDistance)
- minDistance = newDistance;
- }
- for (final PathSegment segment : segments) {
- final double newDistance = segment.outsideDistance(planetModel, distanceStyle, x, y, z);
- if (newDistance < minDistance)
- minDistance = newDistance;
- }
- return minDistance;
- }
-
- @Override
- public boolean isWithin(final double x, final double y, final double z) {
- for (SegmentEndpoint pathPoint : endPoints) {
- if (pathPoint.isWithin(x, y, z))
- return true;
- }
- for (PathSegment pathSegment : segments) {
- if (pathSegment.isWithin(x, y, z))
- return true;
- }
- return false;
- }
-
- @Override
- public GeoPoint[] getEdgePoints() {
- return edgePoints;
- }
-
- @Override
- 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 also have to look for intersections with the cones described by the endpoints.
- // Return "true" if any such intersections are found.
-
- // For plane intersections, the basic idea is to come up with an equation of the line that is
- // the intersection (if any). Then, find the intersections with the unit sphere (if any). If
- // any of the intersection points are within the bounds, then we've detected an intersection.
- // Well, sort of. We can detect intersections also due to overlap of segments with each other.
- // But that's an edge case and we won't be optimizing for it.
- //System.err.println(" Looking for intersection of plane "+plane+" with path "+this);
- for (final SegmentEndpoint pathPoint : endPoints) {
- if (pathPoint.intersects(planetModel, plane, notablePoints, bounds)) {
- return true;
- }
- }
-
- for (final PathSegment pathSegment : segments) {
- if (pathSegment.intersects(planetModel, plane, notablePoints, bounds)) {
- return true;
- }
- }
-
- return false;
- }
-
- @Override
- public void getBounds(Bounds bounds) {
- super.getBounds(bounds);
- // For building bounds, order matters. We want to traverse
- // never more than 180 degrees longitude at a pop or we risk having the
- // bounds object get itself inverted. So do the edges first.
- for (PathSegment pathSegment : segments) {
- pathSegment.getBounds(planetModel, bounds);
- }
- for (SegmentEndpoint pathPoint : endPoints) {
- pathPoint.getBounds(planetModel, bounds);
- }
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof GeoPath))
- return false;
- GeoPath p = (GeoPath) o;
- if (!super.equals(p))
- return false;
- if (cutoffAngle != p.cutoffAngle)
- return false;
- return points.equals(p.points);
- }
-
- @Override
- public int hashCode() {
- int result = super.hashCode();
- long temp = Double.doubleToLongBits(cutoffAngle);
- result = 31 * result + (int) (temp ^ (temp >>> 32));
- result = 31 * result + points.hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- return "GeoPath: {planetmodel=" + planetModel+", width=" + cutoffAngle + "(" + cutoffAngle * 180.0 / Math.PI + "), points={" + points + "}}";
- }
-
- /**
- * This is precalculated data for segment endpoint.
- * Note well: This is not necessarily a circle. There are four cases:
- * (1) The path consists of a single endpoint. In this case, we build a simple circle with the proper cutoff offset.
- * (2) This is the end of a path. The circle plane must be constructed to go through two supplied points and be perpendicular to a connecting plane.
- * (2.5) Intersection, but the path on both sides is linear. We generate a circle, but we use the cutoff planes to limit its influence in the straight line case.
- * (3) This is an intersection in a path. We are supplied FOUR planes. If there are intersections within bounds for both upper and lower, then
- * we generate no circle at all. If there is one intersection only, then we generate a plane that includes that intersection, as well as the remaining
- * cutoff plane/edge plane points.
- */
- public static class SegmentEndpoint {
- /** The center point of the endpoint */
- public final GeoPoint point;
- /** A plane describing the circle */
- public final SidedPlane circlePlane;
- /** Pertinent cutoff planes from adjoining segments */
- public final Membership[] cutoffPlanes;
- /** Notable points for this segment endpoint */
- public final GeoPoint[] notablePoints;
- /** No notable points from the circle itself */
- public final static GeoPoint[] circlePoints = new GeoPoint[0];
- /** Null membership */
- public final static Membership[] NO_MEMBERSHIP = new Membership[0];
-
- /** Base case. Does nothing at all.
- */
- public SegmentEndpoint(final GeoPoint point) {
- this.point = point;
- this.circlePlane = null;
- this.cutoffPlanes = null;
- this.notablePoints = null;
- }
-
- /** Constructor for case (1).
- * Generate a simple circle cutoff plane.
- *@param point is the center point.
- *@param upperPoint is a point that must be on the circle plane.
- *@param lowerPoint is another point that must be on the circle plane.
- */
- public SegmentEndpoint(final GeoPoint point, final Plane normalPlane, final GeoPoint upperPoint, final GeoPoint lowerPoint) {
- this.point = point;
- // Construct a sided plane that goes through the two points and whose normal is in the normalPlane.
- this.circlePlane = SidedPlane.constructNormalizedPerpendicularSidedPlane(point, normalPlane, upperPoint, lowerPoint);
- this.cutoffPlanes = NO_MEMBERSHIP;
- this.notablePoints = circlePoints;
- }
-
- /** Constructor for case (2).
- * Generate an endpoint, given a single cutoff plane plus upper and lower edge points.
- *@param point is the center point.
- *@param cutoffPlane is the plane from the adjoining path segment marking the boundary between this endpoint and that segment.
- *@param topEdgePoint is a point on the cutoffPlane that should be also on the circle plane.
- *@param bottomEdgePoint is another point on the cutoffPlane that should be also on the circle plane.
- */
- public SegmentEndpoint(final GeoPoint point,
- final SidedPlane cutoffPlane, final GeoPoint topEdgePoint, final GeoPoint bottomEdgePoint) {
- this.point = point;
- this.cutoffPlanes = new Membership[]{new SidedPlane(cutoffPlane)};
- this.notablePoints = new GeoPoint[]{topEdgePoint, bottomEdgePoint};
- // To construct the plane, we now just need D, which is simply the negative of the evaluation of the circle normal vector at one of the points.
- this.circlePlane = SidedPlane.constructNormalizedPerpendicularSidedPlane(point, cutoffPlane, topEdgePoint, bottomEdgePoint);
- }
-
- /** Constructor for case (2.5).
- * Generate an endpoint, given two cutoff planes plus upper and lower edge points.
- *@param point is the center.
- *@param cutoffPlane1 is one adjoining path segment cutoff plane.
- *@param cutoffPlane2 is another adjoining path segment cutoff plane.
- *@param topEdgePoint is a point on the cutoffPlane that should be also on the circle plane.
- *@param bottomEdgePoint is another point on the cutoffPlane that should be also on the circle plane.
- */
- public SegmentEndpoint(final GeoPoint point,
- final SidedPlane cutoffPlane1, final SidedPlane cutoffPlane2, final GeoPoint topEdgePoint, final GeoPoint bottomEdgePoint) {
- this.point = point;
- this.cutoffPlanes = new Membership[]{new SidedPlane(cutoffPlane1), new SidedPlane(cutoffPlane2)};
- this.notablePoints = new GeoPoint[]{topEdgePoint, bottomEdgePoint};
- // To construct the plane, we now just need D, which is simply the negative of the evaluation of the circle normal vector at one of the points.
- this.circlePlane = SidedPlane.constructNormalizedPerpendicularSidedPlane(point, cutoffPlane1, topEdgePoint, bottomEdgePoint);
- }
-
- /** Constructor for case (3).
- * Generate an endpoint for an intersection, given four points.
- *@param point is the center.
- *@param prevCutoffPlane is the previous adjoining segment cutoff plane.
- *@param nextCutoffPlane is the next path segment cutoff plane.
- *@param notCand2Point is a point NOT on candidate2.
- *@param notCand1Point is a point NOT on candidate1.
- *@param notCand3Point is a point NOT on candidate3.
- *@param notCand4Point is a point NOT on candidate4.
- *@param candidate1 one of four candidate circle planes.
- *@param candidate2 one of four candidate circle planes.
- *@param candidate3 one of four candidate circle planes.
- *@param candidate4 one of four candidate circle planes.
- */
- public SegmentEndpoint(final GeoPoint point,
- final SidedPlane prevCutoffPlane, final SidedPlane nextCutoffPlane,
- final GeoPoint notCand2Point, final GeoPoint notCand1Point,
- final GeoPoint notCand3Point, final GeoPoint notCand4Point,
- final SidedPlane candidate1, final SidedPlane candidate2, final SidedPlane candidate3, final SidedPlane candidate4) {
- // Note: What we really need is a single plane that goes through all four points.
- // Since that's not possible in the ellipsoid case (because three points determine a plane, not four), we
- // need an approximation that at least creates a boundary that has no interruptions.
- // There are three obvious choices for the third point: either (a) one of the two remaining points, or (b) the top or bottom edge
- // intersection point. (a) has no guarantee of continuity, while (b) is capable of producing something very far from a circle if
- // the angle between segments is acute.
- // The solution is to look for the side (top or bottom) that has an intersection within the shape. We use the two points from
- // the opposite side to determine the plane, AND we pick the third to be either of the two points on the intersecting side
- // PROVIDED that the other point is within the final circle we come up with.
- this.point = point;
-
- // We construct four separate planes, and evaluate which one includes all interior points with least overlap
- // (Constructed beforehand because we need them for degeneracy check)
-
- final boolean cand1IsOtherWithin = candidate1!=null?candidate1.isWithin(notCand1Point):false;
- final boolean cand2IsOtherWithin = candidate2!=null?candidate2.isWithin(notCand2Point):false;
- final boolean cand3IsOtherWithin = candidate3!=null?candidate3.isWithin(notCand3Point):false;
- final boolean cand4IsOtherWithin = candidate4!=null?candidate4.isWithin(notCand4Point):false;
-
- if (cand1IsOtherWithin && cand2IsOtherWithin && cand3IsOtherWithin && cand4IsOtherWithin) {
- // The only way we should see both within is if all four points are coplanar. In that case, we default to the simplest treatment.
- this.circlePlane = candidate1; // doesn't matter which
- this.notablePoints = new GeoPoint[]{notCand2Point, notCand3Point, notCand1Point, notCand4Point};
- this.cutoffPlanes = new Membership[]{new SidedPlane(prevCutoffPlane), new SidedPlane(nextCutoffPlane)};
- } else if (cand1IsOtherWithin) {
- // Use candidate1, and DON'T include prevCutoffPlane in the cutoff planes list
- this.circlePlane = candidate1;
- this.notablePoints = new GeoPoint[]{notCand2Point, notCand3Point, notCand4Point};
- this.cutoffPlanes = new Membership[]{new SidedPlane(nextCutoffPlane)};
- } else if (cand2IsOtherWithin) {
- // Use candidate2
- this.circlePlane = candidate2;
- this.notablePoints = new GeoPoint[]{notCand3Point, notCand4Point, notCand1Point};
- this.cutoffPlanes = new Membership[]{new SidedPlane(nextCutoffPlane)};
- } else if (cand3IsOtherWithin) {
- this.circlePlane = candidate3;
- this.notablePoints = new GeoPoint[]{notCand4Point, notCand1Point, notCand2Point};
- this.cutoffPlanes = new Membership[]{new SidedPlane(prevCutoffPlane)};
- } else if (cand4IsOtherWithin) {
- this.circlePlane = candidate4;
- this.notablePoints = new GeoPoint[]{notCand1Point, notCand2Point, notCand3Point};
- this.cutoffPlanes = new Membership[]{new SidedPlane(prevCutoffPlane)};
- } else {
- // dunno what happened
- throw new RuntimeException("Couldn't come up with a plane through three points that included the fourth");
- }
- }
-
- /** Check if point is within this endpoint.
- *@param point is the point.
- *@return true of within.
- */
- public boolean isWithin(final Vector point) {
- if (circlePlane == null)
- return false;
- if (!circlePlane.isWithin(point))
- return false;
- for (final Membership m : cutoffPlanes) {
- if (!m.isWithin(point)) {
- return false;
- }
- }
- return true;
- }
-
- /** Check if point is within this endpoint.
- *@param x is the point x.
- *@param y is the point y.
- *@param z is the point z.
- *@return true of within.
- */
- public boolean isWithin(final double x, final double y, final double z) {
- if (circlePlane == null)
- return false;
- if (!circlePlane.isWithin(x, y, z))
- return false;
- for (final Membership m : cutoffPlanes) {
- if (!m.isWithin(x,y,z)) {
- return false;
- }
- }
- return true;
- }
-
- /** Compute interior path distance.
- *@param distanceStyle is the distance style.
- *@param x is the point x.
- *@param y is the point y.
- *@param z is the point z.
- *@return the distance metric.
- */
- public double pathDistance(final DistanceStyle distanceStyle, final double x, final double y, final double z) {
- if (!isWithin(x,y,z))
- return Double.MAX_VALUE;
- return distanceStyle.computeDistance(this.point, x, y, z);
- }
-
- /** Compute external distance.
- *@param distanceStyle is the distance style.
- *@param x is the point x.
- *@param y is the point y.
- *@param z is the point z.
- *@return the distance metric.
- */
- public double outsideDistance(final DistanceStyle distanceStyle, final double x, final double y, final double z) {
- return distanceStyle.computeDistance(this.point, x, y, z);
- }
-
- /** Determine if this endpoint intersects a specified plane.
- *@param planetModel is the planet model.
- *@param p is the plane.
- *@param notablePoints are the points associated with the plane.
- *@param bounds are any bounds which the intersection must lie within.
- *@return true if there is a matching intersection.
- */
- public boolean intersects(final PlanetModel planetModel, final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds) {
- //System.err.println(" looking for intersection between plane "+p+" and circle "+circlePlane+" on proper side of "+cutoffPlanes+" within "+bounds);
- if (circlePlane == null)
- return false;
- return circlePlane.intersects(planetModel, p, notablePoints, this.notablePoints, bounds, this.cutoffPlanes);
- }
-
- /** Get the bounds for a segment endpoint.
- *@param planetModel is the planet model.
- *@param bounds are the bounds to be modified.
- */
- public void getBounds(final PlanetModel planetModel, Bounds bounds) {
- bounds.addPoint(point);
- if (circlePlane == null)
- return;
- bounds.addPlane(planetModel, circlePlane);
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof SegmentEndpoint))
- return false;
- SegmentEndpoint other = (SegmentEndpoint) o;
- return point.equals(other.point);
- }
-
- @Override
- public int hashCode() {
- return point.hashCode();
- }
-
- @Override
- public String toString() {
- return point.toString();
- }
- }
-
- /**
- * This is the pre-calculated data for a path segment.
- */
- public static class PathSegment {
- /** Starting point of the segment */
- public final GeoPoint start;
- /** End point of the segment */
- public final GeoPoint end;
- /** Place to keep any complete segment distances we've calculated so far */
- public final Map<DistanceStyle,Double> fullDistanceCache = new HashMap<DistanceStyle,Double>();
- /** Normalized plane connecting the two points and going through world center */
- public final Plane normalizedConnectingPlane;
- /** Cutoff plane parallel to connecting plane representing one side of the path segment */
- public final SidedPlane upperConnectingPlane;
- /** Cutoff plane parallel to connecting plane representing the other side of the path segment */
- public final SidedPlane lowerConnectingPlane;
- /** Plane going through the center and start point, marking the start edge of the segment */
- public final SidedPlane startCutoffPlane;
- /** Plane going through the center and end point, marking the end edge of the segment */
- public final SidedPlane endCutoffPlane;
- /** Upper right hand corner of segment */
- public final GeoPoint URHC;
- /** Lower right hand corner of segment */
- public final GeoPoint LRHC;
- /** Upper left hand corner of segment */
- public final GeoPoint ULHC;
- /** Lower left hand corner of segment */
- public final GeoPoint LLHC;
- /** Notable points for the upper connecting plane */
- public final GeoPoint[] upperConnectingPlanePoints;
- /** Notable points for the lower connecting plane */
- public final GeoPoint[] lowerConnectingPlanePoints;
- /** Notable points for the start cutoff plane */
- public final GeoPoint[] startCutoffPlanePoints;
- /** Notable points for the end cutoff plane */
- public final GeoPoint[] endCutoffPlanePoints;
-
- /** Construct a path segment.
- *@param planetModel is the planet model.
- *@param start is the starting point.
- *@param end is the ending point.
- *@param normalizedConnectingPlane is the connecting plane.
- *@param planeBoundingOffset is the linear offset from the connecting plane to either side.
- */
- public PathSegment(final PlanetModel planetModel, final GeoPoint start, final GeoPoint end,
- final Plane normalizedConnectingPlane, final double planeBoundingOffset) {
- this.start = start;
- this.end = end;
- this.normalizedConnectingPlane = normalizedConnectingPlane;
-
- // Either start or end should be on the correct side
- upperConnectingPlane = new SidedPlane(start, normalizedConnectingPlane, -planeBoundingOffset);
- lowerConnectingPlane = new SidedPlane(start, normalizedConnectingPlane, planeBoundingOffset);
- // Cutoff planes use opposite endpoints as correct side examples
- startCutoffPlane = new SidedPlane(end, normalizedConnectingPlane, start);
- endCutoffPlane = new SidedPlane(start, normalizedConnectingPlane, end);
- final Membership[] upperSide = new Membership[]{upperConnectingPlane};
- final Membership[] lowerSide = new Membership[]{lowerConnectingPlane};
- final Membership[] startSide = new Membership[]{startCutoffPlane};
- final Membership[] endSide = new Membership[]{endCutoffPlane};
- GeoPoint[] points;
- points = upperConnectingPlane.findIntersections(planetModel, startCutoffPlane, lowerSide, endSide);
- if (points.length == 0) {
- throw new IllegalArgumentException("Some segment boundary points are off the ellipsoid; path too wide");
- }
- this.ULHC = points[0];
- points = upperConnectingPlane.findIntersections(planetModel, endCutoffPlane, lowerSide, startSide);
- if (points.length == 0) {
- throw new IllegalArgumentException("Some segment boundary points are off the ellipsoid; path too wide");
- }
- this.URHC = points[0];
- points = lowerConnectingPlane.findIntersections(planetModel, startCutoffPlane, upperSide, endSide);
- if (points.length == 0) {
- throw new IllegalArgumentException("Some segment boundary points are off the ellipsoid; path too wide");
- }
- this.LLHC = points[0];
- points = lowerConnectingPlane.findIntersections(planetModel, endCutoffPlane, upperSide, startSide);
- if (points.length == 0) {
- throw new IllegalArgumentException("Some segment boundary points are off the ellipsoid; path too wide");
- }
- this.LRHC = points[0];
- upperConnectingPlanePoints = new GeoPoint[]{ULHC, URHC};
- lowerConnectingPlanePoints = new GeoPoint[]{LLHC, LRHC};
- startCutoffPlanePoints = new GeoPoint[]{ULHC, LLHC};
- endCutoffPlanePoints = new GeoPoint[]{URHC, LRHC};
- }
-
- /** Compute the full distance along this path segment.
- *@param distanceStyle is the distance style.
- *@return the distance metric.
- */
- public double fullPathDistance(final DistanceStyle distanceStyle) {
- synchronized (fullDistanceCache) {
- Double dist = fullDistanceCache.get(distanceStyle);
- if (dist == null) {
- dist = new Double(distanceStyle.computeDistance(start, end.x, end.y, end.z));
- fullDistanceCache.put(distanceStyle, dist);
- }
- return dist.doubleValue();
- }
- }
-
- /** Check if point is within this segment.
- *@param point is the point.
- *@return true of within.
- */
- public boolean isWithin(final Vector point) {
- return startCutoffPlane.isWithin(point) &&
- endCutoffPlane.isWithin(point) &&
- upperConnectingPlane.isWithin(point) &&
- lowerConnectingPlane.isWithin(point);
- }
-
- /** Check if point is within this segment.
- *@param x is the point x.
- *@param y is the point y.
- *@param z is the point z.
- *@return true of within.
- */
- public boolean isWithin(final double x, final double y, final double z) {
- return startCutoffPlane.isWithin(x, y, z) &&
- endCutoffPlane.isWithin(x, y, z) &&
- upperConnectingPlane.isWithin(x, y, z) &&
- lowerConnectingPlane.isWithin(x, y, z);
- }
-
- /** Compute interior path distance.
- *@param planetModel is the planet model.
- *@param distanceStyle is the distance style.
- *@param x is the point x.
- *@param y is the point y.
- *@param z is the point z.
- *@return the distance metric.
- */
- public double pathDistance(final PlanetModel planetModel, final DistanceStyle distanceStyle, final double x, final double y, final double z) {
- if (!isWithin(x,y,z))
- return Double.MAX_VALUE;
-
- // (1) Compute normalizedPerpPlane. If degenerate, then return point distance from start to point.
- // Want no allocations or expensive operations! so we do this the hard way
- final double perpX = normalizedConnectingPlane.y * z - normalizedConnectingPlane.z * y;
- final double perpY = normalizedConnectingPlane.z * x - normalizedConnectingPlane.x * z;
- final double perpZ = normalizedConnectingPlane.x * y - normalizedConnectingPlane.y * x;
- final double magnitude = Math.sqrt(perpX * perpX + perpY * perpY + perpZ * perpZ);
- if (Math.abs(magnitude) < Vector.MINIMUM_RESOLUTION)
- return distanceStyle.computeDistance(start, x,y,z);
- final double normFactor = 1.0/magnitude;
- final Plane normalizedPerpPlane = new Plane(perpX * normFactor, perpY * normFactor, perpZ * normFactor, 0.0);
-
- // Old computation: too expensive, because it calculates the intersection point twice.
- //return distanceStyle.computeDistance(planetModel, normalizedConnectingPlane, x, y, z, startCutoffPlane, endCutoffPlane) +
- // distanceStyle.computeDistance(planetModel, normalizedPerpPlane, start.x, start.y, start.z, upperConnectingPlane, lowerConnectingPlane);
-
- final GeoPoint[] intersectionPoints = normalizedConnectingPlane.findIntersections(planetModel, normalizedPerpPlane);
- GeoPoint thePoint;
- if (intersectionPoints.length == 0)
- throw new RuntimeException("Can't find world intersection for point x="+x+" y="+y+" z="+z);
- else if (intersectionPoints.length == 1)
- thePoint = intersectionPoints[0];
- else {
- if (startCutoffPlane.isWithin(intersectionPoints[0]) && endCutoffPlane.isWithin(intersectionPoints[0]))
- thePoint = intersectionPoints[0];
- else if (startCutoffPlane.isWithin(intersectionPoints[1]) && endCutoffPlane.isWithin(intersectionPoints[1]))
- thePoint = intersectionPoints[1];
- else
- throw new RuntimeException("Can't find world intersection for point x="+x+" y="+y+" z="+z);
- }
- return distanceStyle.computeDistance(thePoint, x, y, z) + distanceStyle.computeDistance(start, thePoint.x, thePoint.y, thePoint.z);
- }
-
- /** Compute external distance.
- *@param planetModel is the planet model.
- *@param distanceStyle is the distance style.
- *@param x is the point x.
- *@param y is the point y.
- *@param z is the point z.
- *@return the distance metric.
- */
- public double outsideDistance(final PlanetModel planetModel, final DistanceStyle distanceStyle, final double x, final double y, final double z) {
- final double upperDistance = distanceStyle.computeDistance(planetModel, upperConnectingPlane, x,y,z, lowerConnectingPlane, startCutoffPlane, endCutoffPlane);
- final double lowerDistance = distanceStyle.computeDistance(planetModel, lowerConnectingPlane, x,y,z, upperConnectingPlane, startCutoffPlane, endCutoffPlane);
- final double startDistance = distanceStyle.computeDistance(planetModel, startCutoffPlane, x,y,z, endCutoffPlane, lowerConnectingPlane, upperConnectingPlane);
- final double endDistance = distanceStyle.computeDistance(planetModel, endCutoffPlane, x,y,z, startCutoffPlane, lowerConnectingPlane, upperConnectingPlane);
- final double ULHCDistance = distanceStyle.computeDistance(ULHC, x,y,z);
- final double URHCDistance = distanceStyle.computeDistance(URHC, x,y,z);
- final double LLHCDistance = distanceStyle.computeDistance(LLHC, x,y,z);
- final double LRHCDistance = distanceStyle.computeDistance(LRHC, x,y,z);
- return Math.min(
- Math.min(
- Math.min(upperDistance,lowerDistance),
- Math.min(startDistance,endDistance)),
- Math.min(
- Math.min(ULHCDistance, URHCDistance),
- Math.min(LLHCDistance, LRHCDistance)));
- }
-
- /** Determine if this endpoint intersects a specified plane.
- *@param planetModel is the planet model.
- *@param p is the plane.
- *@param notablePoints are the points associated with the plane.
- *@param bounds are any bounds which the intersection must lie within.
- *@return true if there is a matching intersection.
- */
- public boolean intersects(final PlanetModel planetModel, final Plane p, final GeoPoint[] notablePoints, final Membership[] bounds) {
- return upperConnectingPlane.intersects(planetModel, p, notablePoints, upperConnectingPlanePoints, bounds, lowerConnectingPlane, startCutoffPlane, endCutoffPlane) ||
- lowerConnectingPlane.intersects(planetModel, p, notablePoints, lowerConnectingPlanePoints, bounds, upperConnectingPlane, startCutoffPlane, endCutoffPlane);
- }
-
- /** Get the bounds for a segment endpoint.
- *@param planetModel is the planet model.
- *@param bounds are the bounds to be modified.
- */
- public void getBounds(final PlanetModel planetModel, Bounds bounds) {
- // We need to do all bounding planes as well as corner points
- bounds.addPoint(start).addPoint(end).addPoint(ULHC).addPoint(URHC).addPoint(LRHC).addPoint(LLHC);
- bounds.addPlane(planetModel, upperConnectingPlane, lowerConnectingPlane, startCutoffPlane, endCutoffPlane);
- bounds.addPlane(planetModel, lowerConnectingPlane, upperConnectingPlane, startCutoffPlane, endCutoffPlane);
- bounds.addPlane(planetModel, startCutoffPlane, endCutoffPlane, upperConnectingPlane, lowerConnectingPlane);
- bounds.addPlane(planetModel, endCutoffPlane, startCutoffPlane, upperConnectingPlane, lowerConnectingPlane);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f7f81c32/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPoint.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPoint.java b/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPoint.java
deleted file mode 100755
index e8a265d..0000000
--- a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPoint.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.geo3d;
-
-/**
- * This class represents a point on the surface of a sphere or ellipsoid.
- *
- * @lucene.experimental
- */
-public class GeoPoint extends Vector {
-
- // By making lazily-evaluated variables be "volatile", we guarantee atomicity when they
- // are updated. This is necessary if we are using these classes in a multi-thread fashion,
- // because we don't try to synchronize for the lazy computation.
-
- /** This is the lazily-evaluated magnitude. Some constructors include it, but others don't, and
- * we try not to create extra computation by always computing it. Does not need to be
- * synchronized for thread safety, because depends wholly on immutable variables of this class. */
- protected volatile double magnitude = Double.NEGATIVE_INFINITY;
- /** Lazily-evaluated latitude. Does not need to be
- * synchronized for thread safety, because depends wholly on immutable variables of this class. */
- protected volatile double latitude = Double.NEGATIVE_INFINITY;
- /** Lazily-evaluated longitude. Does not need to be
- * synchronized for thread safety, because depends wholly on immutable variables of this class. */
- protected volatile double longitude = Double.NEGATIVE_INFINITY;
-
- /** Construct a GeoPoint from the trig functions of a lat and lon pair.
- * @param planetModel is the planetModel to put the point on.
- * @param sinLat is the sin of the latitude.
- * @param sinLon is the sin of the longitude.
- * @param cosLat is the cos of the latitude.
- * @param cosLon is the cos of the longitude.
- * @param lat is the latitude.
- * @param lon is the longitude.
- */
- public GeoPoint(final PlanetModel planetModel, final double sinLat, final double sinLon, final double cosLat, final double cosLon, final double lat, final double lon) {
- this(computeDesiredEllipsoidMagnitude(planetModel, cosLat * cosLon, cosLat * sinLon, sinLat),
- cosLat * cosLon, cosLat * sinLon, sinLat, lat, lon);
- }
-
- /** Construct a GeoPoint from the trig functions of a lat and lon pair.
- * @param planetModel is the planetModel to put the point on.
- * @param sinLat is the sin of the latitude.
- * @param sinLon is the sin of the longitude.
- * @param cosLat is the cos of the latitude.
- * @param cosLon is the cos of the longitude.
- */
- public GeoPoint(final PlanetModel planetModel, final double sinLat, final double sinLon, final double cosLat, final double cosLon) {
- this(computeDesiredEllipsoidMagnitude(planetModel, cosLat * cosLon, cosLat * sinLon, sinLat),
- cosLat * cosLon, cosLat * sinLon, sinLat);
- }
-
- /** Construct a GeoPoint from a latitude/longitude pair.
- * @param planetModel is the planetModel to put the point on.
- * @param lat is the latitude.
- * @param lon is the longitude.
- */
- public GeoPoint(final PlanetModel planetModel, final double lat, final double lon) {
- this(planetModel, Math.sin(lat), Math.sin(lon), Math.cos(lat), Math.cos(lon), lat, lon);
- }
-
- /** Construct a GeoPoint from a unit (x,y,z) vector and a magnitude.
- * @param magnitude is the desired magnitude, provided to put the point on the ellipsoid.
- * @param x is the unit x value.
- * @param y is the unit y value.
- * @param z is the unit z value.
- * @param lat is the latitude.
- * @param lon is the longitude.
- */
- public GeoPoint(final double magnitude, final double x, final double y, final double z, double lat, double lon) {
- super(x * magnitude, y * magnitude, z * magnitude);
- this.magnitude = magnitude;
- if (lat > Math.PI * 0.5 || lat < -Math.PI * 0.5) {
- throw new IllegalArgumentException("Latitude " + lat + " is out of range: must range from -Math.PI/2 to Math.PI/2");
- }
- if (lon < -Math.PI || lon > Math.PI) {
- throw new IllegalArgumentException("Longitude " + lon + " is out of range: must range from -Math.PI to Math.PI");
- }
- this.latitude = lat;
- this.longitude = lon;
- }
-
- /** Construct a GeoPoint from a unit (x,y,z) vector and a magnitude.
- * @param magnitude is the desired magnitude, provided to put the point on the ellipsoid.
- * @param x is the unit x value.
- * @param y is the unit y value.
- * @param z is the unit z value.
- */
- public GeoPoint(final double magnitude, final double x, final double y, final double z) {
- super(x * magnitude, y * magnitude, z * magnitude);
- this.magnitude = magnitude;
- }
-
- /** Construct a GeoPoint from an (x,y,z) value.
- * The (x,y,z) tuple must be on the desired ellipsoid.
- * @param x is the ellipsoid point x value.
- * @param y is the ellipsoid point y value.
- * @param z is the ellipsoid point z value.
- */
- public GeoPoint(final double x, final double y, final double z) {
- super(x, y, z);
- }
-
- /** Compute an arc distance between two points.
- * Note: this is an angular distance, and not a surface distance, and is therefore independent of planet model.
- * For surface distance, see {@link org.apache.lucene.geo3d.PlanetModel#surfaceDistance(GeoPoint, GeoPoint)}
- * @param v is the second point.
- * @return the angle, in radians, between the two points.
- */
- public double arcDistance(final GeoPoint v) {
- return Tools.safeAcos(dotProduct(v)/(magnitude() * v.magnitude()));
- }
-
- /** Compute an arc distance between two points.
- * @param x is the x part of the second point.
- * @param y is the y part of the second point.
- * @param z is the z part of the second point.
- * @return the angle, in radians, between the two points.
- */
- public double arcDistance(final double x, final double y, final double z) {
- return Tools.safeAcos(dotProduct(x,y,z)/(magnitude() * Vector.magnitude(x,y,z)));
- }
-
- /** Compute the latitude for the point.
- * @return the latitude.
- */
- public double getLatitude() {
- double lat = this.latitude;//volatile-read once
- if (lat == Double.NEGATIVE_INFINITY)
- this.latitude = lat = Math.asin(z / magnitude());
- return lat;
- }
-
- /** Compute the longitude for the point.
- * @return the longitude value. Uses 0.0 if there is no computable longitude.
- */
- public double getLongitude() {
- double lon = this.longitude;//volatile-read once
- if (lon == Double.NEGATIVE_INFINITY) {
- if (Math.abs(x) < MINIMUM_RESOLUTION && Math.abs(y) < MINIMUM_RESOLUTION)
- this.longitude = lon = 0.0;
- else
- this.longitude = lon = Math.atan2(y,x);
- }
- return lon;
- }
-
- /** Compute the linear magnitude of the point.
- * @return the magnitude.
- */
- @Override
- public double magnitude() {
- double mag = this.magnitude;//volatile-read once
- if (mag == Double.NEGATIVE_INFINITY) {
- this.magnitude = mag = super.magnitude();
- }
- return mag;
- }
-
- /** Compute whether point matches another.
- *@param x is the x value
- *@param y is the y value
- *@param z is the z value
- *@return true if the same.
- */
- public boolean isIdentical(final double x, final double y, final double z) {
- return Math.abs(this.x - x) < MINIMUM_RESOLUTION &&
- Math.abs(this.y - y) < MINIMUM_RESOLUTION &&
- Math.abs(this.z - z) < MINIMUM_RESOLUTION;
- }
-
- @Override
- public String toString() {
- if (this.longitude == Double.NEGATIVE_INFINITY) {
- return super.toString();
- }
- return "[lat="+getLatitude()+", lon="+getLongitude()+"]";
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f7f81c32/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPolygon.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPolygon.java
deleted file mode 100644
index 634406d..0000000
--- a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPolygon.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.geo3d;
-
-/**
- * GeoPolygon interface description.
- *
- * @lucene.experimental
- */
-public interface GeoPolygon extends GeoMembershipShape {
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f7f81c32/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPolygonFactory.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPolygonFactory.java b/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPolygonFactory.java
deleted file mode 100755
index 0dc70a5..0000000
--- a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoPolygonFactory.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.geo3d;
-
-import java.util.ArrayList;
-import java.util.BitSet;
-import java.util.List;
-
-/**
- * Class which constructs a GeoMembershipShape representing an arbitrary polygon.
- *
- * @lucene.experimental
- */
-public class GeoPolygonFactory {
- private GeoPolygonFactory() {
- }
-
- /**
- * 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 convexPointIndex is the index of a single convex point whose conformation with
- * its neighbors determines inside/outside for the entire polygon.
- * @return a GeoPolygon corresponding to what was specified.
- */
- public static GeoPolygon makeGeoPolygon(final PlanetModel planetModel, final List<GeoPoint> pointList, final int convexPointIndex) {
- // The basic operation uses a set of points, two points determining one particular edge, and a sided plane
- // describing membership.
- return buildPolygonShape(planetModel, pointList, convexPointIndex, getLegalIndex(convexPointIndex + 1, pointList.size()),
- new SidedPlane(pointList.get(getLegalIndex(convexPointIndex - 1, pointList.size())),
- pointList.get(convexPointIndex), pointList.get(getLegalIndex(convexPointIndex + 1, pointList.size()))),
- false);
- }
-
- /** Build a GeoMembershipShape given points, starting edge, and whether starting edge is internal or not.
- * @param pointsList is a list of the GeoPoints to build an arbitrary polygon out of.
- * @param startPointIndex is one of the points constituting the starting edge.
- * @param endPointIndex is another of the points constituting the starting edge.
- * @param startingEdge is the plane describing the starting edge.
- * @param isInternalEdge is true if the specified edge is an internal one.
- * @return a GeoMembershipShape corresponding to what was specified.
- */
- public static GeoPolygon buildPolygonShape(final PlanetModel planetModel, final List<GeoPoint> pointsList, final int startPointIndex, final int endPointIndex, final SidedPlane startingEdge, final boolean isInternalEdge) {
- // Algorithm as follows:
- // Start with sided edge. Go through all points in some order. For each new point, determine if the point is within all edges considered so far.
- // If not, put it into a list of points for recursion. If it is within, add new edge and keep going.
- // Once we detect a point that is within, if there are points put aside for recursion, then call recursively.
-
- // Current composite. This is what we'll actually be returning.
- final GeoCompositePolygon rval = new GeoCompositePolygon();
-
- final List<GeoPoint> recursionList = new ArrayList<GeoPoint>();
- final List<GeoPoint> currentList = new ArrayList<GeoPoint>();
- final BitSet internalEdgeList = new BitSet();
- final List<SidedPlane> currentPlanes = new ArrayList<SidedPlane>();
-
- // Initialize the current list and current planes
- currentList.add(pointsList.get(startPointIndex));
- currentList.add(pointsList.get(endPointIndex));
- internalEdgeList.set(currentPlanes.size(), isInternalEdge);
- currentPlanes.add(startingEdge);
-
- // Now, scan all remaining points, in order. We'll use an index and just add to it.
- for (int i = 0; i < pointsList.size() - 2; i++) {
- GeoPoint newPoint = pointsList.get(getLegalIndex(i + endPointIndex + 1, pointsList.size()));
- if (isWithin(newPoint, currentPlanes)) {
- // Construct a sided plane based on the last two points, and the previous point
- SidedPlane newBoundary = new SidedPlane(currentList.get(currentList.size() - 2), newPoint, currentList.get(currentList.size() - 1));
- // Construct a sided plane based on the return trip
- SidedPlane returnBoundary = new SidedPlane(currentList.get(currentList.size() - 1), currentList.get(0), newPoint);
- // Verify that none of the points beyond the new point in the list are inside the polygon we'd
- // be creating if we stopped making the current polygon right now.
- boolean pointInside = false;
- for (int j = i + 1; j < pointsList.size() - 2; j++) {
- GeoPoint checkPoint = pointsList.get(getLegalIndex(j + endPointIndex + 1, pointsList.size()));
- boolean isInside = true;
- if (isInside && !newBoundary.isWithin(checkPoint))
- isInside = false;
- if (isInside && !returnBoundary.isWithin(checkPoint))
- isInside = false;
- if (isInside) {
- for (SidedPlane plane : currentPlanes) {
- if (!plane.isWithin(checkPoint)) {
- isInside = false;
- break;
- }
- }
- }
- if (isInside) {
- pointInside = true;
- break;
- }
- }
- if (!pointInside) {
- // Any excluded points?
- boolean isInternalBoundary = recursionList.size() > 0;
- if (isInternalBoundary) {
- // Handle exclusion
- recursionList.add(newPoint);
- recursionList.add(currentList.get(currentList.size() - 1));
- if (recursionList.size() == pointsList.size()) {
- // We are trying to recurse with a list the same size as the one we started with.
- // Clearly, the polygon cannot be constructed
- throw new IllegalArgumentException("Polygon is illegal; cannot be decomposed into convex parts");
- }
- // We want the other side for the recursion
- SidedPlane otherSideNewBoundary = new SidedPlane(newBoundary);
- rval.addShape(buildPolygonShape(planetModel, recursionList, recursionList.size() - 2, recursionList.size() - 1, otherSideNewBoundary, true));
- recursionList.clear();
- }
- currentList.add(newPoint);
- internalEdgeList.set(currentPlanes.size(), isInternalBoundary);
- currentPlanes.add(newBoundary);
- } else {
- recursionList.add(newPoint);
- }
- } else {
- recursionList.add(newPoint);
- }
- }
-
- boolean returnEdgeInternalBoundary = recursionList.size() > 0;
- if (returnEdgeInternalBoundary) {
- // The last step back to the start point had a recursion, so take care of that before we complete our work
- recursionList.add(currentList.get(0));
- recursionList.add(currentList.get(currentList.size() - 1));
- if (recursionList.size() == pointsList.size()) {
- // We are trying to recurse with a list the same size as the one we started with.
- // Clearly, the polygon cannot be constructed
- throw new IllegalArgumentException("Polygon is illegal; cannot be decomposed into convex parts");
- }
- // Construct a sided plane based on these two points, and the previous point
- SidedPlane newBoundary = new SidedPlane(currentList.get(currentList.size() - 2), currentList.get(0), currentList.get(currentList.size() - 1));
- // We want the other side for the recursion
- SidedPlane otherSideNewBoundary = new SidedPlane(newBoundary);
- rval.addShape(buildPolygonShape(planetModel, recursionList, recursionList.size() - 2, recursionList.size() - 1, otherSideNewBoundary, true));
- recursionList.clear();
- }
- // Now, add in the current shape.
- rval.addShape(new GeoConvexPolygon(planetModel, currentList, internalEdgeList, returnEdgeInternalBoundary));
- //System.out.println("Done creating polygon");
- return rval;
- }
-
- /** Check if a point is within a described list of planes.
- *@param newPoint is the point.
- *@param currentPlanes is the list of planes.
- *@return true if within.
- */
- protected static boolean isWithin(final GeoPoint newPoint, final List<SidedPlane> currentPlanes) {
- for (SidedPlane p : currentPlanes) {
- if (!p.isWithin(newPoint))
- return false;
- }
- return true;
- }
-
- /** Convert raw point index into valid array position.
- *@param index is the array index.
- *@param size is the array size.
- *@return an updated index.
- */
- protected static int getLegalIndex(int index, int size) {
- while (index < 0) {
- index += size;
- }
- while (index >= size) {
- index -= size;
- }
- return index;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f7f81c32/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoRectangle.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoRectangle.java b/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoRectangle.java
deleted file mode 100755
index fc2a531..0000000
--- a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoRectangle.java
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.geo3d;
-
-/**
- * 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
- * GeoWideRectangle.
- *
- * @lucene.internal
- */
-public class GeoRectangle extends GeoBaseBBox {
- /** The top latitude of the rect */
- protected final double topLat;
- /** The bottom latitude of the rect */
- protected final double bottomLat;
- /** The left longitude of the rect */
- protected final double leftLon;
- /** The right longitude of the rect */
- protected final double rightLon;
- /** The cosine of a middle latitude */
- protected final double cosMiddleLat;
-
- /** The upper left hand corner point */
- protected final GeoPoint ULHC;
- /** The upper right hand corner point */
- protected final GeoPoint URHC;
- /** The lower right hand corner point */
- protected final GeoPoint LRHC;
- /** The lower left hand corner point */
- protected final GeoPoint LLHC;
-
- /** The top plane */
- protected final SidedPlane topPlane;
- /** The bottom plane */
- protected final SidedPlane bottomPlane;
- /** The left plane */
- protected final SidedPlane leftPlane;
- /** The right plane */
- protected final SidedPlane rightPlane;
-
- /** Notable points for the top plane */
- protected final GeoPoint[] topPlanePoints;
- /** Notable points for the bottom plane */
- protected final GeoPoint[] bottomPlanePoints;
- /** Notable points for the left plane */
- protected final GeoPoint[] leftPlanePoints;
- /** Notable points for the right plane */
- protected final GeoPoint[] rightPlanePoints;
-
- /** Center point */
- protected final GeoPoint centerPoint;
-
- /** Edge point for this rectangle */
- protected final GeoPoint[] edgePoints;
-
- /**
- * Accepts only values in the following ranges: lat: {@code -PI/2 -> PI/2}, lon: {@code -PI -> PI}
- *@param planetModel is the planet model.
- *@param topLat is the top latitude.
- *@param bottomLat is the bottom latitude.
- *@param leftLon is the left longitude.
- *@param rightLon is the right longitude.
- */
- public GeoRectangle(final PlanetModel planetModel, final double topLat, final double bottomLat, final double leftLon, double rightLon) {
- super(planetModel);
- // Argument checking
- if (topLat > Math.PI * 0.5 || topLat < -Math.PI * 0.5)
- throw new IllegalArgumentException("Top latitude out of range");
- if (bottomLat > Math.PI * 0.5 || bottomLat < -Math.PI * 0.5)
- throw new IllegalArgumentException("Bottom latitude out of range");
- if (topLat < bottomLat)
- throw new IllegalArgumentException("Top latitude less than bottom latitude");
- if (leftLon < -Math.PI || leftLon > Math.PI)
- throw new IllegalArgumentException("Left longitude out of range");
- if (rightLon < -Math.PI || rightLon > Math.PI)
- throw new IllegalArgumentException("Right longitude out of range");
- double extent = rightLon - leftLon;
- if (extent < 0.0) {
- extent += 2.0 * Math.PI;
- }
- if (extent > Math.PI)
- throw new IllegalArgumentException("Width of rectangle too great");
-
- this.topLat = topLat;
- this.bottomLat = bottomLat;
- this.leftLon = leftLon;
- this.rightLon = rightLon;
-
- final double sinTopLat = Math.sin(topLat);
- final double cosTopLat = Math.cos(topLat);
- final double sinBottomLat = Math.sin(bottomLat);
- final double cosBottomLat = Math.cos(bottomLat);
- final double sinLeftLon = Math.sin(leftLon);
- final double cosLeftLon = Math.cos(leftLon);
- final double sinRightLon = Math.sin(rightLon);
- final double cosRightLon = Math.cos(rightLon);
-
- // Now build the four points
- this.ULHC = new GeoPoint(planetModel, sinTopLat, sinLeftLon, cosTopLat, cosLeftLon, topLat, leftLon);
- this.URHC = new GeoPoint(planetModel, sinTopLat, sinRightLon, cosTopLat, cosRightLon, topLat, rightLon);
- this.LRHC = new GeoPoint(planetModel, sinBottomLat, sinRightLon, cosBottomLat, cosRightLon, bottomLat, rightLon);
- this.LLHC = new GeoPoint(planetModel, sinBottomLat, sinLeftLon, cosBottomLat, cosLeftLon, bottomLat, leftLon);
-
- final double middleLat = (topLat + bottomLat) * 0.5;
- final double sinMiddleLat = Math.sin(middleLat);
- this.cosMiddleLat = Math.cos(middleLat);
- // Normalize
- while (leftLon > rightLon) {
- rightLon += Math.PI * 2.0;
- }
- final double middleLon = (leftLon + rightLon) * 0.5;
- final double sinMiddleLon = Math.sin(middleLon);
- final double cosMiddleLon = Math.cos(middleLon);
-
- this.centerPoint = new GeoPoint(planetModel, sinMiddleLat, sinMiddleLon, cosMiddleLat, cosMiddleLon);
-
- this.topPlane = new SidedPlane(centerPoint, planetModel, sinTopLat);
- this.bottomPlane = new SidedPlane(centerPoint, planetModel, sinBottomLat);
- this.leftPlane = new SidedPlane(centerPoint, cosLeftLon, sinLeftLon);
- this.rightPlane = new SidedPlane(centerPoint, cosRightLon, sinRightLon);
-
- this.topPlanePoints = new GeoPoint[]{ULHC, URHC};
- this.bottomPlanePoints = new GeoPoint[]{LLHC, LRHC};
- this.leftPlanePoints = new GeoPoint[]{ULHC, LLHC};
- this.rightPlanePoints = new GeoPoint[]{URHC, LRHC};
-
- this.edgePoints = new GeoPoint[]{ULHC};
- }
-
- @Override
- public GeoBBox expand(final double angle) {
- final double newTopLat = topLat + angle;
- final double newBottomLat = bottomLat - angle;
- // Figuring out when we escalate to a special case requires some prefiguring
- double currentLonSpan = rightLon - leftLon;
- if (currentLonSpan < 0.0)
- currentLonSpan += Math.PI * 2.0;
- double newLeftLon = leftLon - angle;
- double newRightLon = rightLon + angle;
- if (currentLonSpan + 2.0 * angle >= Math.PI * 2.0) {
- newLeftLon = -Math.PI;
- newRightLon = Math.PI;
- }
- return GeoBBoxFactory.makeGeoBBox(planetModel, newTopLat, newBottomLat, newLeftLon, newRightLon);
- }
-
- @Override
- public boolean isWithin(final double x, final double y, final double z) {
- return topPlane.isWithin(x, y, z) &&
- bottomPlane.isWithin(x, y, z) &&
- leftPlane.isWithin(x, y, z) &&
- rightPlane.isWithin(x, y, z);
- }
-
- @Override
- public double getRadius() {
- // 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
- // the distance to the right or left edge from the center.
- final double centerAngle = (rightLon - (rightLon + leftLon) * 0.5) * cosMiddleLat;
- final double topAngle = centerPoint.arcDistance(URHC);
- final double bottomAngle = centerPoint.arcDistance(LLHC);
- return Math.max(centerAngle, Math.max(topAngle, bottomAngle));
- }
-
- @Override
- public GeoPoint[] getEdgePoints() {
- return edgePoints;
- }
-
- @Override
- public GeoPoint getCenter() {
- return centerPoint;
- }
-
- @Override
- public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
- return p.intersects(planetModel, topPlane, notablePoints, topPlanePoints, bounds, bottomPlane, leftPlane, rightPlane) ||
- p.intersects(planetModel, bottomPlane, notablePoints, bottomPlanePoints, bounds, topPlane, leftPlane, rightPlane) ||
- p.intersects(planetModel, leftPlane, notablePoints, leftPlanePoints, bounds, rightPlane, topPlane, bottomPlane) ||
- p.intersects(planetModel, rightPlane, notablePoints, rightPlanePoints, bounds, leftPlane, topPlane, bottomPlane);
- }
-
- @Override
- public void getBounds(Bounds bounds) {
- super.getBounds(bounds);
- bounds.addHorizontalPlane(planetModel, topLat, topPlane, bottomPlane, leftPlane, rightPlane)
- .addVerticalPlane(planetModel, rightLon, rightPlane, topPlane, bottomPlane, leftPlane)
- .addHorizontalPlane(planetModel, bottomLat, bottomPlane, topPlane, leftPlane, rightPlane)
- .addVerticalPlane(planetModel, leftLon, leftPlane, topPlane, bottomPlane, rightPlane)
- .addPoint(ULHC).addPoint(URHC).addPoint(LLHC).addPoint(LRHC);
- }
-
- @Override
- public int getRelationship(final GeoShape path) {
- //System.err.println(this+" getrelationship with "+path);
- final int insideRectangle = isShapeInsideBBox(path);
- if (insideRectangle == SOME_INSIDE) {
- //System.err.println(" some inside");
- return OVERLAPS;
- }
-
- final boolean insideShape = path.isWithin(ULHC);
-
- if (insideRectangle == ALL_INSIDE && insideShape) {
- //System.err.println(" inside of each other");
- return OVERLAPS;
- }
-
- if (path.intersects(topPlane, topPlanePoints, bottomPlane, leftPlane, rightPlane) ||
- path.intersects(bottomPlane, bottomPlanePoints, topPlane, leftPlane, rightPlane) ||
- path.intersects(leftPlane, leftPlanePoints, topPlane, bottomPlane, rightPlane) ||
- path.intersects(rightPlane, rightPlanePoints, leftPlane, topPlane, bottomPlane)) {
- //System.err.println(" edges intersect");
- return OVERLAPS;
- }
-
- if (insideRectangle == ALL_INSIDE) {
- //System.err.println(" shape inside rectangle");
- return WITHIN;
- }
-
- if (insideShape) {
- //System.err.println(" shape contains rectangle");
- return CONTAINS;
- }
- //System.err.println(" disjoint");
- return DISJOINT;
- }
-
- @Override
- protected double outsideDistance(final DistanceStyle distanceStyle, final double x, final double y, final double z) {
- final double topDistance = distanceStyle.computeDistance(planetModel, topPlane, x,y,z, bottomPlane, leftPlane, rightPlane);
- final double bottomDistance = distanceStyle.computeDistance(planetModel, bottomPlane, x,y,z, topPlane, leftPlane, rightPlane);
- final double leftDistance = distanceStyle.computeDistance(planetModel, leftPlane, x,y,z, rightPlane, topPlane, bottomPlane);
- final double rightDistance = distanceStyle.computeDistance(planetModel, rightPlane, x,y,z, leftPlane, topPlane, bottomPlane);
-
- final double ULHCDistance = distanceStyle.computeDistance(ULHC, x,y,z);
- final double URHCDistance = distanceStyle.computeDistance(URHC, x,y,z);
- final double LRHCDistance = distanceStyle.computeDistance(LRHC, x,y,z);
- final double LLHCDistance = distanceStyle.computeDistance(LLHC, x,y,z);
-
- return Math.min(
- Math.min(
- Math.min(topDistance, bottomDistance),
- Math.min(leftDistance, rightDistance)),
- Math.min(
- Math.min(ULHCDistance, URHCDistance),
- Math.min(LRHCDistance, LLHCDistance)));
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof GeoRectangle))
- return false;
- GeoRectangle other = (GeoRectangle) o;
- return super.equals(other) && other.ULHC.equals(ULHC) && other.LRHC.equals(LRHC);
- }
-
- @Override
- public int hashCode() {
- int result = super.hashCode();
- result = 31 * result + ULHC.hashCode();
- result = 31 * result + LRHC.hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- return "GeoRectangle: {planetmodel="+planetModel+", toplat=" + topLat + "(" + topLat * 180.0 / Math.PI + "), bottomlat=" + bottomLat + "(" + bottomLat * 180.0 / Math.PI + "), leftlon=" + leftLon + "(" + leftLon * 180.0 / Math.PI + "), rightlon=" + rightLon + "(" + rightLon * 180.0 / Math.PI + ")}";
- }
-}
-
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f7f81c32/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoShape.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoShape.java b/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoShape.java
deleted file mode 100755
index 21cdba3..0000000
--- a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoShape.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.geo3d;
-
-/**
- * Generic shape. This describes methods that help GeoAreas figure out
- * how they interact with a shape, for the purposes of coming up with a
- * set of geo hash values.
- *
- * @lucene.experimental
- */
-public interface GeoShape extends Membership {
-
- /**
- * 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
- * is returned, but zero or two are also possible.
- */
- public GeoPoint[] getEdgePoints();
-
- /**
- * Assess whether a plane, within the provided bounds, intersects
- * 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.
- * Doing this can cause getRelationship() for most GeoBBox shapes to return
- * OVERLAPS rather than the more correct CONTAINS, but that cannot be
- * 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
- * bounding curves.
- * @param notablePoints represents the intersections of the plane with the supplied
- * bounds. These are used to disambiguate when two planes are identical and it needs
- * to be determined whether any points exist that fulfill all the bounds.
- * @param bounds are a set of bounds that define an area that an
- * intersection must be within in order to qualify (provided by a GeoArea).
- * @return true if there's such an intersection, false if not.
- */
- public boolean intersects(final Plane plane, final GeoPoint[] notablePoints, final Membership... bounds);
-
- /**
- * Compute bounds for the shape.
- *
- * @param bounds is the input bounds object.
- * The input object will be modified.
- */
- public void getBounds(final Bounds bounds);
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f7f81c32/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoSizeable.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoSizeable.java b/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoSizeable.java
deleted file mode 100755
index e8c0ebb..0000000
--- a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoSizeable.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.geo3d;
-
-/**
- * Some shapes can compute radii of a geocircle in which they are inscribed.
- *
- * @lucene.experimental
- */
-public interface GeoSizeable {
- /**
- * Returns the radius of a circle into which the GeoSizeable area can
- * be inscribed.
- *
- * @return the radius.
- */
- public double getRadius();
-
- /**
- * Returns the center of a circle into which the area will be inscribed.
- *
- * @return the center.
- */
- public GeoPoint getCenter();
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/f7f81c32/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoSouthLatitudeZone.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoSouthLatitudeZone.java b/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoSouthLatitudeZone.java
deleted file mode 100644
index 439dc1b..0000000
--- a/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoSouthLatitudeZone.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.geo3d;
-
-/**
- * This GeoBBox represents an area rectangle limited only in north latitude.
- *
- * @lucene.internal
- */
-public class GeoSouthLatitudeZone extends GeoBaseBBox {
- /** The top latitude of the zone */
- protected final double topLat;
- /** The cosine of the top latitude of the zone */
- protected final double cosTopLat;
- /** The top plane of the zone */
- protected final SidedPlane topPlane;
- /** An interior point of the zone */
- protected final GeoPoint interiorPoint;
- /** Notable points for the plane (none) */
- protected final static GeoPoint[] planePoints = new GeoPoint[0];
- /** A point on the top boundary */
- protected final GeoPoint topBoundaryPoint;
- /** Edge points; a reference to the topBoundaryPoint */
- protected final GeoPoint[] edgePoints;
-
- /** Constructor.
- *@param planetModel is the planet model.
- *@param topLat is the top latitude of the zone.
- */
- public GeoSouthLatitudeZone(final PlanetModel planetModel, final double topLat) {
- super(planetModel);
- this.topLat = topLat;
-
- final double sinTopLat = Math.sin(topLat);
- this.cosTopLat = Math.cos(topLat);
-
- // Compute an interior point. Pick one whose lat is between top and bottom.
- final double middleLat = (topLat - Math.PI * 0.5) * 0.5;
- final double sinMiddleLat = Math.sin(middleLat);
- this.interiorPoint = new GeoPoint(planetModel, sinMiddleLat, 0.0, Math.sqrt(1.0 - sinMiddleLat * sinMiddleLat), 1.0);
- this.topBoundaryPoint = new GeoPoint(planetModel, sinTopLat, 0.0, Math.sqrt(1.0 - sinTopLat * sinTopLat), 1.0);
-
- this.topPlane = new SidedPlane(interiorPoint, planetModel, sinTopLat);
-
- this.edgePoints = new GeoPoint[]{topBoundaryPoint};
- }
-
- @Override
- public GeoBBox expand(final double angle) {
- final double newTopLat = topLat + angle;
- final double newBottomLat = -Math.PI * 0.5;
- return GeoBBoxFactory.makeGeoBBox(planetModel, newTopLat, newBottomLat, -Math.PI, Math.PI);
- }
-
- @Override
- public boolean isWithin(final double x, final double y, final double z) {
- return topPlane.isWithin(x, y, z);
- }
-
- @Override
- public double getRadius() {
- // 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".
- if (topLat > 0.0)
- return Math.PI;
- double maxCosLat = cosTopLat;
- return maxCosLat * Math.PI;
- }
-
- /**
- * Returns the center of a circle into which the area will be inscribed.
- *
- * @return the center.
- */
- @Override
- public GeoPoint getCenter() {
- return interiorPoint;
- }
-
- @Override
- public GeoPoint[] getEdgePoints() {
- return edgePoints;
- }
-
- @Override
- public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
- return p.intersects(planetModel, topPlane, notablePoints, planePoints, bounds);
- }
-
- @Override
- public void getBounds(Bounds bounds) {
- super.getBounds(bounds);
- bounds
- .addHorizontalPlane(planetModel, topLat, topPlane);
- }
-
- @Override
- public int getRelationship(final GeoShape path) {
- final int insideRectangle = isShapeInsideBBox(path);
- if (insideRectangle == SOME_INSIDE)
- return OVERLAPS;
-
- final boolean insideShape = path.isWithin(topBoundaryPoint);
-
- if (insideRectangle == ALL_INSIDE && insideShape)
- return OVERLAPS;
-
- // Second, the shortcut of seeing whether endpoints are in/out is not going to
- // work with no area endpoints. So we rely entirely on intersections.
-
- if (path.intersects(topPlane, planePoints))
- return OVERLAPS;
-
- // There is another case for latitude zones only. This is when the boundaries of the shape all fit
- // within the zone, but the shape includes areas outside the zone crossing a pole.
- // In this case, the above "overlaps" check is insufficient. We also need to check a point on either boundary
- // whether it is within the shape. If both such points are within, then CONTAINS is the right answer. If
- // one such point is within, then OVERLAPS is the right answer.
-
- if (insideShape)
- return CONTAINS;
-
- if (insideRectangle == ALL_INSIDE)
- return WITHIN;
-
- return DISJOINT;
- }
-
- @Override
- protected double outsideDistance(final DistanceStyle distanceStyle, final double x, final double y, final double z) {
- return distanceStyle.computeDistance(planetModel, topPlane, x,y,z);
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof GeoSouthLatitudeZone))
- return false;
- GeoSouthLatitudeZone other = (GeoSouthLatitudeZone) o;
- return super.equals(other) && other.topBoundaryPoint.equals(topBoundaryPoint);
- }
-
- @Override
- public int hashCode() {
- int result = super.hashCode();
- result = 31 * result + topBoundaryPoint.hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- return "GeoSouthLatitudeZone: {planetmodel="+planetModel+", toplat=" + topLat + "(" + topLat * 180.0 / Math.PI + ")}";
- }
-}
-