Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java @ 1745:4ae7df2a74ed
Fix NPE in WDiff-diagram because no ranges present in masterartifact.
flys-artifacts/trunk@3039 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 19 Oct 2011 16:06:01 +0000 |
parents | 0b6dac664bbb |
children | 0dd58ab7e118 |
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 |
1671
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
5 import de.intevation.flys.artifacts.math.Linear; |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
6 |
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
|
7 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 public class DoubleUtil |
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 public static final double DEFAULT_STEP_PRECISION = 1e6; |
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 private DoubleUtil() { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 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
|
16 return explode(from, to, step, DEFAULT_STEP_PRECISION); |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 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
|
20 return Math.round(x * precision)/precision; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 public static final double round(double x) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 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
|
25 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 public static final double [] explode( |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 double from, |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 double to, |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 double step, |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 double precision |
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 lower = from; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 double diff = to - from; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 double tmp = diff / step; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 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
|
38 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 double [] values = new double[num]; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 if (from > to) { |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 step = -step; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
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
|
45 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
|
46 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 } |
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
|
51 |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 values[idx] = round(lower, precision); |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 lower += step; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 } |
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 return values; |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 } |
1671
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
58 |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
59 public static final double interpolateSorted( |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
60 double [] xs, |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
61 double [] ys, |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
62 double x |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
63 ) { |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
64 int lo = 0, hi = xs.length-1; |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
65 |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
66 int mid = -1; |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
67 |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
68 while (lo <= hi) { |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
69 mid = (lo + hi) >> 1; |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
70 double mx = xs[mid]; |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
71 if (x < mx) hi = mid - 1; |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
72 else if (x > mx) lo = mid + 1; |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
73 else return ys[mid]; |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
74 } |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
75 if (mid < lo) { |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
76 return lo >= xs.length |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
77 ? Double.NaN |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
78 : Linear.linear(x, xs[mid], xs[mid+1], ys[mid], ys[mid+1]); |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
79 } |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
80 return hi < 0 |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
81 ? Double.NaN |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
82 : Linear.linear(x, xs[mid-1], xs[mid], ys[mid-1], ys[mid]); |
da872168a899
Added code to interpolate double values in a sorted array
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1666
diff
changeset
|
83 } |
1672
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
84 |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
85 public static final boolean isIncreasing(double [] array) { |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
86 int inc = 0; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
87 int dec = 0; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
88 int sweet = (array.length-1)/2; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
89 for (int i = 1; i < array.length; ++i) { |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
90 if (array[i] > array[i-1]) { |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
91 if (++inc > sweet) { |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
92 return true; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
93 } |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
94 } |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
95 else if (++dec > sweet) { |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
96 return false; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
97 } |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
98 } |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
99 return inc > sweet; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
100 } |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
101 |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
102 public static final double [] swap(double [] array) { |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
103 int lo = 0; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
104 int hi = array.length-1; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
105 while (hi > lo) { |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
106 double t = array[lo]; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
107 array[lo] = array[hi]; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
108 array[hi] = t; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
109 ++lo; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
110 --hi; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
111 } |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
112 |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
113 return array; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
114 } |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
115 |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
116 public static final double [] swapClone(double [] in) { |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
117 double [] out = new double[in.length]; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
118 |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
119 for (int j = out.length-1, i = 0; j >= 0;) { |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
120 out[j--] = in[i++]; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
121 } |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
122 |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
123 return out; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
124 } |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
125 |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
126 public static final double [] sumDiffs(double [] in) { |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
127 double [] out = new double[in.length]; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
128 |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
129 for (int i = 1; i < out.length; ++i) { |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
130 out[i] = out[i-1] + Math.abs(in[i-1] - in[i]); |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
131 } |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
132 |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
133 return out; |
0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1671
diff
changeset
|
134 } |
655
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 } |
913b52064449
Refactored version of "Berechnung 4"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |