Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java @ 3061:49baebb39305
FixA: Add interpolation of parameters that better suits the instantiation real functions.
flys-artifacts/trunk@4641 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 12 Jun 2012 08:11:36 +0000 |
parents | 4f7171ac6153 |
children | 5642a83420f2 |
comparison
equal
deleted
inserted
replaced
3060:94d78e0dc5e9 | 3061:49baebb39305 |
---|---|
175 double [] values | 175 double [] values |
176 ) { | 176 ) { |
177 return interpolate(columnIndex(columnName), key, values); | 177 return interpolate(columnIndex(columnName), key, values); |
178 } | 178 } |
179 | 179 |
180 public double [] interpolate(int columnIndex, double key, double [] values) { | 180 public double [] interpolate( |
181 | 181 int columnIndex, |
182 double key, | |
183 double [] values | |
184 ) { | |
182 int row = binarySearch(columnIndex, key, EPSILON); | 185 int row = binarySearch(columnIndex, key, EPSILON); |
183 | 186 |
184 if (row >= 0) { | 187 if (row >= 0) { |
185 for (int i = 0; i < values.length; ++i) { | 188 for (int i = 0; i < values.length; ++i) { |
186 values[i] = columns[i].getQuick(row); | 189 values[i] = columns[i].getQuick(row); |
202 } | 205 } |
203 } | 206 } |
204 return values; | 207 return values; |
205 } | 208 } |
206 | 209 |
210 | |
211 public double [] interpolate( | |
212 String keyName, | |
213 double key, | |
214 String [] columnNames | |
215 ) { | |
216 int keyIndex = columnIndex(keyName); | |
217 return keyIndex < 0 | |
218 ? null | |
219 : interpolate(keyIndex, key, columnNames); | |
220 } | |
221 | |
222 public double [] interpolate( | |
223 int keyIndex, | |
224 double key, | |
225 String [] columnNames | |
226 ) { | |
227 int row = binarySearch(keyIndex, key, EPSILON); | |
228 | |
229 if (row >= 0) { // direct match | |
230 double [] values = new double[columnNames.length]; | |
231 for (int i = 0; i < values.length; ++i) { | |
232 int ci = columnIndex(columnNames[i]); | |
233 values[i] = ci < 0 | |
234 ? Double.NaN | |
235 : columns[ci].getQuick(row); | |
236 } | |
237 return values; | |
238 } | |
239 | |
240 row = -row - 1; | |
241 if (row < 1 || row >= size()) { // out of bounds | |
242 return null; | |
243 } | |
244 | |
245 double v1 = columns[keyIndex].getQuick(row-1); | |
246 double v2 = columns[keyIndex].getQuick(row); | |
247 double factor = Linear.factor(key, v1, v2); | |
248 | |
249 double [] values = new double[columnNames.length]; | |
250 | |
251 for (int i = 0; i < values.length; ++i) { | |
252 int ci = columnIndex(columnNames[i]); | |
253 values[i] = ci < 0 | |
254 ? Double.NaN | |
255 : Linear.weight( | |
256 factor, | |
257 columns[ci].getQuick(row-1), | |
258 columns[ci].getQuick(row)); | |
259 } | |
260 | |
261 return values; | |
262 } | |
263 | |
207 public boolean isSorted(String columnName) { | 264 public boolean isSorted(String columnName) { |
208 return isSorted(columnIndex(columnName)); | 265 return isSorted(columnIndex(columnName)); |
209 } | 266 } |
210 | 267 |
211 public boolean isSorted(int columnIndex) { | 268 public boolean isSorted(int columnIndex) { |