Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/utils/DoubleUtil.java @ 8856:5e38e2924c07 3.2.x
Fix code style.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 18 Jan 2018 20:12:01 +0100 |
parents | b486812f4f14 |
children | 8aa1605e58f1 0a5239a1e46e |
comparison
equal
deleted
inserted
replaced
8855:d7c005e12af0 | 8856:5e38e2924c07 |
---|---|
47 public static final double EPSILON = 1e-4; | 47 public static final double EPSILON = 1e-4; |
48 | 48 |
49 private DoubleUtil() { | 49 private DoubleUtil() { |
50 } | 50 } |
51 | 51 |
52 public static final double [] explode(double from, double to, double step) { | 52 public static final double [] explode( |
53 double from, | |
54 double to, | |
55 double step | |
56 ) { | |
53 return explode(from, to, step, DEFAULT_STEP_PRECISION); | 57 return explode(from, to, step, DEFAULT_STEP_PRECISION); |
54 } | 58 } |
55 | 59 |
56 public static final double round(double x, double precision) { | 60 public static final double round(double x, double precision) { |
57 return Math.round(x * precision)/precision; | 61 return Math.round(x * precision)/precision; |
60 public static final double round(double x) { | 64 public static final double round(double x) { |
61 return Math.round(x * DEFAULT_STEP_PRECISION)/DEFAULT_STEP_PRECISION; | 65 return Math.round(x * DEFAULT_STEP_PRECISION)/DEFAULT_STEP_PRECISION; |
62 } | 66 } |
63 | 67 |
64 /** | 68 /** |
65 * Returns array with values from parameter from to to with given step width. | 69 * Returns array with values from parameter from to to |
70 * with given step width. | |
66 * from and to are included. | 71 * from and to are included. |
67 */ | 72 */ |
68 public static final double [] explode( | 73 public static final double [] explode( |
69 double from, | 74 double from, |
70 double to, | 75 double to, |
314 } | 319 } |
315 | 320 |
316 /** Convieniance function for results to get an interpolator. | 321 /** Convieniance function for results to get an interpolator. |
317 * This is basically a static wrapper to for LinearInterpolator.interpolate | 322 * This is basically a static wrapper to for LinearInterpolator.interpolate |
318 * with error handling. Returns null on error.*/ | 323 * with error handling. Returns null on error.*/ |
319 public static PolynomialSplineFunction getLinearInterpolator(double[] x, double[] y) { | 324 public static PolynomialSplineFunction getLinearInterpolator( |
320 /* We want copies here to remove NaNs but don't change the original data. */ | 325 double[] x, |
326 double[] y | |
327 ) { | |
328 /* We want copies here to remove NaNs but don't | |
329 * change the original data. */ | |
321 TDoubleArrayList tX = new TDoubleArrayList(); | 330 TDoubleArrayList tX = new TDoubleArrayList(); |
322 TDoubleArrayList tY = new TDoubleArrayList(); | 331 TDoubleArrayList tY = new TDoubleArrayList(); |
323 for (int i = 0; i < x.length; i++) { | 332 for (int i = 0; i < x.length; i++) { |
324 if (!Double.isNaN(y[i])) { | 333 if (!Double.isNaN(y[i])) { |
325 tX.add(x[i]); | 334 tX.add(x[i]); |
328 } | 337 } |
329 LinearInterpolator lpol = new LinearInterpolator(); | 338 LinearInterpolator lpol = new LinearInterpolator(); |
330 try { | 339 try { |
331 return lpol.interpolate(tX.toNativeArray(), tY.toNativeArray()); | 340 return lpol.interpolate(tX.toNativeArray(), tY.toNativeArray()); |
332 } catch (DimensionMismatchException e) { | 341 } catch (DimensionMismatchException e) { |
333 log.error("KMs and Result values have different sizes. Failed to interpolate: " + | 342 log.error("KMs and Result values have different sizes. " |
334 e.getMessage()); | 343 + "Failed to interpolate: " |
344 + e.getMessage()); | |
335 } catch (NonMonotonousSequenceException e) { | 345 } catch (NonMonotonousSequenceException e) { |
336 log.error("KMs are not monotonous. Failed to interpolate: " + e.getMessage()); | 346 log.error("KMs are not monotonous. Failed to interpolate: " |
347 + e.getMessage()); | |
337 } catch (NumberIsTooSmallException e) { | 348 } catch (NumberIsTooSmallException e) { |
338 log.error("Result is to small. Failed to interpolate: " + e.getMessage()); | 349 log.error("Result is to small. Failed to interpolate: " |
350 + e.getMessage()); | |
339 } | 351 } |
340 return null; | 352 return null; |
341 } | 353 } |
342 | 354 |
343 public static PolynomialSplineFunction getLinearInterpolator(TDoubleArrayList x, TDoubleArrayList y) { | 355 public static PolynomialSplineFunction getLinearInterpolator( |
356 TDoubleArrayList x, | |
357 TDoubleArrayList y | |
358 ) { | |
344 return getLinearInterpolator(x.toNativeArray(), y.toNativeArray()); | 359 return getLinearInterpolator(x.toNativeArray(), y.toNativeArray()); |
345 } | 360 } |
346 } | 361 } |
347 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 362 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |