X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fnet%2Fsf%2Fopenrocket%2Ffile%2FOpenRocketSaver.java;h=de41cb0ca4efc7a2194111eb1d3b6f1ff01eae97;hb=6afc62224f6f7e581b1d321e125ed97a6ec77dc1;hp=d7a7eba1df52a87e2692ab8d2962c5bf9e20e7e9;hpb=800e211417d977c55c8fddcc175ec8c74793f51b;p=debian%2Fopenrocket diff --git a/src/net/sf/openrocket/file/OpenRocketSaver.java b/src/net/sf/openrocket/file/OpenRocketSaver.java index d7a7eba1..de41cb0c 100644 --- a/src/net/sf/openrocket/file/OpenRocketSaver.java +++ b/src/net/sf/openrocket/file/OpenRocketSaver.java @@ -8,7 +8,6 @@ import java.io.Writer; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Locale; import java.util.zip.GZIPOutputStream; import net.sf.openrocket.aerodynamics.Warning; @@ -21,10 +20,10 @@ import net.sf.openrocket.simulation.FlightData; import net.sf.openrocket.simulation.FlightDataBranch; import net.sf.openrocket.simulation.FlightEvent; import net.sf.openrocket.simulation.SimulationConditions; -import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.Pair; import net.sf.openrocket.util.Prefs; import net.sf.openrocket.util.Reflection; +import net.sf.openrocket.util.TextUtil; public class OpenRocketSaver extends RocketSaver { @@ -131,8 +130,10 @@ public class OpenRocketSaver extends RocketSaver { if (timeSkip != StorageOptions.SIMULATION_DATA_NONE) { for (Simulation s: doc.getSimulations()) { FlightData data = s.getSimulatedData(); - for (int i=0; i < data.getBranchCount(); i++) { - pointCount += countFlightDataBranchPoints(data.getBranch(i), timeSkip); + if (data != null) { + for (int i=0; i < data.getBranchCount(); i++) { + pointCount += countFlightDataBranchPoints(data.getBranch(i), timeSkip); + } } } } @@ -250,19 +251,19 @@ public class OpenRocketSaver extends RocketSaver { if (data != null) { String str = " p: branch.getEvents()) { - writeln(""); } @@ -414,7 +415,7 @@ public class OpenRocketSaver extends RocketSaver { for (int j=0; j < data.size(); j++) { if (j > 0) sb.append(","); - sb.append(doubleToString(data.get(j).get(index))); + sb.append(TextUtil.doubleToString(data.get(j).get(index))); } sb.append(""); writeln(sb.toString()); @@ -443,81 +444,12 @@ public class OpenRocketSaver extends RocketSaver { } - /** - * Return a string of the double value with suitable precision. - * The string is the shortest representation of the value including the - * required precision. - * - * @param d the value to present. - * @return a representation with suitable precision. - */ - public static final String doubleToString(double d) { - - // Check for special cases - if (MathUtil.equals(d, 0)) - return "0"; - - if (Double.isNaN(d)) - return "NaN"; - - if (Double.isInfinite(d)) { - if (d < 0) - return "-Inf"; - else - return "Inf"; - } - - - 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); - } - 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; - exp++; - } - - String sign = (d < 0) ? "-" : ""; - return sign + String.format((Locale)null, "%.4fe%d", abs, exp); - } - - - public static void main(String[] arg) { double d = -0.000000123456789123; for (int i=0; i< 20; i++) { - String str = doubleToString(d); + String str = TextUtil.doubleToString(d); System.out.println(str + " -> " + Double.parseDouble(str)); d *= 10; }