diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-08-24 16:34:38 +0100 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-08-24 16:34:38 +0100 |
commit | 5f455188ce11c975ced96d8364624af540dd276b (patch) | |
tree | 498359404ed74a738f31bab4df3ca7b4ac22a6a9 /src/Java/gtPlusPlus/core | |
parent | 043b16e0c10674e606885d6586e3448803eb2f23 (diff) | |
download | GT5-Unofficial-5f455188ce11c975ced96d8364624af540dd276b.tar.gz GT5-Unofficial-5f455188ce11c975ced96d8364624af540dd276b.tar.bz2 GT5-Unofficial-5f455188ce11c975ced96d8364624af540dd276b.zip |
+ Added some more generic language strings.
- Removed maintenance requirement from Cyclotron.
% More work on new Multiblock GUIs.
$ Potentially fixed #507.
Diffstat (limited to 'src/Java/gtPlusPlus/core')
-rw-r--r-- | src/Java/gtPlusPlus/core/util/math/MathUtils.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/util/math/MathUtils.java b/src/Java/gtPlusPlus/core/util/math/MathUtils.java index bda722b47e..a9f7b901ef 100644 --- a/src/Java/gtPlusPlus/core/util/math/MathUtils.java +++ b/src/Java/gtPlusPlus/core/util/math/MathUtils.java @@ -692,6 +692,39 @@ 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 + * @param aMin - The minimum bounds + * @param aMax - The maximum bounds + * @return - A Number which will be between the bounds, or a boundary value. + */ + 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 + * @param aMin - The minimum bounds + * @param aMax - The maximum bounds + * @return - An Integer which will be between the bounds, or a boundary value. + */ + 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 + * @param aMin - The minimum bounds + * @param aMax - The maximum bounds + * @return - A Long which will be between the bounds, or a boundary value. + */ + public static long balanceLong(Number aInput, Number aMin, Number aMax) { + return (long) balance(max(min(aInput, aMax), aMin), Long.MIN_VALUE, Long.MAX_VALUE); + } public static int getValueWithinRange(int i, int aMin, int aMax) { int aAmount = Math.max(Math.min(i, aMax), aMin); @@ -703,5 +736,37 @@ public class MathUtils { 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; + } + } |