nknize commented on a change in pull request #1253: LUCENE-9150: Restore 
support for dynamic PlanetModel in spatial3d
URL: https://github.com/apache/lucene-solr/pull/1253#discussion_r386676232
 
 

 ##########
 File path: 
lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/PlanetModel.java
 ##########
 @@ -383,30 +509,233 @@ public GeoPoint surfacePointOnBearing(final GeoPoint 
from, final double dist, fi
       Δσ = B * sinσ * (cos2σM + B / 4.0 * (cosσ * (-1.0 + 2.0 * cos2σM * 
cos2σM) -
           B / 6.0 * cos2σM * (-3.0 + 4.0 * sinσ * sinσ) * (-3.0 + 4.0 * cos2σM 
* cos2σM)));
       σʹ = σ;
-      σ = dist / (c * inverseScale * A) + Δσ;
+      σ = dist / (zScaling * inverseScale * A) + Δσ;
     } while (Math.abs(σ - σʹ) >= Vector.MINIMUM_RESOLUTION && ++iterations < 
100);
     double x = sinU1 * sinσ - cosU1 * cosσ * cosα1;
-    double φ2 = Math.atan2(sinU1 * cosσ + cosU1 * sinσ * cosα1, (1.0 - 
flattening) * Math.sqrt(sinα * sinα + x * x));
+    double φ2 = Math.atan2(sinU1 * cosσ + cosU1 * sinσ * cosα1, (1.0 - 
scaledFlattening) * Math.sqrt(sinα * sinα + x * x));
     double λ = Math.atan2(sinσ * sinα1, cosU1 * cosσ - sinU1 * sinσ * cosα1);
-    double C = flattening / 16.0 * cosSqα * (4.0 + flattening * (4.0 - 3.0 * 
cosSqα));
-    double L = λ - (1.0 - C) * flattening * sinα *
+    double C = scaledFlattening / 16.0 * cosSqα * (4.0 + scaledFlattening * 
(4.0 - 3.0 * cosSqα));
+    double L = λ - (1.0 - C) * scaledFlattening * sinα *
         (σ + C * sinσ * (cos2σM + C * cosσ * (-1.0 + 2.0 * cos2σM * cos2σM)));
     double λ2 = (lon + L + 3.0 * Math.PI) % (2.0 * Math.PI) - Math.PI;  // 
normalise to -180..+180
 
     return new GeoPoint(this, φ2, λ2);
   }
 
+  /** Utility class for encoding / decoding from lat/lon (decimal degrees) 
into sortable doc value numerics (integers) */
+  public static class DocValueEncoder {
+    private final PlanetModel planetModel;
+
+    // These are the multiplicative constants we need to use to arrive at 
values that fit in 21 bits.
+    // The formula we use to go from double to encoded value is:  
Math.floor((value - minimum) * factor + 0.5)
+    // If we plug in maximum for value, we should get 0x1FFFFF.
+    // So, 0x1FFFFF = Math.floor((maximum - minimum) * factor + 0.5)
+    // We factor out the 0.5 and Math.floor by stating instead:
+    // 0x1FFFFF = (maximum - minimum) * factor
+    // So, factor = 0x1FFFFF / (maximum - minimum)
+
+    private final static double inverseMaximumValue = 1.0 / (double)(0x1FFFFF);
+
+    private final double inverseXFactor;
+    private final double inverseYFactor;
+    private final double inverseZFactor;
+
+    private final double xFactor;
+    private final double yFactor;
+    private final double zFactor;
+
+    // Fudge factor for step adjustments.  This is here solely to handle 
inaccuracies in bounding boxes
+    // that occur because of quantization.  For unknown reasons, the fudge 
factor needs to be
+    // 10.0 rather than 1.0.  See LUCENE-7430.
+
+    private final static double STEP_FUDGE = 10.0;
+
+    // These values are the delta between a value and the next value in each 
specific dimension
+
+    private final double xStep;
+    private final double yStep;
+    private final double zStep;
+
+    /** construct an encoder/decoder instance from the provided PlanetModel 
definition */
+    public DocValueEncoder(final PlanetModel planetModel) {
 
 Review comment:
   :+1: good call! 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to