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/03/18 20:17:33 UTC

lucene-solr:branch_6x: LUCENE-8214: Do a better job of selecting the test point for a geocomplexpolygon.

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 50724b78f -> 1c0e82abc


LUCENE-8214: Do a better job of selecting the test point for a geocomplexpolygon.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/1c0e82ab
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/1c0e82ab
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/1c0e82ab

Branch: refs/heads/branch_6x
Commit: 1c0e82abc3de0c0086529370f9ff2134f060ee65
Parents: 50724b7
Author: Karl Wright <Da...@gmail.com>
Authored: Sun Mar 18 16:12:29 2018 -0400
Committer: Karl Wright <Da...@gmail.com>
Committed: Sun Mar 18 16:17:26 2018 -0400

----------------------------------------------------------------------
 .../lucene/spatial3d/geom/GeoPolygonFactory.java    | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1c0e82ab/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 8105b80..90ab75f 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
@@ -165,7 +165,7 @@ public class GeoPolygonFactory {
     }
 
     //First approximation to find a point
-    final GeoPoint centerOfMass = getCenterOfMass(filteredPointList);
+    final GeoPoint centerOfMass = getCenterOfMass(planetModel, filteredPointList);
     final Boolean isCenterOfMassInside = isInsidePolygon(centerOfMass, filteredPointList);
     if (isCenterOfMassInside != null) {
       return generateGeoPolygon(planetModel, filteredPointList, holes, centerOfMass, isCenterOfMassInside);
@@ -192,7 +192,7 @@ public class GeoPolygonFactory {
     throw new IllegalArgumentException("cannot find a point that is inside the polygon "+filteredPointList);
   }
 
-  private static GeoPoint getCenterOfMass(List<GeoPoint> points) {
+  private static GeoPoint getCenterOfMass(PlanetModel planetModel, List<GeoPoint> points) {
     double x = 0;
     double y = 0;
     double z = 0;
@@ -202,7 +202,7 @@ public class GeoPolygonFactory {
       y += point.y;
       z += point.z;
     }
-    return new GeoPoint(x / points.size(), y / points.size(), z / points.size());
+    return planetModel.createSurfacePoint(x / points.size(), y / points.size(), z / points.size());
   }
   
   /** Use this class to specify a polygon with associated holes.
@@ -268,6 +268,16 @@ public class GeoPolygonFactory {
     if (testPointShape == null) {
       throw new IllegalArgumentException("couldn't find a non-degenerate polygon for in-set determination");
     }
+
+    final GeoPoint centerOfMass = getCenterOfMass(planetModel, testPointShape.points);
+    final Boolean isCenterOfMassInside = isInsidePolygon(centerOfMass, testPointShape.points);
+    if (isCenterOfMassInside != null) {
+      if (isCenterOfMassInside == testPointShape.poleMustBeInside) {
+        return new GeoComplexPolygon(planetModel, pointsList, centerOfMass, isCenterOfMassInside);
+      } else {
+        return new GeoComplexPolygon(planetModel, pointsList, new GeoPoint(-centerOfMass.x, -centerOfMass.y, -centerOfMass.z), !isCenterOfMassInside);
+      }
+    }
     
     // Create a random number generator.  Effectively this furnishes us with a repeatable sequence
     // of points to use for poles.