Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/utils/DoubleUtil.java @ 1672:0b6dac664bbb
Moved some generic double array code from BackjumpCorrector to DoubleUtil
flys-artifacts/trunk@2885 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 04 Oct 2011 15:29:39 +0000 |
parents | da872168a899 |
children | 0dd58ab7e118 |
comparison
equal
deleted
inserted
replaced
1671:da872168a899 | 1672:0b6dac664bbb |
---|---|
79 } | 79 } |
80 return hi < 0 | 80 return hi < 0 |
81 ? Double.NaN | 81 ? Double.NaN |
82 : Linear.linear(x, xs[mid-1], xs[mid], ys[mid-1], ys[mid]); | 82 : Linear.linear(x, xs[mid-1], xs[mid], ys[mid-1], ys[mid]); |
83 } | 83 } |
84 | |
85 public static final boolean isIncreasing(double [] array) { | |
86 int inc = 0; | |
87 int dec = 0; | |
88 int sweet = (array.length-1)/2; | |
89 for (int i = 1; i < array.length; ++i) { | |
90 if (array[i] > array[i-1]) { | |
91 if (++inc > sweet) { | |
92 return true; | |
93 } | |
94 } | |
95 else if (++dec > sweet) { | |
96 return false; | |
97 } | |
98 } | |
99 return inc > sweet; | |
100 } | |
101 | |
102 public static final double [] swap(double [] array) { | |
103 int lo = 0; | |
104 int hi = array.length-1; | |
105 while (hi > lo) { | |
106 double t = array[lo]; | |
107 array[lo] = array[hi]; | |
108 array[hi] = t; | |
109 ++lo; | |
110 --hi; | |
111 } | |
112 | |
113 return array; | |
114 } | |
115 | |
116 public static final double [] swapClone(double [] in) { | |
117 double [] out = new double[in.length]; | |
118 | |
119 for (int j = out.length-1, i = 0; j >= 0;) { | |
120 out[j--] = in[i++]; | |
121 } | |
122 | |
123 return out; | |
124 } | |
125 | |
126 public static final double [] sumDiffs(double [] in) { | |
127 double [] out = new double[in.length]; | |
128 | |
129 for (int i = 1; i < out.length; ++i) { | |
130 out[i] = out[i-1] + Math.abs(in[i-1] - in[i]); | |
131 } | |
132 | |
133 return out; | |
134 } | |
84 } | 135 } |
85 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 136 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |