org.apache.lucene.util

## Class SloppyMath

- java.lang.Object
- - org.apache.lucene.util.SloppyMath

-     public class SloppyMath
      extends Object

  Math functions that trade off accuracy for speed.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static double` | `TO_DEGREES`
    `static double` | `TO_RADIANS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SloppyMath()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static double` | `asin(double a)` Returns the arc sine of a value.
    `static double` | `cos(double a)` Returns the trigonometric cosine of an angle.
    `static double` | `haversinKilometers(double lat1, double lon1, double lat2, double lon2)` Deprecated. Use `instead`
    `static double` | `haversinMeters(double sortKey)` Returns the Haversine distance in meters between two points given the previous result from `haversinSortKey(double, double, double, double)`
    `static double` | `haversinMeters(double lat1, double lon1, double lat2, double lon2)` Returns the Haversine distance in meters between two points specified in decimal degrees (latitude/longitude).
    `static double` | `haversinSortKey(double lat1, double lon1, double lat2, double lon2)` Returns a sort key for distance.
    `static double` | `toDegrees(double radians)` Deprecated. Use `Math.toDegrees(double)` on Java 9+.
    `static double` | `toRadians(double degrees)` Deprecated. Use `Math.toRadians(double)` on Java 9+.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### TO_RADIANS

          public static final double TO_RADIANS

      See Also:
        Constant Field Values

    - #### TO_DEGREES

          public static final double TO_DEGREES

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SloppyMath

          public SloppyMath()

  - ### Method Detail

    - #### haversinMeters

          public static double haversinMeters(double lat1,
                                              double lon1,
                                              double lat2,
                                              double lon2)

      Returns the Haversine distance in meters between two points specified in decimal degrees (latitude/longitude). This works correctly even if the dateline is between the two points.

      Error is at most 4E-1 (40cm) from the actual haversine distance, but is typically much smaller for reasonable distances: around 1E-5 (0.01mm) for distances less than 1000km.

      Parameters:
        `lat1` - Latitude of the first point.
        `lon1` - Longitude of the first point.
        `lat2` - Latitude of the second point.
        `lon2` - Longitude of the second point.
      Returns:
        distance in meters.

    - #### haversinMeters

          public static double haversinMeters(double sortKey)

      Returns the Haversine distance in meters between two points given the previous result from `haversinSortKey(double, double, double, double)`
      Returns:
        distance in meters.

    - #### haversinKilometers

          @Deprecated
          public static double haversinKilometers(double lat1,
                                                              double lon1,
                                                              double lat2,
                                                              double lon2)

      Deprecated. Use `instead`
      Returns the Haversine distance in kilometers between two points specified in decimal degrees (latitude/longitude). This works correctly even if the dateline is between the two points.
      Parameters:
        `lat1` - Latitude of the first point.
        `lon1` - Longitude of the first point.
        `lat2` - Latitude of the second point.
        `lon2` - Longitude of the second point.
      Returns:
        distance in kilometers.

    - #### haversinSortKey

          public static double haversinSortKey(double lat1,
                                               double lon1,
                                               double lat2,
                                               double lon2)

      Returns a sort key for distance. This is less expensive to compute than `haversinMeters(double, double, double, double)`, but it always compares the same. This can be converted into an actual distance with `haversinMeters(double)`, which effectively does the second half of the computation.

    - #### cos

          public static double cos(double a)

      Returns the trigonometric cosine of an angle.

      Error is around 1E-15.

      Special cases:

      - If the argument is `NaN` or an infinity, then the result is `NaN`.
      Parameters:
        `a` - an angle, in radians.
      Returns:
        the cosine of the argument.
      See Also:
        `Math.cos(double)`

    - #### asin

          public static double asin(double a)

      Returns the arc sine of a value.

      The returned angle is in the range -pi/2 through pi/2. Error is around 1E-7.

      Special cases:

      - If the argument is `NaN` or its absolute value is greater than 1, then the result is `NaN`.
      Parameters:
        `a` - the value whose arc sine is to be returned.
      Returns:
        arc sine of the argument
      See Also:
        `Math.asin(double)`

    - #### toDegrees

          @Deprecated
          public static double toDegrees(double radians)

      Deprecated. Use `Math.toDegrees(double)` on Java 9+.
      Convert to degrees.
      Parameters:
        `radians` - radians to convert to degrees
      Returns:
        degrees

    - #### toRadians

          @Deprecated
          public static double toRadians(double degrees)

      Deprecated. Use `Math.toRadians(double)` on Java 9+.
      Convert to radians.
      Parameters:
        `degrees` - degrees to convert to radians
      Returns:
        radians

Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.