You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by iv...@apache.org on 2018/04/04 11:39:35 UTC
lucene-solr:branch_6x: LUCENE-8236: Filter duplicated points when
creating GeoPath shapes to avoid creation of bogus planes.
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 99e0694ed -> feacd428f
LUCENE-8236: Filter duplicated points when creating GeoPath shapes to avoid creation of bogus planes.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/feacd428
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/feacd428
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/feacd428
Branch: refs/heads/branch_6x
Commit: feacd428ff1d4e2810e2eb5224cbcf15078eaf34
Parents: 99e0694
Author: Ignacio Vera <iv...@apache.org>
Authored: Wed Apr 4 13:37:18 2018 +0200
Committer: Ignacio Vera <iv...@apache.org>
Committed: Wed Apr 4 13:37:18 2018 +0200
----------------------------------------------------------------------
lucene/CHANGES.txt | 3 +++
.../lucene/spatial3d/geom/GeoPathFactory.java | 22 +++++++++++++++++--
.../lucene/spatial3d/geom/GeoPathTest.java | 23 ++++++++++++++++++++
3 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/feacd428/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index d0e2e8a..534f3df 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -43,6 +43,9 @@ New Features
Bug Fixes
+* LUCENE-8236: Filter duplicated points when creating GeoPath shapes
+ to avoid creation of bogus planes. (Ignacio Vera)
+
* LUCENE-8234: Fixed bug in how spatial relationship is computed for
GeoStandardCircle when it covers the whole world. (Ignacio Vera)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/feacd428/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPathFactory.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPathFactory.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPathFactory.java
index 2ca132f..6389f57 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPathFactory.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPathFactory.java
@@ -16,6 +16,9 @@
*/
package org.apache.lucene.spatial3d.geom;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Class which constructs a GeoPath representing an arbitrary path.
*
@@ -34,9 +37,24 @@ public class GeoPathFactory {
*/
public static GeoPath makeGeoPath(final PlanetModel planetModel, final double maxCutoffAngle, final GeoPoint[] pathPoints) {
if (maxCutoffAngle < Vector.MINIMUM_ANGULAR_RESOLUTION) {
- return new GeoDegeneratePath(planetModel, pathPoints);
+ return new GeoDegeneratePath(planetModel, filterPoints(pathPoints));
+ }
+ return new GeoStandardPath(planetModel, maxCutoffAngle, filterPoints(pathPoints));
+ }
+
+ /** Filter duplicate points.
+ * @param pathPoints with the arras of points.
+ * @return the filtered array.
+ */
+ private static GeoPoint[] filterPoints(final GeoPoint[] pathPoints) {
+ final List<GeoPoint> noIdenticalPoints = new ArrayList<>(pathPoints.length);
+ for (int i = 0; i < pathPoints.length - 1; i++) {
+ if (!pathPoints[i].isNumericallyIdentical(pathPoints[i + 1])) {
+ noIdenticalPoints.add(pathPoints[i]);
+ }
}
- return new GeoStandardPath(planetModel, maxCutoffAngle, pathPoints);
+ noIdenticalPoints.add(pathPoints[pathPoints.length - 1]);
+ return noIdenticalPoints.toArray(new GeoPoint[noIdenticalPoints.size()]);
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/feacd428/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java
index f6d14f2..93f90f4 100755
--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java
+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPathTest.java
@@ -379,4 +379,27 @@ public class GeoPathTest {
}
+ @Test
+ public void testIdenticalPoints() {
+ PlanetModel planetModel = PlanetModel.WGS84;
+ GeoPoint point1 = new GeoPoint(planetModel, 1.5707963267948963, -2.4818290647609542E-148);
+ GeoPoint point2 = new GeoPoint(planetModel, 1.570796326794895, -3.5E-323);
+ GeoPoint point3 = new GeoPoint(planetModel,4.4E-323, -3.1415926535897896);
+ GeoPath path = GeoPathFactory.makeGeoPath(planetModel, 0, new GeoPoint[] {point1, point2, point3});
+ GeoPoint point = new GeoPoint(planetModel, -1.5707963267948952,2.369064805649877E-284);
+ //If not filtered the point is wrongly in set
+ assertFalse(path.isWithin(point));
+ //If not filtered it throws error
+ path = GeoPathFactory.makeGeoPath(planetModel, 1e-6, new GeoPoint[] {point1, point2, point3});
+ assertFalse(path.isWithin(point));
+
+ GeoPoint point4 = new GeoPoint(planetModel, 1.5, 0);
+ GeoPoint point5 = new GeoPoint(planetModel, 1.5, 0);
+ GeoPoint point6 = new GeoPoint(planetModel,4.4E-323, -3.1415926535897896);
+ //If not filtered creates a degenerated Vector
+ path = GeoPathFactory.makeGeoPath(planetModel, 0, new GeoPoint[] {point4, point5, point6});
+ path = GeoPathFactory.makeGeoPath(planetModel, 0.5, new GeoPoint[] {point4, point5, point6});
+
+ }
+
}