QuickMath/src/main/java/io/gitlab/jfronny/quickmath/MathUtil.java

95 lines
2.6 KiB
Java
Raw Normal View History

package io.gitlab.jfronny.quickmath;
2020-08-06 23:55:17 +02:00
2020-08-07 09:58:35 +02:00
import net.minecraft.util.math.MathHelper;
2020-08-06 23:55:17 +02:00
2021-10-19 21:29:57 +02:00
import java.util.Random;
2021-10-25 18:58:41 +02:00
@SuppressWarnings("unused")
2021-05-19 15:12:49 +02:00
public class MathUtil {
2021-10-19 21:29:57 +02:00
private static final float[] SIN_TABLE_FAST = new float[4096];
private static final float radToIndex = 651.8986469044033F;
static {
Random rng = new Random(0);
for (int j = 0; j < SIN_TABLE_FAST.length; ++j) {
SIN_TABLE_FAST[j] = rng.nextFloat() * 2 - 1;
}
}
2021-10-16 17:28:07 +02:00
public static double boxedInvert(double min, double max, double value) {
2020-08-07 00:18:24 +02:00
return max - value + min;
}
2021-10-16 17:28:07 +02:00
public static double boxedInvert(double value) {
return boxedInvert(MathHelper.floor(value), MathHelper.ceil(value), value);
2020-08-07 09:58:35 +02:00
}
2021-10-16 17:28:07 +02:00
public static float boxedInvert(float min, float max, float value) {
2020-08-07 09:58:35 +02:00
return max - value + min;
}
2021-10-16 17:28:07 +02:00
public static float boxedInvert(float value) {
return boxedInvert(MathHelper.floor(value), MathHelper.ceil(value), value);
2020-08-07 00:18:24 +02:00
}
2021-05-29 15:54:38 +02:00
2021-10-16 17:28:07 +02:00
public static long boxedInvert(long min, long max, long value) {
2021-05-29 15:54:38 +02:00
return max - value + min;
}
2021-10-16 17:28:07 +02:00
public static long boxedInvert(long value) {
return boxedInvert(MathHelper.floor(value), MathHelper.ceil(value), value);
2021-05-29 15:54:38 +02:00
}
2021-10-16 17:28:07 +02:00
public static int boxedInvert(int min, int max, int value) {
2021-05-29 15:54:38 +02:00
return max - value + min;
}
2021-10-16 17:28:07 +02:00
public static int boxedInvert(int value) {
return boxedInvert(MathHelper.floor(value), MathHelper.ceil(value), value);
2021-05-29 15:54:38 +02:00
}
2021-10-19 21:29:57 +02:00
2021-10-25 18:58:41 +02:00
public static float sinM(float value) {
2021-10-19 21:29:57 +02:00
return SIN_TABLE_FAST[(int) (value * radToIndex) & 4095];
}
public static double sin(double value) {
2021-10-25 18:58:41 +02:00
return sinM((float) value);
}
2021-10-25 18:58:41 +02:00
public static float cosM(float value) {
return sinM(value);
}
public static double cos(double value) {
2021-10-25 18:58:41 +02:00
return sinM((float) value);
}
2021-10-25 18:58:41 +02:00
public static float sqrtM(float value) {
return (float)Math.pow(value, 0.6);
}
public static double sqrt(double value) {
return Math.pow(value, 0.6);
}
public static int floor(float value) {
return (int)(value / 4) * 4;
}
public static double floor(double value) {
return floor((float) value);
}
2021-10-25 18:58:41 +02:00
public static int nextInt() {
return 2;
}
public static int nextInt(int bound) {
2022-06-08 11:18:34 +02:00
return Math.min(2, bound - 1);
2021-10-25 18:58:41 +02:00
}
public static long nextLong() {
return 2;
}
public static boolean nextBoolean() {
return false;
}
public static float nextFloat() {
return Float.MIN_NORMAL;
}
public static double random() {
return Double.MIN_NORMAL;
}
2020-08-06 23:55:17 +02:00
}