From commits-return-98662-archive-asf-public=cust-asf.ponee.io@lucene.apache.org Thu Jan 25 16:33:56 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id CA11A180651 for ; Thu, 25 Jan 2018 16:33:56 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id BA4DC160C3D; Thu, 25 Jan 2018 15:33:56 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0CE85160C13 for ; Thu, 25 Jan 2018 16:33:55 +0100 (CET) Received: (qmail 39812 invoked by uid 500); 25 Jan 2018 15:33:55 -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 39803 invoked by uid 99); 25 Jan 2018 15:33:55 -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; Thu, 25 Jan 2018 15:33:55 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E5CA5E0287; Thu, 25 Jan 2018 15:33:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kwright@apache.org To: commits@lucene.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: lucene-solr:master: LUCENE-8139: Optimize polygon interior point discovery to check center of mass first. Committed on behalf of Ignacio Vera. Date: Thu, 25 Jan 2018 15:33:54 +0000 (UTC) Repository: lucene-solr Updated Branches: refs/heads/master 776899b4e -> c10ba5a6d LUCENE-8139: Optimize polygon interior point discovery to check center of mass first. Committed on behalf of Ignacio Vera. Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/c10ba5a6 Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/c10ba5a6 Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/c10ba5a6 Branch: refs/heads/master Commit: c10ba5a6d9497a6f716ccc1c5b0f789a967e7fad Parents: 776899b Author: Karl Wright Authored: Thu Jan 25 10:33:42 2018 -0500 Committer: Karl Wright Committed: Thu Jan 25 10:33:42 2018 -0500 ---------------------------------------------------------------------- .../spatial3d/geom/GeoPolygonFactory.java | 21 ++++++++++++++++++++ .../lucene/spatial3d/geom/RandomPlaneTest.java | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c10ba5a6/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java ---------------------------------------------------------------------- diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java index f599716..d272c86 100755 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoPolygonFactory.java @@ -162,6 +162,14 @@ public class GeoPolygonFactory { if (filteredPointList == null) { return null; } + + //First approximation to find a point + final GeoPoint centerOfMass = getCenterOfMass(filteredPointList); + final Boolean isCenterOfMassInside = isInsidePolygon(centerOfMass, filteredPointList); + if (isCenterOfMassInside != null) { + return generateGeoPolygon(planetModel, filteredPointList, holes, centerOfMass, isCenterOfMassInside); + } + //System.err.println("points="+pointList); // Create a random number generator. Effectively this furnishes us with a repeatable sequence // of points to use for poles. @@ -182,6 +190,19 @@ public class GeoPolygonFactory { } throw new IllegalArgumentException("cannot find a point that is inside the polygon "+filteredPointList); } + + private static GeoPoint getCenterOfMass(List points) { + double x = 0; + double y = 0; + double z = 0; + //get center of mass + for (GeoPoint point : points) { + x += point.x; + y += point.y; + z += point.z; + } + return new GeoPoint(x / points.size(), y / points.size(), z / points.size()); + } /** Use this class to specify a polygon with associated holes. */ http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c10ba5a6/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/RandomPlaneTest.java ---------------------------------------------------------------------- diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/RandomPlaneTest.java b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/RandomPlaneTest.java index 1e19194..42f09e3 100644 --- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/RandomPlaneTest.java +++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/RandomPlaneTest.java @@ -51,7 +51,7 @@ public class RandomPlaneTest extends RandomGeo3dShapeGenerator { } } - /* + @Test @Repeat(iterations = 10) public void testPolygonAccuracy() { @@ -70,5 +70,5 @@ public class RandomPlaneTest extends RandomGeo3dShapeGenerator { } } - */ + }