comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java @ 3273:739aa90eb79e

Fix issue694. flys-artifacts/trunk@4917 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 10 Jul 2012 16:04:44 +0000
parents 31168ac9c7e7
children d9af29a4bb85
comparison
equal deleted inserted replaced
3272:31168ac9c7e7 3273:739aa90eb79e
278 * the other given km. 278 * the other given km.
279 * Return Double.NaN otherwise 279 * Return Double.NaN otherwise
280 * 280 *
281 * @param wkms WKms in which to search for a spatially close W value. 281 * @param wkms WKms in which to search for a spatially close W value.
282 * @param km the input km, which is compared to values from wkms. 282 * @param km the input km, which is compared to values from wkms.
283 * @param next the next available input km. 283 * @param next the next available input km (-1 if unavailable).
284 * @param prev the previous available input km. 284 * @param prev the previous available input km (-1 if unavailable).
285 * 285 *
286 * @return W in wkms that is closer to km than to next and prev, or Double.NaN. 286 * @return W in wkms that is closer to km than to next and prev, or Double.NaN.
287 */ 287 */
288 public double getWAtCloseKm(WKms wkms, double km, double next, double prev) { 288 public double getWAtCloseKm(WKms wkms, double km, double next, double prev) {
289 int size = wkms.size(); 289 int size = wkms.size();
290 // TODO handle edge cases (with no next or prev).
291 for (int i = 0; i < size; i++) { 290 for (int i = 0; i < size; i++) {
292 double wkmsKm = wkms.getKm(i); 291 double wkmsKm = wkms.getKm(i);
293 double dist = Distance.distance(wkmsKm, km); 292 double dist = Distance.distance(wkmsKm, km);
294 if ((prev != km && dist <= Distance.distance(wkmsKm, prev)) 293 if ((prev == -1d || dist <= Distance.distance(wkmsKm, prev))
295 && dist <= Distance.distance(wkmsKm, next)) { 294 && (next == -1d || dist <= Distance.distance(wkmsKm, next))) {
296 return wkms.getW(i); 295 return wkms.getW(i);
297 } 296 }
298 } 297 }
299 298
300 return Double.NaN; 299 return Double.NaN;
301 } 300 }

http://dive4elements.wald.intevation.org