You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kw...@apache.org on 2018/01/25 15:34:45 UTC

lucene-solr:branch_6x: LUCENE-8139: Optimize polygon interior point discovery to check center of mass first. Committed on behalf of Ignacio Vera.

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 243252909 -> 930ee498f


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/930ee498
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/930ee498
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/930ee498

Branch: refs/heads/branch_6x
Commit: 930ee498fbd6648f36db2abe20b3d611aa036579
Parents: 2432529
Author: Karl Wright <Da...@gmail.com>
Authored: Thu Jan 25 10:33:42 2018 -0500
Committer: Karl Wright <Da...@gmail.com>
Committed: Thu Jan 25 10:34:38 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/930ee498/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<GeoPoint> 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/930ee498/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 {
 
     }
   }
-  */
+
 }