comparison flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java @ 655:913b52064449

Refactored version of "Berechnung 4" flys-artifacts/trunk@2053 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 05 Jun 2011 18:24:46 +0000
parents
children 09c1292cf36d
comparison
equal deleted inserted replaced
654:bbc966c81809 655:913b52064449
1 package de.intevation.flys.utils;
2
3 public class DoubleUtil
4 {
5 public static final double DEFAULT_STEP_PRECISION = 1e6;
6
7 private DoubleUtil() {
8 }
9
10 public static final double [] explode(double from, double to, double step) {
11 return explode(from, to, step, DEFAULT_STEP_PRECISION);
12 }
13
14 public static final double round(double x, double precision) {
15 return Math.round(x * precision)/precision;
16 }
17
18 public static final double round(double x) {
19 return Math.round(x * DEFAULT_STEP_PRECISION)/DEFAULT_STEP_PRECISION;
20 }
21
22 public static final double [] explode(
23 double from,
24 double to,
25 double step,
26 double precision
27 ) {
28 double lower = from;
29
30 double diff = to - from;
31 double tmp = diff / step;
32 int num = (int)Math.abs(Math.ceil(tmp)) + 1;
33
34 double [] values = new double[num];
35
36 if (from > to) {
37 step = -step;
38 }
39
40 for (int idx = 0; idx < num; idx++) {
41 values[idx] = round(lower, precision);
42 lower += step;
43 }
44
45 return values;
46 }
47 }
48 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org