aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util/math
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2017-03-04 12:58:47 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2017-03-04 12:58:47 +1000
commitae21012d216df71f31aed6fbc9d76215fc24ceed (patch)
treecc89accbe6ce5c04b72ed3c5e46b2a185f88be6a /src/Java/gtPlusPlus/core/util/math
parentba89972a22a316030f8c3bd99974f915b1d7aefc (diff)
downloadGT5-Unofficial-ae21012d216df71f31aed6fbc9d76215fc24ceed.tar.gz
GT5-Unofficial-ae21012d216df71f31aed6fbc9d76215fc24ceed.tar.bz2
GT5-Unofficial-ae21012d216df71f31aed6fbc9d76215fc24ceed.zip
+ New texture for the slow builders ring.
+ Added the Alkalus Disk. $ Fixed Frame Box Assembler Recipes. $ Fixed Missing 7Li material. $ Fixed Tiered Tanks not showing their capacity in the tooltip. $ Fixed tooltips for alloys containing Bronze or Steel. $ Fixed Clay Pipe Extruder Recipes. - Removed a handful of Plasma cells for misc. materials. % Changed the Industrial Coke Oven's tooltip, to better describe the input/output requirements. % Cleaned up The Entire Project.
Diffstat (limited to 'src/Java/gtPlusPlus/core/util/math')
-rw-r--r--src/Java/gtPlusPlus/core/util/math/MathUtils.java236
1 files changed, 120 insertions, 116 deletions
diff --git a/src/Java/gtPlusPlus/core/util/math/MathUtils.java b/src/Java/gtPlusPlus/core/util/math/MathUtils.java
index 96231fb29c..3c04266f38 100644
--- a/src/Java/gtPlusPlus/core/util/math/MathUtils.java
+++ b/src/Java/gtPlusPlus/core/util/math/MathUtils.java
@@ -1,10 +1,10 @@
package gtPlusPlus.core.util.math;
-import gtPlusPlus.core.util.Utils;
-
import java.util.Map;
import java.util.Random;
+import gtPlusPlus.core.util.Utils;
+
public class MathUtils {
/**
@@ -17,24 +17,24 @@ public class MathUtils {
* @return Integer between min and max, inclusive.
* @see java.util.Random#nextInt(int)
*/
- public static int randInt(int min, int max) {
+ public static int randInt(final int min, final int max) {
// Usually this can be a field rather than a method variable
- Random rand = new Random();
+ final Random rand = new Random();
// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
- int randomNum = rand.nextInt((max - min) + 1) + min;
+ final int randomNum = rand.nextInt((max - min) + 1) + min;
return randomNum;
}
-
- public static double getChanceOfXOverYRuns(double x, double y){
- double z = (1-Math.pow((1-x), y));
- return z;
+
+ public static double getChanceOfXOverYRuns(final double x, final double y){
+ final double z = (1-Math.pow((1-x), y));
+ return z;
}
-
-
+
+
/**
* Returns a psuedo-random number between min and max, inclusive.
* The difference between min and max can be at most
@@ -45,27 +45,27 @@ public class MathUtils {
* @return Long between min and max, inclusive.
* @see java.util.Random#nextLong(long)
*/
- public static long randLong(long min, long max) {
+ public static long randLong(final long min, final long max) {
// Usually this can be a field rather than a method variable
- Random rand = new Random();
+ final Random rand = new Random();
// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
- long randomNum = MathUtils.nextLong(rand,(max - min) + 1) + min;
+ final long randomNum = MathUtils.nextLong(rand,(max - min) + 1) + min;
return randomNum;
}
- private static long nextLong(Random rng, long n) {
+ private static long nextLong(final Random rng, final long n) {
// error checking and 2^x checking removed for simplicity.
long bits, val;
do {
bits = (rng.nextLong() << 1) >>> 1;
val = bits % n;
- } while (bits-val+(n-1) < 0L);
+ } while (((bits-val)+(n-1)) < 0L);
return val;
}
-
-
+
+
/**
* Returns a psuedo-random number between min and max, inclusive.
* The difference between min and max can be at most
@@ -76,26 +76,26 @@ public class MathUtils {
* @return Double between min and max, inclusive.
* @see java.util.Random#nextDouble(double)
*/
- public static double randDouble(double min, double max) {
+ public static double randDouble(final double min, final double max) {
// Usually this can be a field rather than a method variable
- Random rand = new Random();
+ final Random rand = new Random();
// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
- double randomNum = MathUtils.nextDouble(rand,(max - min) + 1) + min;
+ final double randomNum = MathUtils.nextDouble(rand,(max - min) + 1) + min;
return randomNum;
}
-
- private static double nextDouble(Random rng, double n) {
+
+ private static double nextDouble(final Random rng, final double n) {
// error checking and 2^x checking removed for simplicity.
double bits, val;
do {
bits = (rng.nextLong() << 1) >>> 1;
val = bits % n;
- } while (bits-val+(n-1) < 0L);
+ } while (((bits-val)+(n-1)) < 0L);
return val;
}
-
+
/**
* Returns a percentage.
@@ -104,14 +104,14 @@ public class MathUtils {
*
* @param current Current value.
* @param max Maximim value. Must be greater than min.
- * @return double between min and max, inclusive.
+ * @return double between min and max, inclusive.
*/
- public static double findPercentage(double current, double max){
- double c = ((double) current / max) * 100;
- double roundOff = Math.round(c * 100.00) / 100.00;
+ public static double findPercentage(final double current, final double max){
+ final double c = (current / max) * 100;
+ final double roundOff = Math.round(c * 100.00) / 100.00;
return roundOff;
}
-
+
//Smooth Rounding Function
/**
@@ -120,12 +120,12 @@ public class MathUtils {
* Supports Doubles.
*
* @param current Current value.
- * @return double Rounded value.
+ * @return double Rounded value.
*/
- public static double decimalRounding(double d) {
+ public static double decimalRounding(final double d) {
return Math.round(d * 2) / 2.0;
}
-
+
//Smooth Rounding Function (Nearest 5)
/**
@@ -134,39 +134,39 @@ public class MathUtils {
* Supports Doubles.
*
* @param current Current value.
- * @return double Rounded value.
+ * @return double Rounded value.
*/
- public static double decimalRoundingToWholes(double d) {
+ public static double decimalRoundingToWholes(final double d) {
return 5*(Math.round(d/5));
}
-
+
//Smooth Rounding Function
- /**
- * Returns a integer.
- * The returned number is d rounded to the nearest flat integer.
- * Supports Doubles as input.
- *
- * @param current Current value.
- * @return integer Rounded value.
- */
- public static int roundToClosestInt(double d) {
- return (int) (Math.round(d * 2) / 2.0);
+ /**
+ * Returns a integer.
+ * The returned number is d rounded to the nearest flat integer.
+ * Supports Doubles as input.
+ *
+ * @param current Current value.
+ * @return integer Rounded value.
+ */
+ public static int roundToClosestInt(final double d) {
+ return (int) (Math.round(d * 2) / 2.0);
+ }
+
+ public static int roundToClosestMultiple(final double number, final int multiple) {
+ int result = multiple;
+ if ((number % multiple) == 0) {
+ return (int) number;
+ }
+ // If not already multiple of given number
+ if ((number % multiple) != 0) {
+ final int division = (int) ((number / multiple) + 1);
+ result = division * multiple;
}
-
- public static int roundToClosestMultiple(double number, int multiple) {
- int result = multiple;
- if (number % multiple == 0) {
- return (int) number;
- }
- // If not already multiple of given number
- if (number % multiple != 0) {
- int division = (int) ((number / multiple) + 1);
- result = division * multiple;
- }
- return result;
- }
-
-
+ return result;
+ }
+
+
/**
* Returns a boolean.
* The returned boolean is wether or not X evenly fits in to Y.
@@ -174,9 +174,9 @@ public class MathUtils {
*
* @param x Value A.
* @param y Value B. Must be greater than min.
- * @return boolean Whether or not it divides evenly.
+ * @return boolean Whether or not it divides evenly.
*/
- public static boolean divideXintoY(int x, int y){
+ public static boolean divideXintoY(final int x, final int y){
if ((x % y) == 0)
{
return true;
@@ -184,16 +184,16 @@ public class MathUtils {
return false;
}
-
+
/**
* Returns a boolean.
* The returned boolean is based on the odd/eveness of the input.
* Supports ints.
*
* @param x Value A.
- * @return boolean Whether or not it divides evenly.
+ * @return boolean Whether or not it divides evenly.
*/
- public static boolean isNumberEven(int x){
+ public static boolean isNumberEven(final int x){
if ((x % 2) == 0)
{
return true;
@@ -201,7 +201,7 @@ public class MathUtils {
return false;
}
-
+
/**
* Returns an int.
@@ -209,13 +209,13 @@ public class MathUtils {
* Supports ints.
*
* @param i Temp in Celcius.
- * @return int The celcius temp returned as Kelvin, rounded to the readest whole.
+ * @return int The celcius temp returned as Kelvin, rounded to the readest whole.
*/
- public static float celsiusToKelvin(int i){
- double f = i + 273.15F;
+ public static float celsiusToKelvin(final int i){
+ final double f = i + 273.15F;
return (int)decimalRoundingToWholes(f);
}
-
+
/**
* Returns a hexInteger.
@@ -223,14 +223,14 @@ public class MathUtils {
* Supports ints.
*
* @param input Current value.
- * @return hexInteger.
+ * @return hexInteger.
*/
- public static int getHexNumberFromInt(int input){
- String result = Integer.toHexString(input);
- int resultINT = Integer.getInteger(result);
+ public static int getHexNumberFromInt(final int input){
+ final String result = Integer.toHexString(input);
+ final int resultINT = Integer.getInteger(result);
return resultINT;
}
-
+
/**
* Returns a hexInteger.
@@ -239,80 +239,84 @@ public class MathUtils {
*
* @param min Minimum value.
* @param max Maximium value. Must be greater than min.
- * @return hexInteger between min and max, inclusive.
+ * @return hexInteger between min and max, inclusive.
*/
- public static int generateRandomHexValue(int min, int max){
- int result = getHexNumberFromInt(randInt(min, max));
+ public static int generateRandomHexValue(final int min, final int max){
+ final int result = getHexNumberFromInt(randInt(min, max));
return result;
}
-
+
/**
* Returns a random hex value.
* The returned value is between 000000-ffffff.
*
- * @return hexInteger between min and max, inclusive.
+ * @return hexInteger between min and max, inclusive.
*/
public static int generateSingularRandomHexValue(){
String temp;
- int randomInt = randInt(1, 5);
+ final int randomInt = randInt(1, 5);
final Map<Integer, String> colours = Utils.hexColourGeneratorRandom(5);
- if (colours.get(randomInt) != null && colours.size() > 0){
- temp = colours.get(randomInt);
+ if ((colours.get(randomInt) != null) && (colours.size() > 0)){
+ temp = colours.get(randomInt);
}
else {
- temp = "0F0F0F";
+ temp = "0F0F0F";
}
- Utils.LOG_WARNING("Operating with "+temp);
+ Utils.LOG_WARNING("Operating with "+temp);
temp = Utils.appenedHexNotationToString(String.valueOf(temp));
Utils.LOG_WARNING("Made "+temp+" - Hopefully it's not a mess.");
Utils.LOG_WARNING("It will decode into "+Integer.decode(temp)+".");
return Integer.decode(temp);
}
-
- public static long[] simplifyNumbersToSmallestForm(long[] inputArray){
- long GCD = gcd(inputArray);
- long[] outputArray = new long[inputArray.length];
+
+ public static long[] simplifyNumbersToSmallestForm(final long[] inputArray){
+ final long GCD = gcd(inputArray);
+ final long[] outputArray = new long[inputArray.length];
for (int i=0;i<inputArray.length;i++){
- if (GCD != 0)
- outputArray[i] = (inputArray[i]/GCD);
- else
+ if (GCD != 0) {
+ outputArray[i] = (inputArray[i]/GCD);
+ } else {
outputArray[i] = inputArray[i];
+ }
+ }
+ if (outputArray.length > 0) {
+ return outputArray;
}
- if (outputArray.length > 0)
- return outputArray;
return null;
}
-
+
private static long gcd(long a, long b){
- while (b > 0)
- {
- long temp = b;
- b = a % b; // % is remainder
- a = temp;
- }
- return a;
+ while (b > 0)
+ {
+ final long temp = b;
+ b = a % b; // % is remainder
+ a = temp;
+ }
+ return a;
}
-
- private static long gcd(long[] input){
- long result = input[0];
- for(int i = 1; i < input.length; i++) result = gcd(result, input[i]);
- return result;
+
+ private static long gcd(final long[] input){
+ long result = input[0];
+ for(int i = 1; i < input.length; i++) {
+ result = gcd(result, input[i]);
+ }
+ return result;
}
-
- final public static int getRgbAsHex(short[] RGBA){
- int returnValue = Utils.rgbtoHexValue(RGBA[0], RGBA[1], RGBA[2]);
+ final public static int getRgbAsHex(final short[] RGBA){
+
+ final int returnValue = Utils.rgbtoHexValue(RGBA[0], RGBA[1], RGBA[2]);
if (returnValue == 0){
- return (int) 0;
- }
+ return 0;
+ }
return Utils.rgbtoHexValue(RGBA[0], RGBA[1], RGBA[2]);
}
-
-
- public final static int returnLargestNumber(int a, int b){
+
+
+ public final static int returnLargestNumber(final int a, final int b){
if (a > b){
return a;
}