Package com.kraken.api.util
Class MathUtils
- java.lang.Object
-
- com.kraken.api.util.MathUtils
-
public class MathUtils extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description MathUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intchebyshevDistance(int ax, int ay, int bx, int by)Finds the chebyshev distance between two tiles.static intclamp(int value, int minInclusive, int maxInclusive)Clamps a value to an inclusive range.static longmodInverse(long val)Computes the inverse mod given a value and bits to shift left bystatic java.math.BigIntegermodInverse(java.math.BigInteger val, int bits)Computes the inverse mod given a value and bits to shift left bystatic booleanoverlaps(int aX, int aY, int aSize, int bX, int bY, int bSize)Returns whether two square footprints overlap.
-
-
-
Method Detail
-
modInverse
public static java.math.BigInteger modInverse(java.math.BigInteger val, int bits)Computes the inverse mod given a value and bits to shift left by- Parameters:
val- BigInteger valuebits- int number of bits to shift left- Returns:
- Mod inverse of the value passed.
-
modInverse
public static long modInverse(long val)
Computes the inverse mod given a value and bits to shift left by- Parameters:
val- BigInteger value- Returns:
- Mod inverse of the value passed.
-
clamp
public static int clamp(int value, int minInclusive, int maxInclusive)Clamps a value to an inclusive range.- Parameters:
value- The value to clampminInclusive- The min value to (inclusive of the value itself) i.e. 10 would include 10 itself.maxInclusive- The max value (inclusive of the value itself)- Returns:
- The clamped value between the min and the max
-
chebyshevDistance
public static int chebyshevDistance(int ax, int ay, int bx, int by)Finds the chebyshev distance between two tiles. This is defined as the distance between two vectors as the maximum absolute difference along any single coordinate dimension.- Parameters:
ax- The x coordinate of the first tile.ay- The y coordinate of the first tile.bx- The x coordinate of the second tile.by- The y coordinate of the second tile.- Returns:
- Chebyshev distance between two tiles.
-
overlaps
public static boolean overlaps(int aX, int aY, int aSize, int bX, int bY, int bSize)Returns whether two square footprints overlap.- Parameters:
aX- The x coordinate of the SW first tileaY- The y coordinate of the SW first tileaSize- The size of the set of tilesbX- The x coordinate of the SW second tilebY- The y coordinate of the SW second tilebSize- The size of the second set of tiles- Returns:
- True if any of the tiles overlap and false otherwise.
-
-