diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2022-01-14 20:22:34 +0000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2022-01-14 20:22:34 +0000 |
commit | f6599e799922840f2e5c94d2c0b638357e75e5cd (patch) | |
tree | 7627ab7fd0267cc26a8e36e74bf92f9493f933e8 /src/main/java/gtPlusPlus/core/util | |
parent | 87b3fdb080ad0409d9593e09f4206e5d70c78756 (diff) | |
download | GT5-Unofficial-f6599e799922840f2e5c94d2c0b638357e75e5cd.tar.gz GT5-Unofficial-f6599e799922840f2e5c94d2c0b638357e75e5cd.tar.bz2 GT5-Unofficial-f6599e799922840f2e5c94d2c0b638357e75e5cd.zip |
Fix Computer Cube GUI.
Fix Glod's shitty implementation of perfect OC which broke some multis.
Diffstat (limited to 'src/main/java/gtPlusPlus/core/util')
-rw-r--r-- | src/main/java/gtPlusPlus/core/util/math/MathUtils.java | 131 |
1 files changed, 71 insertions, 60 deletions
diff --git a/src/main/java/gtPlusPlus/core/util/math/MathUtils.java b/src/main/java/gtPlusPlus/core/util/math/MathUtils.java index 7573e0d51c..5c7a5bac6d 100644 --- a/src/main/java/gtPlusPlus/core/util/math/MathUtils.java +++ b/src/main/java/gtPlusPlus/core/util/math/MathUtils.java @@ -16,12 +16,12 @@ public class MathUtils { final static Random rand = CORE.RANDOM; - /** Formats a number with group separator and at most 2 fraction digits. */ - private static final NumberFormat sNumberFormat = NumberFormat.getInstance(); - - static { - sNumberFormat.setMaximumFractionDigits(2); - } + /** Formats a number with group separator and at most 2 fraction digits. */ + private static final NumberFormat sNumberFormat = NumberFormat.getInstance(); + + static { + sNumberFormat.setMaximumFractionDigits(2); + } /** * Returns a psuedo-random number between min and max, inclusive. @@ -554,7 +554,7 @@ public class MathUtils { return 0; } } - + public static <V> V safeCast(Object aNumberType) { long a1; double a2; @@ -573,7 +573,7 @@ public class MathUtils { String s = ""+a1; Short s1 = Short.valueOf(s); return (V) s1; - + } } else if ((aNumberType.getClass() == int.class) || (aNumberType instanceof Integer)){ @@ -581,7 +581,7 @@ public class MathUtils { String s = ""+a1; Integer s1 = Integer.valueOf(s); return (V) s1; - + } } else if ((aNumberType.getClass() == long.class) || (aNumberType instanceof Long)){ @@ -596,7 +596,7 @@ public class MathUtils { String s = ""+a1; Float s1 = Float.valueOf(s); return (V) s1; - + } } else if ((aNumberType.getClass() == double.class) || (aNumberType instanceof Double)){ @@ -604,40 +604,40 @@ public class MathUtils { String s = ""+a1; Double s1 = Double.valueOf(s); return (V) s1; - + } } - + Integer o = 0; return (V) o; - + } - + public static byte getSafeByte(Byte b) { Byte a = safeCast(b); return a.byteValue(); } - + public static short getSafeShort(Short b) { Short a = safeCast(b); return a.shortValue(); } - + public static int getSafeInt(Integer b) { Integer a = safeCast(b); return a.intValue(); } - + public static long getSafeLong(Long b) { Long a = safeCast(b); return a.longValue(); } - + public static float getSafeFloat(Float b) { Float a = safeCast(b); return a.floatValue(); } - + public static double getSafeDouble(Double b) { Double a = safeCast(b); return a.doubleValue(); @@ -699,7 +699,7 @@ public class MathUtils { public static int balance(int aInput, int aMin, int aMax) { return Math.max(Math.min(aInput, aMax), aMin); } - + /** * Balances a number within a range. * @param aInput - The number to balance @@ -710,7 +710,7 @@ public class MathUtils { public static Number balance(Number aInput, Number aMin, Number aMax) { return max(min(aInput, aMax), aMin); } - + /** * Balances a number within a range. * @param aInput - The number to balance @@ -721,7 +721,7 @@ public class MathUtils { public static int balanceInt(Number aInput, Number aMin, Number aMax) { return MathUtils.safeCast_LongToInt((long) balance(max(min(aInput, aMax), aMin), Integer.MIN_VALUE, Integer.MAX_VALUE)); } - + /** * Balances a number within a range. * @param aInput - The number to balance @@ -737,51 +737,62 @@ public class MathUtils { int aAmount = Math.max(Math.min(i, aMax), aMin); return aAmount; } - + public static Pair<Integer, Integer> splitLongIntoIntegers(long aLong){ int aIntMaxInLong = (int) Math.min(Integer.MAX_VALUE, Math.floor(aLong/Integer.MAX_VALUE)); int aRemainder = (int) (aLong - (aIntMaxInLong * Integer.MAX_VALUE)); return new Pair<Integer, Integer>(aIntMaxInLong, aRemainder); } - - - /** - * Returns the smaller of two {@code Number}s. That is, - * the result the argument closer to the value of - * {@link Long#MIN_VALUE}. If the arguments have the same - * value, the result is that same value. - * - * @param a an argument. - * @param b another argument. - * @return the smaller of {@code a} and {@code b}. - */ - public static Number min(Number a, Number b) { - return (a.longValue() <= b.longValue()) ? a : b; - } - - /** - * Returns the greater of two {@code Number}s. That is, the - * result is the argument closer to the value of - * {@link Long#MAX_VALUE}. If the arguments have the same value, - * the result is that same value. - * - * @param a an argument. - * @param b another argument. - * @return the larger of {@code a} and {@code b}. - */ - public static Number max(Number a, Number b) { - return (a.longValue() >= b.longValue()) ? a : b; - } - - public static String formatNumbers(long aNumber) { - return sNumberFormat.format(aNumber); - } - - public static String formatNumbers(double aNumber) { - return sNumberFormat.format(aNumber); - } + + + /** + * Returns the smaller of two {@code Number}s. That is, + * the result the argument closer to the value of + * {@link Long#MIN_VALUE}. If the arguments have the same + * value, the result is that same value. + * + * @param a an argument. + * @param b another argument. + * @return the smaller of {@code a} and {@code b}. + */ + public static Number min(Number a, Number b) { + return (a.longValue() <= b.longValue()) ? a : b; + } + + /** + * Returns the greater of two {@code Number}s. That is, the + * result is the argument closer to the value of + * {@link Long#MAX_VALUE}. If the arguments have the same value, + * the result is that same value. + * + * @param a an argument. + * @param b another argument. + * @return the larger of {@code a} and {@code b}. + */ + public static Number max(Number a, Number b) { + return (a.longValue() >= b.longValue()) ? a : b; + } + + public static long combineTwoIntegersToLong(int a, int b) { + long val = (((long) a) << 32) | (b & 0xffffffffL); + return val; + } + public static int[] splitLongIntoTwoIntegers(long aNum) { + int a = (int) (aNum >> 32); + int b = (int) aNum; + return new int[] {a, b}; + } + + public static String formatNumbers(long aNumber) { + return sNumberFormat.format(aNumber); + } + + public static String formatNumbers(double aNumber) { + return sNumberFormat.format(aNumber); + } + } |