Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 634:d8c47520c726
Round exploded values to a precision of 1e-6.
flys-artifacts/trunk@2008 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 26 May 2011 09:41:57 +0000 |
parents | a9af60c84dca |
children | acf3b49ec31f |
comparison
equal
deleted
inserted
replaced
633:d08f77e7f7e8 | 634:d8c47520c726 |
---|---|
71 * range.*/ | 71 * range.*/ |
72 public static final int DEFAULT_Q_STEPS = 30; | 72 public static final int DEFAULT_Q_STEPS = 30; |
73 | 73 |
74 /** The default step width between the start end end kilometer.*/ | 74 /** The default step width between the start end end kilometer.*/ |
75 public static final double DEFAULT_KM_STEPS = 0.1; | 75 public static final double DEFAULT_KM_STEPS = 0.1; |
76 | |
77 public static final double DEFAULT_PRECISION = 1e6; | |
76 | 78 |
77 | 79 |
78 /** The identifier of the current state. */ | 80 /** The identifier of the current state. */ |
79 protected String currentStateId; | 81 protected String currentStateId; |
80 | 82 |
904 * @param to The upper value. | 906 * @param to The upper value. |
905 * @param step The step width between two values in the result array. | 907 * @param step The step width between two values in the result array. |
906 * | 908 * |
907 * @return an array of double values. | 909 * @return an array of double values. |
908 */ | 910 */ |
909 public static double[] getExplodedValues(double from, double to, double step) { | 911 public static double[] getExplodedValues( |
912 double from, | |
913 double to, | |
914 double step | |
915 ) { | |
916 return getExplodedValues(from, to, step, DEFAULT_PRECISION); | |
917 } | |
918 | |
919 public static double[] getExplodedValues( | |
920 double from, | |
921 double to, | |
922 double step, | |
923 double precision | |
924 ) { | |
910 double lower = from; | 925 double lower = from; |
911 | 926 |
912 double diff = to - from; | 927 double diff = to - from; |
913 double tmp = diff / step; | 928 double tmp = diff / step; |
914 int num = (int)Math.abs(Math.ceil(tmp)) + 1; | 929 int num = (int)Math.abs(Math.ceil(tmp)) + 1; |
915 | 930 |
916 double [] values = new double[num]; | 931 double [] values = new double[num]; |
917 | 932 |
918 for (int idx = 0; idx < num; idx++) { | 933 for (int idx = 0; idx < num; idx++) { |
919 values[idx] = lower; | 934 values[idx] = Math.round(lower * precision)/precision; |
920 lower += step; | 935 lower += step; |
921 } | 936 } |
922 | 937 |
923 return values; | 938 return values; |
924 } | 939 } |