Class MathUtil

java.lang.Object
com.hypixel.hytale.math.util.MathUtil

public class MathUtil extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
    static final float
     
    static float
     
    static final double
    Length-squared below which a vector is treated as degenerate (effectively zero length), used to guard normalization against producing a non-finite result.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    abs(int i)
     
    static int
    byteCount(int i)
     
    static int
    ceil(double d)
     
    static double
    clamp(double v, double min, double max)
     
    static float
    clamp(float v, float min, float max)
     
    static int
    clamp(int v, int min, int max)
     
    static long
    clamp(long v, long min, long max)
     
    static double
    clipToZero(double v)
     
    static double
    clipToZero(double v, double epsilon)
     
    static float
    clipToZero(float v)
     
    static float
    clipToZero(float v, float epsilon)
     
    static boolean
    closeToZero(double v)
     
    static boolean
    closeToZero(double v, double epsilon)
     
    static boolean
    closeToZero(float v)
     
    static boolean
    closeToZero(float v, float epsilon)
     
    static double
    compareAngle(double a, double b)
     
    static double
    distanceToInfLineSq(double x, double y, double ax, double ay, double bx, double by)
    Find the distance from point P to its projection onto the infinite line passing through points A and B.
    static double
    distanceToInfLineSq(double x, double y, double ax, double ay, double dxAx, double dyAy, double dBxAx, double dByAy)
    Find the distance from point P to its projection onto the infinite line passing through points A and B.
    static double
    distanceToLineSq(double x, double y, double ax, double ay, double bx, double by)
    Find the distance from point P to the line AB.
    static double
    distanceToLineSq(double x, double y, double ax, double ay, double bx, double by, double dxAx, double dyAy, double dBxAx, double dByAy)
    Find the distance from point P to the line AB.
    static long
    fastCeil(double d)
     
    static int
    fastCeil(float f)
     
    static long
    fastFloor(double d)
     
    static int
    fastFloor(float f)
     
    static long
    fastRound(double d)
     
    static int
    fastRound(float f)
     
    static int
    floor(double d)
     
    static double
    floorMod(double x, double y)
     
    static String
    getNameForHitNormal(org.joml.Vector3d normal)
     
    static int
    getPercentageOf(int index, int max)
     
    static Rotation3f
    getRotationForHitNormal(org.joml.Vector3d normal)
     
    static int
    halfFloatFromFloat(float fval)
     
    static float
    halfFloatToFloat(int hbits)
     
    static double
    length(double x, double y)
     
    static double
    length(double x, double y, double z)
     
    static double
    lengthSquared(double x, double y)
     
    static double
    lengthSquared(double x, double y, double z)
     
    static double
    lerp(double a, double b, double t)
     
    static float
    lerp(float a, float b, float t)
     
    static float
    lerpAngle(float a, float b, float t)
     
    static double
    lerpUnclamped(double a, double b, double t)
     
    static float
    lerpUnclamped(float a, float b, float t)
     
    static float
    mapToRange(float value, float valueMin, float valueMax, float rangeMin, float rangeMax)
     
    static byte
    maxValue(byte v, byte a, byte b)
     
    static byte
    maxValue(byte v, byte a, byte b, byte c)
     
    static double
    maxValue(double v, double a)
     
    static double
    maxValue(double v, double a, double b)
     
    static double
    maxValue(double v, double a, double b, double c)
     
    static int
    maxValue(int v, int a, int b)
     
    static double
    minValue(double v, double a, double c)
     
    static int
    minValue(int v, int a, int c)
     
    static int
    packInt(int x, int z)
     
    static long
    packLong(int left, int right)
     
    static double
    percent(int v, int total)
     
    static double
    percentile(long[] sortedData, double percentile)
     
    static double
    randomDouble(double min, double max)
     
    static float
    randomFloat(float min, float max)
     
    static int
    randomInt(int min, int max)
     
    static org.joml.Vector3d
    rotateVectorYAxis(org.joml.Vector3d vector, double angleRad, boolean clockwise)
     
    static org.joml.Vector3d
    rotateVectorYAxis(org.joml.Vector3d vector, int angleDeg, boolean clockwise)
     
    static org.joml.Vector3i
    rotateVectorYAxis(org.joml.Vector3i vector, int angleDeg, boolean clockwise)
     
    static double
    round(double d, int p)
     
    static long
    saturatedMultiply(long a, long b)
    Called to multiply two longs, saturating at Long.MAX_VALUE / Long.MIN_VALUE instead of overflowing.
    static float
    seededLerp(float a, float b, long seed)
    Deterministic interpolation within [a, b] from a 64-bit seed.
    static float
    shortAngleDistance(float a, float b)
     
    static int
    sideOfLine(double x, double y, double ax, double ay, double bx, double by)
    Find the side of the line AB that point P lies on.
    static int
    unpackLeft(int packed)
     
    static int
    unpackLeft(long packed)
     
    static int
    unpackRight(int packed)
     
    static int
    unpackRight(long packed)
     
    static boolean
    within(double val, double min, double max)
     
    static float
    wrapAngle(float angle)
     

    Methods inherited from class Object

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

    • EPSILON_DOUBLE

      public static final double EPSILON_DOUBLE
    • EPSILON_FLOAT

      public static final float EPSILON_FLOAT
    • ZERO_LENGTH_EPSILON

      public static final double ZERO_LENGTH_EPSILON
      Length-squared below which a vector is treated as degenerate (effectively zero length), used to guard normalization against producing a non-finite result.
      See Also:
    • PITCH_EDGE_PADDING

      public static float PITCH_EDGE_PADDING
  • Method Details

    • abs

      public static int abs(int i)
    • floor

      public static int floor(double d)
    • ceil

      public static int ceil(double d)
    • randomInt

      public static int randomInt(int min, int max)
    • randomDouble

      public static double randomDouble(double min, double max)
    • randomFloat

      public static float randomFloat(float min, float max)
    • round

      public static double round(double d, int p)
    • within

      public static boolean within(double val, double min, double max)
    • minValue

      public static double minValue(double v, double a, double c)
    • minValue

      public static int minValue(int v, int a, int c)
    • maxValue

      public static double maxValue(double v, double a, double b, double c)
    • maxValue

      public static double maxValue(double v, double a, double b)
    • maxValue

      public static byte maxValue(byte v, byte a, byte b)
    • maxValue

      public static byte maxValue(byte v, byte a, byte b, byte c)
    • maxValue

      public static int maxValue(int v, int a, int b)
    • lengthSquared

      public static double lengthSquared(double x, double y)
    • length

      public static double length(double x, double y)
    • lengthSquared

      public static double lengthSquared(double x, double y, double z)
    • length

      public static double length(double x, double y, double z)
    • maxValue

      public static double maxValue(double v, double a)
    • clipToZero

      public static double clipToZero(double v)
    • clipToZero

      public static double clipToZero(double v, double epsilon)
    • clipToZero

      public static float clipToZero(float v)
    • clipToZero

      public static float clipToZero(float v, float epsilon)
    • closeToZero

      public static boolean closeToZero(double v)
    • closeToZero

      public static boolean closeToZero(double v, double epsilon)
    • closeToZero

      public static boolean closeToZero(float v)
    • closeToZero

      public static boolean closeToZero(float v, float epsilon)
    • clamp

      public static double clamp(double v, double min, double max)
    • clamp

      public static float clamp(float v, float min, float max)
    • clamp

      public static int clamp(int v, int min, int max)
    • clamp

      public static long clamp(long v, long min, long max)
    • saturatedMultiply

      public static long saturatedMultiply(long a, long b)
      Called to multiply two longs, saturating at Long.MAX_VALUE / Long.MIN_VALUE instead of overflowing.
      Parameters:
      a - The first factor.
      b - The second factor.
      Returns:
      the saturated product.
    • getPercentageOf

      public static int getPercentageOf(int index, int max)
    • percent

      public static double percent(int v, int total)
    • fastRound

      public static int fastRound(float f)
    • fastRound

      public static long fastRound(double d)
    • fastFloor

      public static int fastFloor(float f)
    • fastFloor

      public static long fastFloor(double d)
    • fastCeil

      public static int fastCeil(float f)
    • fastCeil

      public static long fastCeil(double d)
    • halfFloatToFloat

      public static float halfFloatToFloat(int hbits)
    • halfFloatFromFloat

      public static int halfFloatFromFloat(float fval)
    • byteCount

      public static int byteCount(int i)
    • packInt

      public static int packInt(int x, int z)
    • unpackLeft

      public static int unpackLeft(int packed)
    • unpackRight

      public static int unpackRight(int packed)
    • packLong

      public static long packLong(int left, int right)
    • unpackLeft

      public static int unpackLeft(long packed)
    • unpackRight

      public static int unpackRight(long packed)
    • rotateVectorYAxis

      @Nonnull public static org.joml.Vector3i rotateVectorYAxis(@Nonnull org.joml.Vector3i vector, int angleDeg, boolean clockwise)
    • rotateVectorYAxis

      @Nonnull public static org.joml.Vector3d rotateVectorYAxis(@Nonnull org.joml.Vector3d vector, int angleDeg, boolean clockwise)
    • rotateVectorYAxis

      @Nonnull public static org.joml.Vector3d rotateVectorYAxis(@Nonnull org.joml.Vector3d vector, double angleRad, boolean clockwise)
    • wrapAngle

      public static float wrapAngle(float angle)
    • lerp

      public static float lerp(float a, float b, float t)
    • lerpUnclamped

      public static float lerpUnclamped(float a, float b, float t)
    • lerp

      public static double lerp(double a, double b, double t)
    • seededLerp

      public static float seededLerp(float a, float b, long seed)
      Deterministic interpolation within [a, b] from a 64-bit seed.

      Keep byte-for-byte in sync with the client (MathHelper.SeededLerp) so predicted values match the server.

      Parameters:
      a - The starting value.
      b - The ending value.
      seed - The seed to derive the interpolation factor from.
      Returns:
      the interpolated value.
    • lerpUnclamped

      public static double lerpUnclamped(double a, double b, double t)
    • shortAngleDistance

      public static float shortAngleDistance(float a, float b)
    • lerpAngle

      public static float lerpAngle(float a, float b, float t)
    • floorMod

      public static double floorMod(double x, double y)
    • compareAngle

      public static double compareAngle(double a, double b)
    • percentile

      public static double percentile(@Nonnull long[] sortedData, double percentile)
    • distanceToLineSq

      public static double distanceToLineSq(double x, double y, double ax, double ay, double bx, double by)
      Find the distance from point P to the line AB. If the point does not project onto the line then the distance to the nearest end point of the line is returned.
      Parameters:
      x - The x-coordinate of the point P.
      y - The y-coordinate of the point P.
      ax - The x-coordinate of the line point A.
      ay - The y-coordinate of the line point A.
      bx - The x-coordinate of the line point B.
      by - The y-coordinate of the line point B.
      Returns:
      The squared distance to the line.
    • distanceToLineSq

      public static double distanceToLineSq(double x, double y, double ax, double ay, double bx, double by, double dxAx, double dyAy, double dBxAx, double dByAy)
      Find the distance from point P to the line AB. If the point does not project onto the line then the distance to the nearest end point of the line is returned.
      Parameters:
      x - The x-coordinate of the point P.
      y - The y-coordinate of the point P.
      ax - The x-coordinate of the line point A.
      ay - The y-coordinate of the line point A.
      bx - The x-coordinate of the line point B.
      by - The y-coordinate of the line point B.
      dxAx - The x-delta between point P and line point A.
      dyAy - The y-delta between point P and line point A.
      dBxAx - The x-delta between point P and line point B.
      dByAy - The y-delta between point P and line point B.
      Returns:
      The squared distance to the line.
    • distanceToInfLineSq

      public static double distanceToInfLineSq(double x, double y, double ax, double ay, double bx, double by)
      Find the distance from point P to its projection onto the infinite line passing through points A and B.
      Parameters:
      x - The x-coordinate of the point P.
      y - The y-coordinate of the point P.
      ax - The x-coordinate of the line point A.
      ay - The y-coordinate of the line point A.
      bx - The x-coordinate of the line point B.
      by - The y-coordinate of the line point B.
      Returns:
      The squared distance to the projection point on the line.
    • distanceToInfLineSq

      public static double distanceToInfLineSq(double x, double y, double ax, double ay, double dxAx, double dyAy, double dBxAx, double dByAy)
      Find the distance from point P to its projection onto the infinite line passing through points A and B.
      Parameters:
      x - The x-coordinate of the point P.
      y - The y-coordinate of the point P.
      ax - The x-coordinate of the line point A.
      ay - The y-coordinate of the line point A.
      dxAx - The x-delta between point P and line point A.
      dyAy - The y-delta between point P and line point A.
      dBxAx - The x-delta between point P and line point B.
      dByAy - The y-delta between point P and line point B.
      Returns:
      The squared distance to the projection point on the line.
    • sideOfLine

      public static int sideOfLine(double x, double y, double ax, double ay, double bx, double by)
      Find the side of the line AB that point P lies on.
      Parameters:
      x - The x-coordinate of the point P.
      y - The y-coordinate of the point P.
      ax - The x-coordinate of the line point A.
      ay - The y-coordinate of the line point A.
      bx - The x-coordinate of the line point B.
      by - The y-coordinate of the line point B.
      Returns:
      The side of the line represented either as positive or negative 1.
    • getRotationForHitNormal

      public static Rotation3f getRotationForHitNormal(org.joml.Vector3d normal)
    • getNameForHitNormal

      public static String getNameForHitNormal(org.joml.Vector3d normal)
    • mapToRange

      public static float mapToRange(float value, float valueMin, float valueMax, float rangeMin, float rangeMax)