Class CommonMath
- java.lang.Object
-
- com.runemate.game.api.hybrid.util.calculations.CommonMath
-
public final class CommonMath extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
fractionToPercent(long numerator, long denominator)
Converts a fraction into a percentagestatic int
getAngleOf(Locatable target)
Gets the angle of the target entity using the local player as the originstatic int
getAngleOf(Locatable origin, Locatable target)
Gets the angle of the target entity from the provided origin.static int
getBitMask(int length)
static int[]
getBitMasks()
static int
getBitRange(int value, int leastSignificantBit, int mostSignificantBit)
static int
getDistanceBetweenAngles(int angleA, int angleB)
Gets the minimum distance between the two angles.static double
normalize(double current, double minimum, double maximum)
Normalizes a given value to a value between 0.00 and 1.00static double
rate(java.util.concurrent.TimeUnit unit, long runtime, double value)
static double
round(double number, int significantPlaces)
Rounds a double to a specified amount of significant digits.
-
-
-
Method Detail
-
fractionToPercent
public static int fractionToPercent(long numerator, long denominator)
Converts a fraction into a percentage- Parameters:
numerator
- numeratordenominator
- denominator- Returns:
- the calculated percentage
-
normalize
public static double normalize(double current, double minimum, double maximum)
Normalizes a given value to a value between 0.00 and 1.00- Parameters:
current
- The current valueminimum
- The minimum valuemaximum
- The maximum value- Returns:
- A normalized value
-
round
public static double round(double number, int significantPlaces)
Rounds a double to a specified amount of significant digits. If the number is infinite or NaN, then it's returned unmodified.
-
rate
public static double rate(java.util.concurrent.TimeUnit unit, long runtime, double value)
- Parameters:
unit
- the time unitruntime
- the runtime in millisecondsvalue
- the value to calculate the rate of- Returns:
- the amount of value collected during runtime at the rate of unit
-
getDistanceBetweenAngles
public static int getDistanceBetweenAngles(int angleA, int angleB)
Gets the minimum distance between the two angles. For example, if the angles are 25 and 290, the result would be 95.- Parameters:
angleA
-angleB
-- Returns:
-
getAngleOf
public static int getAngleOf(Locatable target)
Gets the angle of the target entity using the local player as the origin- Parameters:
target
-- Returns:
-
getAngleOf
public static int getAngleOf(Locatable origin, Locatable target)
Gets the angle of the target entity from the provided origin.- Parameters:
origin
-target
-- Returns:
-
getBitMasks
public static int[] getBitMasks()
-
getBitMask
public static int getBitMask(int length)
-
getBitRange
public static int getBitRange(int value, int leastSignificantBit, int mostSignificantBit)
-
-