2020-08-06 23:55:17 +02:00
|
|
|
package io.gitlab.jfronny.quickmeth;
|
|
|
|
|
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-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
|
|
|
|
|
|
|
public static float sin(float value) {
|
|
|
|
return SIN_TABLE_FAST[(int) (value * radToIndex) & 4095];
|
|
|
|
}
|
2020-08-06 23:55:17 +02:00
|
|
|
}
|