lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject lucene-solr:master: LUCENE-7140: add spatial3d PlanetModel.bisection method
Date Fri, 25 Mar 2016 12:20:11 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master b8feb9227 -> 626bed8bc


LUCENE-7140: add spatial3d PlanetModel.bisection method


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

Branch: refs/heads/master
Commit: 626bed8bc6e225bdba2f95b5a99f2e8b87d3d382
Parents: b8feb92
Author: Mike McCandless <mikemccand@apache.org>
Authored: Fri Mar 25 08:21:44 2016 -0400
Committer: Mike McCandless <mikemccand@apache.org>
Committed: Fri Mar 25 08:21:44 2016 -0400

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  3 +++
 .../lucene/spatial3d/geom/PlanetModel.java      | 24 ++++++++++++++++++++
 .../lucene/spatial3d/geom/GeoPointTest.java     | 19 ++++++++++++++++
 3 files changed, 46 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/626bed8b/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 1e34413..25b014d 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -13,6 +13,9 @@ New Features
 * LUCENE-7099: Add LatLonPoint.newDistanceSort to the sandbox's
   LatLonPoint. (Robert Muir)
 
+* LUCENE-7140: Add PlanetModel.bisection to spatial3d (Karl Wright via
+  Mike McCandless)
+
 Optimizations
 
 * LUCENE-7071: Reduce bytes copying in OfflineSorter, giving ~10%

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/626bed8b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java
index b905b56..9f53851 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java
@@ -188,6 +188,30 @@ public class PlanetModel {
     return (x * x + y * y) * inverseAb * inverseAb + z * z * inverseC * inverseC - 1.0 >
Vector.MINIMUM_RESOLUTION;
   }
   
+  /** Compute a GeoPoint that's a bisection between two other GeoPoints.
+   * @param pt1 is the first point.
+   * @param pt2 is the second point.
+   * @return the bisection point, or null if a unique one cannot be found.
+   */
+  public GeoPoint bisection(final GeoPoint pt1, final GeoPoint pt2) {
+    final double A0 = (pt1.x + pt2.x) * 0.5;
+    final double B0 = (pt1.y + pt2.y) * 0.5;
+    final double C0 = (pt1.z + pt2.z) * 0.5;
+      
+    final double denom = inverseAbSquared * A0 * A0 +
+      inverseAbSquared * B0 * B0 +
+      inverseCSquared * C0 * C0;
+          
+    if(denom < Vector.MINIMUM_RESOLUTION) {
+      // Bisection is undefined
+      return null;
+    }
+      
+    final double t = Math.sqrt(1.0 / denom);
+      
+    return new GeoPoint(t * A0, t * B0, t * C0);
+  }
+  
   /** Compute surface distance between two points.
    * @param pt1 is the first point.
    * @param pt2 is the second point.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/626bed8b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPointTest.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPointTest.java
b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPointTest.java
index 6df35c5..d738110 100644
--- a/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPointTest.java
+++ b/lucene/spatial3d/src/test/org/apache/lucene/spatial3d/geom/GeoPointTest.java
@@ -83,6 +83,25 @@ public class GeoPointTest extends LuceneTestCase {
     }
   }
 
+  @Test
+  public void testBisection() {
+    final int times = atLeast(100);
+    for (int i = 0; i < times; i++) {
+      final double p1Lat = (randomFloat() * 180.0 - 90.0) * DEGREES_TO_RADIANS;
+      final double p1Lon = (randomFloat() * 360.0 - 180.0) * DEGREES_TO_RADIANS;
+      final double p2Lat = (randomFloat() * 180.0 - 90.0) * DEGREES_TO_RADIANS;
+      final double p2Lon = (randomFloat() * 360.0 - 180.0) * DEGREES_TO_RADIANS;
+      final GeoPoint p1 = new GeoPoint(PlanetModel.WGS84, p1Lat, p1Lon);
+      final GeoPoint p2 = new GeoPoint(PlanetModel.WGS84, p2Lat, p2Lon);
+      final GeoPoint pMid = PlanetModel.WGS84.bisection(p1, p2);
+      if (pMid != null) {
+        final double arcDistance = p1.arcDistance(p2);
+        final double sum = pMid.arcDistance(p1) + pMid.arcDistance(p2);
+        assertEquals(arcDistance, sum, 1e-6);
+      }
+    }
+  }
+  
   @Test(expected = IllegalArgumentException.class)
   public void testBadLatLon() {
     new GeoPoint(PlanetModel.SPHERE, 50.0, 32.2);


Mime
View raw message