You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2015/08/13 11:19:12 UTC
svn commit: r1695663 - in
/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene:
bkdtree3d/PointInGeo3DShapeQuery.java geo3d/BaseXYZSolid.java
geo3d/GeoAreaFactory.java geo3d/XYZSolid.java
Author: mikemccand
Date: Thu Aug 13 09:19:11 2015
New Revision: 1695663
URL: http://svn.apache.org/r1695663
Log:
LUCENE-6699: handle degenerate solids
Added:
lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/BaseXYZSolid.java (with props)
Modified:
lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java
lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoAreaFactory.java
lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/XYZSolid.java
Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java?rev=1695663&r1=1695662&r2=1695663&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/bkdtree3d/PointInGeo3DShapeQuery.java Thu Aug 13 09:19:11 2015
@@ -20,7 +20,7 @@ package org.apache.lucene.bkdtree3d;
import org.apache.lucene.geo3d.GeoArea;
import org.apache.lucene.geo3d.GeoShape;
import org.apache.lucene.geo3d.PlanetModel;
-import org.apache.lucene.geo3d.XYZSolid;
+import org.apache.lucene.geo3d.GeoAreaFactory;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
@@ -119,7 +119,7 @@ public class PointInGeo3DShapeQuery exte
double zMin = Geo3DDocValuesFormat.decodeValue(zMinEnc);
double zMax = Geo3DDocValuesFormat.decodeValue(zMaxEnc);
- GeoArea xyzSolid = new XYZSolid(planetModel, xMin, xMax, yMin, yMax, zMin, zMax);
+ GeoArea xyzSolid = GeoAreaFactory.makeGeoArea(planetModel, xMin, xMax, yMin, yMax, zMin, zMax);
// nocommit untested!
switch(xyzSolid.getRelationship(shape)) {
Added: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/BaseXYZSolid.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/BaseXYZSolid.java?rev=1695663&view=auto
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/BaseXYZSolid.java (added)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/BaseXYZSolid.java Thu Aug 13 09:19:11 2015
@@ -0,0 +1,179 @@
+package org.apache.lucene.geo3d;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Base class of a family of 3D rectangles, bounded on six sides by X,Y,Z limits
+ *
+ * @lucene.internal
+ */
+public abstract class BaseXYZSolid extends BasePlanetObject implements GeoArea {
+
+ /** Unit vector in x */
+ protected static final Vector xUnitVector = new Vector(1.0, 0.0, 0.0);
+ /** Unit vector in y */
+ protected static final Vector yUnitVector = new Vector(0.0, 1.0, 0.0);
+ /** Unit vector in z */
+ protected static final Vector zUnitVector = new Vector(0.0, 0.0, 1.0);
+
+ /** Vertical plane normal to x unit vector passing through origin */
+ protected static final Plane xVerticalPlane = new Plane(0.0, 1.0, 0.0, 0.0);
+ /** Vertical plane normal to y unit vector passing through origin */
+ protected static final Plane yVerticalPlane = new Plane(1.0, 0.0, 0.0, 0.0);
+
+ /**
+ * Base solid constructor.
+ *@param planetModel is the planet model.
+ */
+ public BaseXYZSolid(final PlanetModel planetModel) {
+ super(planetModel);
+ }
+
+ /** Construct a single array from a number of individual arrays.
+ * @param pointArrays is the array of point arrays.
+ * @return the single unified array.
+ */
+ protected static GeoPoint[] glueTogether(final GeoPoint[]... pointArrays) {
+ int count = 0;
+ for (final GeoPoint[] pointArray : pointArrays) {
+ count += pointArray.length;
+ }
+ final GeoPoint[] rval = new GeoPoint[count];
+ count = 0;
+ for (final GeoPoint[] pointArray : pointArrays) {
+ for (final GeoPoint point : pointArray) {
+ rval[count++] = point;
+ }
+ }
+ return rval;
+ }
+
+ /** Find the longest set of point solutions.
+ * @param pointArrays is the array of point arrays.
+ * @return one of the longest sets.
+ */
+ protected static GeoPoint[] findLargestSolution(final GeoPoint[]... pointArrays) {
+ GeoPoint[] rval = null;
+ for (final GeoPoint[] pointArray : pointArrays) {
+ if (rval == null || rval.length < pointArray.length) {
+ rval = pointArray;
+ }
+ }
+ return rval;
+ }
+
+ @Override
+ public boolean isWithin(final Vector point) {
+ return isWithin(point.x, point.y, point.z);
+ }
+
+ @Override
+ public abstract boolean isWithin(final double x, final double y, final double z);
+
+ // Signals for relationship of edge points to shape
+
+ /** All edgepoints inside shape */
+ protected final static int ALL_INSIDE = 0;
+ /** Some edgepoints inside shape */
+ protected final static int SOME_INSIDE = 1;
+ /** No edgepoints inside shape */
+ protected final static int NONE_INSIDE = 2;
+ /** No edgepoints at all (means a shape that is the whole world) */
+ protected final static int NO_EDGEPOINTS = 3;
+
+ /** Determine the relationship between this area and the provided
+ * shape's edgepoints.
+ *@param path is the shape.
+ *@return the relationship.
+ */
+ protected int isShapeInsideArea(final GeoShape path) {
+ final GeoPoint[] pathPoints = path.getEdgePoints();
+ if (pathPoints.length == 0)
+ return NO_EDGEPOINTS;
+ boolean foundOutside = false;
+ boolean foundInside = false;
+ for (final GeoPoint p : pathPoints) {
+ if (isWithin(p)) {
+ foundInside = true;
+ } else {
+ foundOutside = true;
+ }
+ if (foundInside && foundOutside) {
+ return SOME_INSIDE;
+ }
+ }
+ if (!foundInside && !foundOutside)
+ return NONE_INSIDE;
+ if (foundInside && !foundOutside)
+ return ALL_INSIDE;
+ if (foundOutside && !foundInside)
+ return NONE_INSIDE;
+ return SOME_INSIDE;
+ }
+
+ /** Determine the relationship between a shape and this area's
+ * edgepoints.
+ *@param path is the shape.
+ *@return the relationship.
+ */
+ protected int isAreaInsideShape(final GeoShape path) {
+ final GeoPoint[] edgePoints = getEdgePoints();
+ if (edgePoints.length == 0) {
+ return NO_EDGEPOINTS;
+ }
+ boolean foundOutside = false;
+ boolean foundInside = false;
+ for (final GeoPoint p : edgePoints) {
+ if (path.isWithin(p)) {
+ foundInside = true;
+ } else {
+ foundOutside = true;
+ }
+ if (foundInside && foundOutside) {
+ return SOME_INSIDE;
+ }
+ }
+ if (!foundInside && !foundOutside)
+ return NONE_INSIDE;
+ if (foundInside && !foundOutside)
+ return ALL_INSIDE;
+ if (foundOutside && !foundInside)
+ return NONE_INSIDE;
+ return SOME_INSIDE;
+ }
+
+ /** Get the edge points for this shape.
+ *@return the edge points.
+ */
+ protected abstract GeoPoint[] getEdgePoints();
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof BaseXYZSolid))
+ return false;
+ BaseXYZSolid other = (BaseXYZSolid) o;
+ return super.equals(other);
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+}
+
Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoAreaFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoAreaFactory.java?rev=1695663&r1=1695662&r2=1695663&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoAreaFactory.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/GeoAreaFactory.java Thu Aug 13 09:19:11 2015
@@ -28,7 +28,7 @@ public class GeoAreaFactory {
/**
* Create a GeoArea of the right kind given the specified bounds.
- *
+ * @param planetModel is the planet model
* @param topLat is the top latitude
* @param bottomLat is the bottom latitude
* @param leftLon is the left longitude
@@ -39,4 +39,19 @@ public class GeoAreaFactory {
return GeoBBoxFactory.makeGeoBBox(planetModel, topLat, bottomLat, leftLon, rightLon);
}
+ /**
+ * Create a GeoArea of the right kind given (x,y,z) bounds.
+ * @param planetModel is the planet model
+ * @param minX is the min X boundary
+ * @param maxX is the max X boundary
+ * @param minY is the min Y boundary
+ * @param maxY is the max Y boundary
+ * @param minZ is the min Z boundary
+ * @param maxZ is the max Z boundary
+ */
+ public static GeoArea makeGeoArea(final PlanetModel planetModel, final double minX, final double maxX, final double minY, final double maxY, final double minZ, final double maxZ) {
+ // nocommit - handle degenerate cases explicitly
+ return new XYZSolid(planetModel, minX, maxY, minY, maxY, minZ, maxZ);
+ }
+
}
Modified: lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/XYZSolid.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/XYZSolid.java?rev=1695663&r1=1695662&r2=1695663&view=diff
==============================================================================
--- lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/XYZSolid.java (original)
+++ lucene/dev/branches/lucene6699/lucene/spatial3d/src/java/org/apache/lucene/geo3d/XYZSolid.java Thu Aug 13 09:19:11 2015
@@ -22,20 +22,8 @@ package org.apache.lucene.geo3d;
*
* @lucene.internal
*/
-public class XYZSolid extends BasePlanetObject implements GeoArea {
+public class XYZSolid extends BaseXYZSolid {
- /** Unit vector in x */
- protected static final Vector xUnitVector = new Vector(1.0, 0.0, 0.0);
- /** Unit vector in y */
- protected static final Vector yUnitVector = new Vector(0.0, 1.0, 0.0);
- /** Unit vector in z */
- protected static final Vector zUnitVector = new Vector(0.0, 0.0, 1.0);
-
- /** Vertical plane normal to x unit vector passing through origin */
- protected static final Plane xVerticalPlane = new Plane(0.0, 1.0, 0.0, 0.0);
- /** Vertical plane normal to y unit vector passing through origin */
- protected static final Plane yVerticalPlane = new Plane(1.0, 0.0, 0.0, 0.0);
-
/** Whole world? */
protected final boolean isWholeWorld;
/** Min-X plane */
@@ -250,42 +238,9 @@ public class XYZSolid extends BasePlanet
}
}
- /** Construct a single array from a number of individual arrays.
- * @param pointArrays is the array of point arrays.
- * @return the single unified array.
- */
- protected static GeoPoint[] glueTogether(final GeoPoint[]... pointArrays) {
- int count = 0;
- for (final GeoPoint[] pointArray : pointArrays) {
- count += pointArray.length;
- }
- final GeoPoint[] rval = new GeoPoint[count];
- count = 0;
- for (final GeoPoint[] pointArray : pointArrays) {
- for (final GeoPoint point : pointArray) {
- rval[count++] = point;
- }
- }
- return rval;
- }
-
- /** Find the longest set of point solutions.
- * @param pointArrays is the array of point arrays.
- * @return one of the longest sets.
- */
- protected static GeoPoint[] findLargestSolution(final GeoPoint[]... pointArrays) {
- GeoPoint[] rval = null;
- for (final GeoPoint[] pointArray : pointArrays) {
- if (rval == null || rval.length < pointArray.length) {
- rval = pointArray;
- }
- }
- return rval;
- }
-
@Override
- public boolean isWithin(final Vector point) {
- return isWithin(point.x, point.y, point.z);
+ protected GeoPoint[] getEdgePoints() {
+ return edgePoints;
}
@Override
@@ -301,77 +256,6 @@ public class XYZSolid extends BasePlanet
maxZPlane.isWithin(x, y, z);
}
- // Signals for relationship of edge points to shape
-
- /** All edgepoints inside shape */
- protected final static int ALL_INSIDE = 0;
- /** Some edgepoints inside shape */
- protected final static int SOME_INSIDE = 1;
- /** No edgepoints inside shape */
- protected final static int NONE_INSIDE = 2;
- /** No edgepoints at all (means a shape that is the whole world) */
- protected final static int NO_EDGEPOINTS = 3;
-
- /** Determine the relationship between this area and the provided
- * shape's edgepoints.
- *@param path is the shape.
- *@return the relationship.
- */
- protected int isShapeInsideArea(final GeoShape path) {
- final GeoPoint[] pathPoints = path.getEdgePoints();
- if (pathPoints.length == 0)
- return NO_EDGEPOINTS;
- boolean foundOutside = false;
- boolean foundInside = false;
- for (final GeoPoint p : pathPoints) {
- if (isWithin(p)) {
- foundInside = true;
- } else {
- foundOutside = true;
- }
- if (foundInside && foundOutside) {
- return SOME_INSIDE;
- }
- }
- if (!foundInside && !foundOutside)
- return NONE_INSIDE;
- if (foundInside && !foundOutside)
- return ALL_INSIDE;
- if (foundOutside && !foundInside)
- return NONE_INSIDE;
- return SOME_INSIDE;
- }
-
- /** Determine the relationship between a shape and this area's
- * edgepoints.
- *@param path is the shape.
- *@return the relationship.
- */
- protected int isAreaInsideShape(final GeoShape path) {
- if (edgePoints.length == 0) {
- return NO_EDGEPOINTS;
- }
- boolean foundOutside = false;
- boolean foundInside = false;
- for (final GeoPoint p : edgePoints) {
- if (path.isWithin(p)) {
- foundInside = true;
- } else {
- foundOutside = true;
- }
- if (foundInside && foundOutside) {
- return SOME_INSIDE;
- }
- }
- if (!foundInside && !foundOutside)
- return NONE_INSIDE;
- if (foundInside && !foundOutside)
- return ALL_INSIDE;
- if (foundOutside && !foundInside)
- return NONE_INSIDE;
- return SOME_INSIDE;
- }
-
@Override
public int getRelationship(final GeoShape path) {
if (isWholeWorld) {