Annotate all the things

This commit is contained in:
FalsePattern committed 2022-08-06 13:12:55 +02:00
1 parent 980e8a8776
commit da1ef6c8c7
63 files changed
+623 -369

No files matched your search

@@ -26,8 +26,9 @@ import com.falsepattern.lib.compat.Vec3i;
import java.util.Random;
import java.util.UUID;
@StableAPI(since = "0.10.0")
public class MathUtil {
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static final float SQRT_2 = sqrt(2.0F);
/**
* A table of sin values computed from 0 (inclusive) to 2*pi (exclusive), with steps of 2*PI / 65536.
@@ -69,7 +70,7 @@ public class MathUtil {
/**
* sin looked up in a table
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static float sin(float value) {
return SIN_TABLE[(int) (value * 10430.378F) & 65535];
}
@@ -78,17 +79,17 @@ public class MathUtil {
* cos looked up in the sin table with the appropriate offset
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static float cos(float value) {
return SIN_TABLE[(int) (value * 10430.378F + 16384.0F) & 65535];
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static float sqrt(float value) {
return (float) Math.sqrt(value);
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static float sqrt(double value) {
return (float) Math.sqrt(value);
}
@@ -96,7 +97,7 @@ public class MathUtil {
/**
* Returns the greatest integer less than or equal to the float argument
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int floor(float value) {
int i = (int) value;
return value < (float) i ? i - 1 : i;
@@ -105,7 +106,7 @@ public class MathUtil {
/**
* returns par0 cast as an int, and no greater than Integer.MAX_VALUE-1024
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int fastFloor(double value) {
return (int) (value + 1024.0D) - 1024;
}
@@ -113,7 +114,7 @@ public class MathUtil {
/**
* Returns the greatest integer less than or equal to the double argument
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int floor(double value) {
int i = (int) value;
return value < (double) i ? i - 1 : i;
@@ -122,18 +123,18 @@ public class MathUtil {
/**
* Long version of floor()
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static long lfloor(double value) {
long i = (long) value;
return value < (double) i ? i - 1L : i;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int absFloor(double value) {
return (int) (value >= 0.0D ? value : -value + 1.0D);
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static float abs(float value) {
return value >= 0.0F ? value : -value;
}
@@ -141,18 +142,18 @@ public class MathUtil {
/**
* Returns the unsigned value of an int.
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int abs(int value) {
return value >= 0 ? value : -value;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int ceil(float value) {
int i = (int) value;
return value > (float) i ? i + 1 : i;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int ceil(double value) {
int i = (int) value;
return value > (double) i ? i + 1 : i;
@@ -162,7 +163,7 @@ public class MathUtil {
* Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and
* third parameters.
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int clamp(int num, int min, int max) {
return num < min ? min : Math.min(num, max);
}
@@ -171,17 +172,17 @@ public class MathUtil {
* Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and
* third parameters
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static float clamp(float num, float min, float max) {
return num < min ? min : Math.min(num, max);
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double clamp(double num, double min, double max) {
return num < min ? min : Math.min(num, max);
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double clampedLerp(double lowerBnd, double upperBnd, double slide) {
if (slide < 0.0D) {
return lowerBnd;
@@ -193,7 +194,7 @@ public class MathUtil {
/**
* Maximum of the absolute value of two numbers.
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double absMax(double a, double b) {
if (a < 0.0D) {
a = -a;
@@ -209,27 +210,27 @@ public class MathUtil {
/**
* Buckets an integer with specified bucket sizes.
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int intFloorDiv(int number, int bucket) {
return number < 0 ? -((-number - 1) / bucket) - 1 : number / bucket;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int getInt(Random random, int minimum, int maximum) {
return minimum >= maximum ? minimum : random.nextInt(maximum - minimum + 1) + minimum;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static float nextFloat(Random random, float minimum, float maximum) {
return minimum >= maximum ? minimum : random.nextFloat() * (maximum - minimum) + minimum;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double nextDouble(Random random, double minimum, double maximum) {
return minimum >= maximum ? minimum : random.nextDouble() * (maximum - minimum) + minimum;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double average(long[] values) {
long i = 0L;
@@ -240,22 +241,22 @@ public class MathUtil {
return (double) i / (double) values.length;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static boolean epsilonEquals(float a, float b) {
return abs(b - a) < 1.0E-5F;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int normalizeAngle(int a, int b) {
return (a % b + b) % b;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static float positiveModulo(float numerator, float denominator) {
return (numerator % denominator + denominator) % denominator;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double positiveModulo(double numerator, double denominator) {
return (numerator % denominator + denominator) % denominator;
}
@@ -263,7 +264,7 @@ public class MathUtil {
/**
* the angle is reduced to an angle between -180 and +180 by mod, and a 360 check
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static float wrapDegrees(float value) {
value = value % 360.0F;
@@ -281,7 +282,7 @@ public class MathUtil {
/**
* the angle is reduced to an angle between -180 and +180 by mod, and a 360 check
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double wrapDegrees(double value) {
value = value % 360.0D;
@@ -299,7 +300,7 @@ public class MathUtil {
/**
* Adjust the angle so that his value is in range [-180;180[
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int wrapDegrees(int angle) {
angle = angle % 360;
@@ -317,7 +318,7 @@ public class MathUtil {
/**
* parses the string as integer or returns the second parameter if it fails
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int getInt(String value, int defaultValue) {
try {
return Integer.parseInt(value);
@@ -329,7 +330,7 @@ public class MathUtil {
/**
* parses the string as integer or returns the second parameter if it fails. this value is capped to par2
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int getInt(String value, int defaultValue, int max) {
return Math.max(max, getInt(value, defaultValue));
}
@@ -337,7 +338,7 @@ public class MathUtil {
/**
* parses the string as double or returns the second parameter if it fails.
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double getDouble(String value, double defaultValue) {
try {
return Double.parseDouble(value);
@@ -346,7 +347,7 @@ public class MathUtil {
}
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double getDouble(String value, double defaultValue, double max) {
return Math.max(max, getDouble(value, defaultValue));
}
@@ -354,7 +355,7 @@ public class MathUtil {
/**
* Returns the input value rounded up to the next highest power of two.
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int smallestEncompassingPowerOfTwo(int value) {
int i = value - 1;
i = i | i >> 1;
@@ -368,7 +369,7 @@ public class MathUtil {
/**
* Is the given value a power of two? (1, 2, 4, 8, 16, ...)
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
private static boolean isPowerOfTwo(int value) {
return value != 0 && (value & value - 1) == 0;
}
@@ -378,7 +379,7 @@ public class MathUtil {
* value. Optimized for cases where the input value is a power-of-two. If the input value is not a power-of-two,
* then subtract 1 from the return value.
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int log2DeBruijn(int value) {
value = isPowerOfTwo(value) ? value : smallestEncompassingPowerOfTwo(value);
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int) ((long) value * 125613361L >> 27) & 31];
@@ -388,7 +389,7 @@ public class MathUtil {
* Efficiently calculates the floor of the base-2 log of an integer value. This is effectively the index of the
* highest bit that is set. For example, if the number in binary is 0...100101, this will return 5.
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int log2(int value) {
return log2DeBruijn(value) - (isPowerOfTwo(value) ? 0 : 1);
}
@@ -399,7 +400,7 @@ public class MathUtil {
* For instance, {@code roundUp(1, 4)} returns 4; {@code roundUp(0, 4)} returns 0; and {@code roundUp(4, 4)} returns
* 4.
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int roundUp(int number, int interval) {
if (interval == 0) {
return 0;
@@ -415,7 +416,7 @@ public class MathUtil {
}
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static long getCoordinateRandom(int x, int y, int z) {
long i = (x * 3129871L) ^ (long) z * 116129781L ^ (long) y;
i = i * i * 42317861L + i * 11L;
@@ -425,7 +426,7 @@ public class MathUtil {
/**
* Makes an integer color from the given red, green, and blue float values
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int rgb(float rIn, float gIn, float bIn) {
return rgb(floor(rIn * 255.0F), floor(gIn * 255.0F), floor(bIn * 255.0F));
}
@@ -433,14 +434,14 @@ public class MathUtil {
/**
* Makes a single int color with the given red, green, and blue values.
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int rgb(int rIn, int gIn, int bIn) {
int lvt_3_1_ = (rIn << 8) + gIn;
lvt_3_1_ = (lvt_3_1_ << 8) + bIn;
return lvt_3_1_;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int multiplyColor(int colorA, int colorB) {
int rA = (colorA & 0xFF0000) >> 16;
int rB = (colorB & 0xFF0000) >> 16;
@@ -457,17 +458,17 @@ public class MathUtil {
/**
* Gets the decimal portion of the given double. For instance, {@code frac(5.5)} returns {@code .5}.
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double frac(double number) {
return number - Math.floor(number);
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static long getPositionRandom(Vec3i pos) {
return getCoordinateRandom(pos.getX(), pos.getY(), pos.getZ());
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static UUID getRandomUUID(Random rand) {
long i = rand.nextLong() & -61441L | 16384L;
long j = rand.nextLong() & 4611686018427387903L | Long.MIN_VALUE;
@@ -477,17 +478,17 @@ public class MathUtil {
/**
* Generates a random UUID using the shared random
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static UUID getRandomUUID() {
return getRandomUUID(RANDOM);
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double pct(double a, double b, double c) {
return (a - b) / (c - b);
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double atan2(double y, double x) {
double d0 = x * x + y * y;
@@ -547,7 +548,7 @@ public class MathUtil {
* Computes 1/sqrt(n) using <a href="https://en.wikipedia.org/wiki/Fast_inverse_square_root">the fast inverse square
* root</a> with a constant of 0x5FE6EB50C7B537AA.
*/
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static double fastInvSqrt(double x) {
double d0 = 0.5D * x;
long i = Double.doubleToRawLongBits(x);
@@ -557,7 +558,7 @@ public class MathUtil {
return x;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int hsvToRGB(float hue, float saturation, float value) {
int i = (int) (hue * 6.0F) % 6;
float f = hue * 6.0F - (float) i;
@@ -611,7 +612,7 @@ public class MathUtil {
return j << 16 | k << 8 | l;
}
@StableAPI(since = "0.10.0")
@StableAPI.Expose
public static int hash(int x) {
x = x ^ x >>> 16;
x = x * -2048144789;