You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2017/09/02 15:42:33 UTC

[02/50] lucene-solr:feature/autoscaling: LUCENE-7942: Add aggregateDistances() method to DistanceStyle, and use it in GeoStandardPath to aggregate distances from segment to segment.

LUCENE-7942: Add aggregateDistances() method to DistanceStyle, and use it in GeoStandardPath to aggregate distances from segment to segment.


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

Branch: refs/heads/feature/autoscaling
Commit: 92c94d8ca20191bb72c2da87767970632f14213b
Parents: d640c92
Author: Karl Wright <Da...@gmail.com>
Authored: Mon Aug 28 01:49:53 2017 -0400
Committer: Karl Wright <Da...@gmail.com>
Committed: Mon Aug 28 01:49:53 2017 -0400

----------------------------------------------------------------------
 .../org/apache/lucene/spatial3d/geom/DistanceStyle.java   | 10 ++++++++++
 .../org/apache/lucene/spatial3d/geom/GeoStandardPath.java | 10 +++++-----
 .../lucene/spatial3d/geom/LinearSquaredDistance.java      |  6 ++++++
 .../lucene/spatial3d/geom/NormalSquaredDistance.java      |  6 ++++++
 4 files changed, 27 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/92c94d8c/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/DistanceStyle.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/DistanceStyle.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/DistanceStyle.java
index 3657fe9..1dccffb 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/DistanceStyle.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/DistanceStyle.java
@@ -78,6 +78,16 @@ public interface DistanceStyle {
    */
   public double computeDistance(final PlanetModel planetModel, final Plane plane, final double x, final double y, final double z, final Membership... bounds);
 
+  /** Aggregate two distances together to produce a "sum".
+   * This is usually just an addition operation, but in the case of squared distances it is more complex.
+   * @param distance1 is the first distance.
+   * @param distance2 is the second distance.
+   * @return the combined distance.
+   */
+  public default double aggregateDistances(final double distance1, final double distance2) {
+    return distance1 + distance2;
+  }
+  
   // The following methods are used to go from a distance value back to something
   // that can be used to construct a constrained shape.
   

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/92c94d8c/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java
index c30414c..cde1c49 100755
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java
@@ -223,8 +223,8 @@ class GeoStandardPath extends GeoBasePath {
     for (PathSegment segment : segments) {
       double distance = segment.pathDistance(planetModel, distanceStyle, x,y,z);
       if (distance != Double.POSITIVE_INFINITY)
-        return currentDistance + distance;
-      currentDistance += segment.fullPathDistance(distanceStyle);
+        return distanceStyle.aggregateDistances(currentDistance, distance);
+      currentDistance = distanceStyle.aggregateDistances(currentDistance, segment.fullPathDistance(distanceStyle));
     }
 
     int segmentIndex = 0;
@@ -232,9 +232,9 @@ class GeoStandardPath extends GeoBasePath {
     for (SegmentEndpoint endpoint : endPoints) {
       double distance = endpoint.pathDistance(distanceStyle, x, y, z);
       if (distance != Double.POSITIVE_INFINITY)
-        return currentDistance + distance;
+        return distanceStyle.aggregateDistances(currentDistance, distance);
       if (segmentIndex < segments.size())
-        currentDistance += segments.get(segmentIndex++).fullPathDistance(distanceStyle);
+        currentDistance = distanceStyle.aggregateDistances(currentDistance, segments.get(segmentIndex++).fullPathDistance(distanceStyle));
     }
 
     return Double.POSITIVE_INFINITY;
@@ -807,7 +807,7 @@ class GeoStandardPath extends GeoBasePath {
         else
           throw new RuntimeException("Can't find world intersection for point x="+x+" y="+y+" z="+z);
       }
-      return distanceStyle.computeDistance(thePoint, x, y, z) + distanceStyle.computeDistance(start, thePoint.x, thePoint.y, thePoint.z);
+      return distanceStyle.aggregateDistances(distanceStyle.computeDistance(thePoint, x, y, z), distanceStyle.computeDistance(start, thePoint.x, thePoint.y, thePoint.z));
     }
 
     /** Compute external distance.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/92c94d8c/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/LinearSquaredDistance.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/LinearSquaredDistance.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/LinearSquaredDistance.java
index 4b26f8e..c1800f6 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/LinearSquaredDistance.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/LinearSquaredDistance.java
@@ -52,6 +52,12 @@ public class LinearSquaredDistance implements DistanceStyle {
   }
 
   @Override
+  public double aggregateDistances(final double distance1, final double distance2) {
+    final double linearDistance = Math.sqrt(distance1) + Math.sqrt(distance2);
+    return linearDistance * linearDistance;
+  }
+
+  @Override
   public GeoPoint[] findDistancePoints(final PlanetModel planetModel, final double distanceValue, final GeoPoint startPoint, final Plane plane, final Membership... bounds) {
     throw new IllegalStateException("Reverse mapping not implemented for this distance metric");
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/92c94d8c/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/NormalSquaredDistance.java
----------------------------------------------------------------------
diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/NormalSquaredDistance.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/NormalSquaredDistance.java
index 428e042..3a68cc9 100644
--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/NormalSquaredDistance.java
+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/NormalSquaredDistance.java
@@ -52,6 +52,12 @@ public class NormalSquaredDistance implements DistanceStyle {
   }
 
   @Override
+  public double aggregateDistances(final double distance1, final double distance2) {
+    final double normalDistance = Math.sqrt(distance1) + Math.sqrt(distance2);
+    return normalDistance * normalDistance;
+  }
+
+  @Override
   public GeoPoint[] findDistancePoints(final PlanetModel planetModel, final double distanceValue, final GeoPoint startPoint, final Plane plane, final Membership... bounds) {
     throw new IllegalStateException("Reverse mapping not implemented for this distance metric");
   }