From commits-return-100031-archive-asf-public=cust-asf.ponee.io@lucene.apache.org Wed Apr 4 13:39:36 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 1CD8F18064F for ; Wed, 4 Apr 2018 13:39:35 +0200 (CEST) Received: (qmail 17286 invoked by uid 500); 4 Apr 2018 11:39:35 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 17277 invoked by uid 99); 4 Apr 2018 11:39:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Apr 2018 11:39:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0CAD0F17C8; Wed, 4 Apr 2018 11:39:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ivera@apache.org To: commits@lucene.apache.org Message-Id: <9b3656c209604813913d36c7b77c19dd@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: lucene-solr:branch_6x: LUCENE-8236: Filter duplicated points when creating GeoPath shapes to avoid creation of bogus planes. Date: Wed, 4 Apr 2018 11:39:35 +0000 (UTC) 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 Authored: Wed Apr 4 13:37:18 2018 +0200 Committer: Ignacio Vera 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 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}); + + } + }