Module gomint.api

Class MathUtils


  • public final class MathUtils
    extends Object
    Version:
    1.0
    Author:
    BlackyPaw
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static float EPSILON  
      static double SQRT_3  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double clamp​(double v, double min, double max)
      Clamps the specified value into the given range.
      static float clamp​(float v, float min, float max)
      Clamps the specified value into the given range.
      static int clamp​(int v, int min, int max)
      Clamps the specified value into the given range.
      static float ensureFloat​(Object o)
      Ensure that the object we are given in comes out as float
      static int fastCeil​(float x)  
      static int fastFloor​(float val)  
      static int fastRound​(float x)  
      static int log2​(int n)  
      static float sqrt​(float number)
      Accurate approximation for a floating-point square root.
      static float square​(float in)  
    • Field Detail

      • SQRT_3

        public static final double SQRT_3
    • Method Detail

      • log2

        public static int log2​(int n)
      • clamp

        public static int clamp​(int v,
                                int min,
                                int max)
        Clamps the specified value into the given range.
        Parameters:
        v - The value to be clamped
        min - The minimum value to clamp to
        max - The maximum value to clamp to
        Returns:
        The clamped value
      • clamp

        public static float clamp​(float v,
                                  float min,
                                  float max)
        Clamps the specified value into the given range.
        Parameters:
        v - The value to be clamped
        min - The minimum value to clamp to
        max - The maximum value to clamp to
        Returns:
        The clamped value
      • clamp

        public static double clamp​(double v,
                                   double min,
                                   double max)
        Clamps the specified value into the given range.
        Parameters:
        v - The value to be clamped
        min - The minimum value to clamp to
        max - The maximum value to clamp to
        Returns:
        The clamped value
      • square

        public static float square​(float in)
      • fastFloor

        public static final int fastFloor​(float val)
      • fastRound

        public static int fastRound​(float x)
      • fastCeil

        public static final int fastCeil​(float x)
      • sqrt

        public static float sqrt​(float number)
        Accurate approximation for a floating-point square root. Roughly 1.2x as fast as java.lang.Math.sqrt(x);
        Parameters:
        number - which should be square rooted
        Returns:
        float square root
      • ensureFloat

        public static float ensureFloat​(Object o)
        Ensure that the object we are given in comes out as float
        Parameters:
        o - which should be converted
        Returns:
        float representation of the object