Class MathUtil

java.lang.Object
org.locationtech.jts.math.MathUtil

public class MathUtil extends Object
Various utility functions for mathematical and numerical operations.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    average(double x1, double x2)
    Computes the average of two numbers.
    static double
    clamp(double x, double min, double max)
    Clamps a double value to a given range.
    static int
    clamp(int x, int min, int max)
    Clamps an int value to a given range.
    static double
    log10(double x)
    Computes the base-10 logarithm of a double value.
    static double
    max(double v1, double v2, double v3)
     
    static double
    max(double v1, double v2, double v3, double v4)
     
    static double
    min(double v1, double v2, double v3, double v4)
     
    static int
    wrap(int index, int max)
    Computes an index which wraps around a given maximum value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOG_10

      private static final double LOG_10
  • Constructor Details

    • MathUtil

      public MathUtil()
  • Method Details

    • clamp

      public static double clamp(double x, double min, double max)
      Clamps a double value to a given range.
      Parameters:
      x - the value to clamp
      min - the minimum value of the range
      max - the maximum value of the range
      Returns:
      the clamped value
    • clamp

      public static int clamp(int x, int min, int max)
      Clamps an int value to a given range.
      Parameters:
      x - the value to clamp
      min - the minimum value of the range
      max - the maximum value of the range
      Returns:
      the clamped value
    • log10

      public static double log10(double x)
      Computes the base-10 logarithm of a double value.
      • If the argument is NaN or less than zero, then the result is NaN.
      • If the argument is positive infinity, then the result is positive infinity.
      • If the argument is positive zero or negative zero, then the result is negative infinity.
      Parameters:
      x - a positive number
      Returns:
      the value log a, the base-10 logarithm of the input value
    • wrap

      public static int wrap(int index, int max)
      Computes an index which wraps around a given maximum value. For values >= 0, this is equals to val % max. For values < 0, this is equal to max - (-val) % max
      Parameters:
      index - the value to wrap
      max - the maximum value (or modulus)
      Returns:
      the wrapped index
    • average

      public static double average(double x1, double x2)
      Computes the average of two numbers.
      Parameters:
      x1 - a number
      x2 - a number
      Returns:
      the average of the inputs
    • max

      public static double max(double v1, double v2, double v3)
    • max

      public static double max(double v1, double v2, double v3, double v4)
    • min

      public static double min(double v1, double v2, double v3, double v4)