InputStream
. The file is read using
* the default charset returned by {@link #getDefaultCharset()}.
@@ -330,28 +171,7 @@ public abstract class MotorLoader implements Loader
+ * This method is about 4 times faster than Math.signum().
+ *
+ * @param x the checked value.
+ * @return -1.0 if x<0; 1.0 if x>0; otherwise either -1.0 or 1.0.
+ */
public static double sign(double x) {
return (x<0) ? -1.0 : 1.0;
}
@@ -180,38 +190,4 @@ public class MathUtil {
*/
- public static void main(String[] arg) {
- double nan = Double.NaN;
- System.out.println("min(5,6) = " + min(5, 6));
- System.out.println("min(5,nan) = " + min(5, nan));
- System.out.println("min(nan,6) = " + min(nan, 6));
- System.out.println("min(nan,nan) = " + min(nan, nan));
- System.out.println();
- System.out.println("max(5,6) = " + max(5, 6));
- System.out.println("max(5,nan) = " + max(5, nan));
- System.out.println("max(nan,6) = " + max(nan, 6));
- System.out.println("max(nan,nan) = " + max(nan, nan));
- System.out.println();
- System.out.println("min(5,6,7) = " + min(5, 6, 7));
- System.out.println("min(5,6,nan) = " + min(5, 6, nan));
- System.out.println("min(5,nan,7) = " + min(5, nan, 7));
- System.out.println("min(5,nan,nan) = " + min(5, nan, nan));
- System.out.println("min(nan,6,7) = " + min(nan, 6, 7));
- System.out.println("min(nan,6,nan) = " + min(nan, 6, nan));
- System.out.println("min(nan,nan,7) = " + min(nan, nan, 7));
- System.out.println("min(nan,nan,nan) = " + min(nan, nan, nan));
- System.out.println();
- System.out.println("max(5,6,7) = " + max(5, 6, 7));
- System.out.println("max(5,6,nan) = " + max(5, 6, nan));
- System.out.println("max(5,nan,7) = " + max(5, nan, 7));
- System.out.println("max(5,nan,nan) = " + max(5, nan, nan));
- System.out.println("max(nan,6,7) = " + max(nan, 6, 7));
- System.out.println("max(nan,6,nan) = " + max(nan, 6, nan));
- System.out.println("max(nan,nan,7) = " + max(nan, nan, 7));
- System.out.println("max(nan,nan,nan) = " + max(nan, nan, nan));
- System.out.println();
-
-
- }
-
}
diff --git a/src/net/sf/openrocket/util/Prefs.java b/src/net/sf/openrocket/util/Prefs.java
index 0ca273f65..049b54683 100644
--- a/src/net/sf/openrocket/util/Prefs.java
+++ b/src/net/sf/openrocket/util/Prefs.java
@@ -55,6 +55,7 @@ public class Prefs {
private static final String BUILD_VERSION;
private static final String BUILD_SOURCE;
+ public static final String DEFAULT_BUILD_SOURCE = "default";
static {
try {
diff --git a/src/net/sf/openrocket/util/Rotation2D.java b/src/net/sf/openrocket/util/Rotation2D.java
index f8f063e8d..1672a0114 100644
--- a/src/net/sf/openrocket/util/Rotation2D.java
+++ b/src/net/sf/openrocket/util/Rotation2D.java
@@ -41,18 +41,4 @@ public class Rotation2D {
return new Coordinate(cos*c.x + sin*c.y, cos*c.y - sin*c.x, c.z, c.weight);
}
-
-
- public static void main(String arg[]) {
- Coordinate c = new Coordinate(1,1,1,2.5);
- Rotation2D rot = new Rotation2D(Math.PI/4);
-
- System.out.println("X: "+rot.rotateX(c));
- System.out.println("Y: "+rot.rotateY(c));
- System.out.println("Z: "+rot.rotateZ(c));
- System.out.println("invX: "+rot.invRotateX(c));
- System.out.println("invY: "+rot.invRotateY(c));
- System.out.println("invZ: "+rot.invRotateZ(c));
- }
-
}
diff --git a/src/net/sf/openrocket/util/Test.java b/src/net/sf/openrocket/util/Test.java
index 4d150d42d..c0e37c7ac 100644
--- a/src/net/sf/openrocket/util/Test.java
+++ b/src/net/sf/openrocket/util/Test.java
@@ -2,6 +2,7 @@ package net.sf.openrocket.util;
import net.sf.openrocket.database.Databases;
import net.sf.openrocket.material.Material;
+import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.rocketcomponent.BodyTube;
import net.sf.openrocket.rocketcomponent.Bulkhead;
import net.sf.openrocket.rocketcomponent.CenteringRing;
@@ -10,7 +11,6 @@ import net.sf.openrocket.rocketcomponent.IllegalFinPointException;
import net.sf.openrocket.rocketcomponent.InnerTube;
import net.sf.openrocket.rocketcomponent.LaunchLug;
import net.sf.openrocket.rocketcomponent.MassComponent;
-import net.sf.openrocket.rocketcomponent.Motor;
import net.sf.openrocket.rocketcomponent.NoseCone;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.Stage;
diff --git a/src/net/sf/openrocket/util/TextUtil.java b/src/net/sf/openrocket/util/TextUtil.java
index fdbf99128..7d2ee8535 100644
--- a/src/net/sf/openrocket/util/TextUtil.java
+++ b/src/net/sf/openrocket/util/TextUtil.java
@@ -1,16 +1,13 @@
package net.sf.openrocket.util;
-import java.util.Locale;
public class TextUtil {
/**
- * Return a string of the double value with suitable precision.
+ * Return a string of the double value with suitable precision (5 digits).
* The string is the shortest representation of the value including the
* required precision.
*
- * TODO: MEDIUM: Extra zeros are added unnecessarily to the end of the string.
- *
* @param d the value to present.
* @return a representation with suitable precision.
*/
@@ -31,46 +28,106 @@ public class TextUtil {
}
+ final String sign = (d < 0) ? "-" : "";
double abs = Math.abs(d);
- if (abs < 0.001) {
- // Compact exponential notation
- int exp = 0;
-
- while (abs < 1.0) {
- abs *= 10;
- exp++;
- }
-
- String sign = (d < 0) ? "-" : "";
- return sign + String.format((Locale)null, "%.4fe-%d", abs, exp);
+ // Small and large values always in exponential notation
+ if (abs < 0.001 || abs >= 100000000) {
+ return sign + exponentialFormat(abs);
}
- if (abs < 0.01)
- return String.format((Locale)null, "%.7f", d);
- if (abs < 0.1)
- return String.format((Locale)null, "%.6f", d);
- if (abs < 1)
- return String.format((Locale)null, "%.5f", d);
- if (abs < 10)
- return String.format((Locale)null, "%.4f", d);
- if (abs < 100)
- return String.format((Locale)null, "%.3f", d);
- if (abs < 1000)
- return String.format((Locale)null, "%.2f", d);
- if (abs < 10000)
- return String.format((Locale)null, "%.1f", d);
- if (abs < 100000000.0)
- return String.format((Locale)null, "%.0f", d);
-
- // Compact exponential notation
- int exp = 0;
- while (abs >= 10.0) {
- abs /= 10;
+
+ // Check whether decimal or exponential notation is shorter
+
+ String exp = exponentialFormat(abs);
+ String dec = decimalFormat(abs);
+
+ if (dec.length() <= exp.length())
+ return sign + dec;
+ else
+ return sign + exp;
+ }
+
+
+ /*
+ * value must be positive and not zero!
+ */
+ private static String exponentialFormat(double value) {
+ int exp;
+
+ exp = 0;
+ while (value < 1.0) {
+ value *= 10;
+ exp--;
+ }
+ while (value >= 10.0) {
+ value /= 10;
exp++;
}
- String sign = (d < 0) ? "-" : "";
- return sign + String.format((Locale)null, "%.4fe%d", abs, exp);
+ return shortDecimal(value, 4) + "e" + exp;
+ }
+
+
+ /*
+ * value must be positive and not zero!
+ */
+ private static String decimalFormat(double value) {
+ if (value >= 10000)
+ return "" + (int)(value + 0.5);
+
+ int decimals = 1;
+ double v = value;
+ while (v < 1000) {
+ v *= 10;
+ decimals++;
+ }
+
+ return shortDecimal(value, decimals);
+ }
+
+
+
+
+ /*
+ * value must be positive!
+ */
+ private static String shortDecimal(double value, int decimals) {
+
+ int whole = (int)value;
+ value -= whole;
+
+ // Calculate limit, return when remaining value less than this
+ double limit;
+ limit = 0.5;
+ for (int i=0; i