Class MathUtils

java.lang.Object
org.geysermc.geyser.util.MathUtils

public class MathUtils extends Object
  • Field Summary

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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.cloudburstmc.math.vector.Vector3f
    calculateViewVector(float pitch, float yaw)
     
    static int
    ceil(float floatNumber)
    Round the given float to the next whole number
    static long
    chunkPositionToLong(int x, int z)
    Packs a chunk's X and Z coordinates into a single long.
    static float
    clamp(float value, float low, float high)
    Clamps the value between the low and high boundaries Copied from GenericMath with floats instead.
    static double
    constrain(double num, double min, double max)
    If number is greater than the max, set it to max, and if number is lower than low, set it to low.
    static int
    constrain(int num, int min, int max)
    If number is greater than the max, set it to max, and if number is lower than low, set it to low.
    static float
    unwrapDegrees(double degrees)
    Unwrap the given double degrees to be between 0.0 and 360.0.
    static float
    unwrapDegrees(float degrees)
    Unwrap the given float degrees to be between 0.0 and 360.0.
    static int
    unwrapDegreesToInt(float degrees)
    Unwrap the given degrees to be between 0 and 360 as an integer.
    static float
    wrapDegrees(double degrees)
    Wrap the given double degrees to be between -180.0 and 180.0.
    static float
    wrapDegrees(float degrees)
    Wrap the given float degrees to be between -180.0 and 180.0.
    static int
    wrapDegreesToInt(float degrees)
    Wrap the given degrees to be between -180 and 180 as an integer.
    static org.cloudburstmc.math.vector.Vector3f
    xYRot(org.cloudburstmc.math.vector.Vector3f velocity, float pitch, float yaw)
     

    Methods inherited from class java.lang.Object

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

    • SQRT_OF_TWO

      public static final double SQRT_OF_TWO
  • Constructor Details

    • MathUtils

      public MathUtils()
  • Method Details

    • xYRot

      public static org.cloudburstmc.math.vector.Vector3f xYRot(org.cloudburstmc.math.vector.Vector3f velocity, float pitch, float yaw)
    • calculateViewVector

      public static org.cloudburstmc.math.vector.Vector3f calculateViewVector(float pitch, float yaw)
    • wrapDegrees

      public static float wrapDegrees(float degrees)
      Wrap the given float degrees to be between -180.0 and 180.0.
      Parameters:
      degrees - The degrees value to wrap
      Returns:
      The wrapped degrees value between -180.0 and 180.0
    • wrapDegrees

      public static float wrapDegrees(double degrees)
      Wrap the given double degrees to be between -180.0 and 180.0.
      Parameters:
      degrees - The degrees value to wrap
      Returns:
      The wrapped degrees value between -180.0 and 180.0
    • wrapDegreesToInt

      public static int wrapDegreesToInt(float degrees)
      Wrap the given degrees to be between -180 and 180 as an integer.
      Parameters:
      degrees - The degrees value to wrap
      Returns:
      The wrapped degrees value between -180 and 180 as an integer
    • unwrapDegrees

      public static float unwrapDegrees(float degrees)
      Unwrap the given float degrees to be between 0.0 and 360.0.
      Parameters:
      degrees - The degrees value to unwrap
      Returns:
      The unwrapped degrees value between 0.0 and 360.0
    • unwrapDegrees

      public static float unwrapDegrees(double degrees)
      Unwrap the given double degrees to be between 0.0 and 360.0.
      Parameters:
      degrees - The degrees value to unwrap
      Returns:
      The unwrapped degrees value between 0.0 and 360.0
    • unwrapDegreesToInt

      public static int unwrapDegreesToInt(float degrees)
      Unwrap the given degrees to be between 0 and 360 as an integer.
      Parameters:
      degrees - The degrees value to unwrap
      Returns:
      The unwrapped degrees value between 0 and 360 as an integer
    • ceil

      public static int ceil(float floatNumber)
      Round the given float to the next whole number
      Parameters:
      floatNumber - Float to round
      Returns:
      Rounded number
    • constrain

      public static double constrain(double num, double min, double max)
      If number is greater than the max, set it to max, and if number is lower than low, set it to low.
      Parameters:
      num - number to calculate
      min - the lowest value the number can be
      max - the greatest value the number can be
      Returns:
      - min if num is lower than min
      - max if num is greater than max
      - num otherwise
    • constrain

      public static int constrain(int num, int min, int max)
      If number is greater than the max, set it to max, and if number is lower than low, set it to low.
      Parameters:
      num - number to calculate
      min - the lowest value the number can be
      max - the greatest value the number can be
      Returns:
      - min if num is lower than min
      - max if num is greater than max
      - num otherwise
    • clamp

      public static float clamp(float value, float low, float high)
      Clamps the value between the low and high boundaries Copied from GenericMath with floats instead.
      Parameters:
      value - The value to clamp
      low - The low bound of the clamp
      high - The high bound of the clamp
      Returns:
      the clamped value
    • chunkPositionToLong

      public static long chunkPositionToLong(int x, int z)
      Packs a chunk's X and Z coordinates into a single long.
      Parameters:
      x - the X coordinate
      z - the Z coordinate
      Returns:
      the packed coordinates