annotate flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java @ 1668:6566c7868456

Added facet and index information to theme which are stored at CollectionItems. flys-artifacts/trunk@2880 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 04 Oct 2011 11:28:37 +0000
parents 09c1292cf36d
children da872168a899
rev   line source
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.utils;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
1666
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
3 import java.util.Arrays;
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
4
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
5
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 public class DoubleUtil
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 public static final double DEFAULT_STEP_PRECISION = 1e6;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 private DoubleUtil() {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 public static final double [] explode(double from, double to, double step) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 return explode(from, to, step, DEFAULT_STEP_PRECISION);
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 public static final double round(double x, double precision) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 return Math.round(x * precision)/precision;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 public static final double round(double x) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 return Math.round(x * DEFAULT_STEP_PRECISION)/DEFAULT_STEP_PRECISION;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 public static final double [] explode(
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 double from,
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 double to,
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 double step,
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 double precision
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 ) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 double lower = from;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 double diff = to - from;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 double tmp = diff / step;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 int num = (int)Math.abs(Math.ceil(tmp)) + 1;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 double [] values = new double[num];
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 if (from > to) {
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 step = -step;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
1666
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
43 double max = Math.max(from, to);
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
44
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 for (int idx = 0; idx < num; idx++) {
1666
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
46 if (lower > max) {
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
47 return Arrays.copyOfRange(values, 0, idx);
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
48 }
09c1292cf36d Bugfix: #351 Modified determination of single values specified by min/max values and an interval.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 655
diff changeset
49
655
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 values[idx] = round(lower, precision);
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 lower += step;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 return values;
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 }
913b52064449 Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org