comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java @ 406:663aa18bee7f

Back jump correction should work now for both flow directions. flys-artifacts/trunk@1848 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 07 May 2011 21:34:02 +0000
parents f165c7d5d6db
children 2dbbb5be30a1
comparison
equal deleted inserted replaced
405:55c2b0d9999e 406:663aa18bee7f
36 36
37 public double [] getCorrected() { 37 public double [] getCorrected() {
38 return corrected; 38 return corrected;
39 } 39 }
40 40
41 private static final boolean isIncreasing(double [] ws) {
42 int inc = 0;
43 int dec = 0;
44 int sweet = (ws.length-1)/2;
45 for (int i = 1; i < ws.length; ++i) {
46 if (ws[i] > ws[i-1]) {
47 if (++inc > sweet) {
48 return true;
49 }
50 }
51 else if (++dec > sweet) {
52 return false;
53 }
54 }
55 return inc > sweet;
56 }
57
41 public boolean doCorrection(double [] km, double [] ws) { 58 public boolean doCorrection(double [] km, double [] ws) {
59 boolean isIncreasing = isIncreasing(ws);
60
61 if (isIncreasing) {
62 // mirror along x axis to simulate decreasing values
63 ws = (double [])ws.clone();
64 for (int i = 0; i < ws.length; ++i) {
65 ws[i] = -ws[i];
66 }
67 }
68
69 boolean hasBackJumps = doCorrectionClean(km, ws);
70
71 if (hasBackJumps && isIncreasing) {
72 // mirror back
73 for (int i = 0; i < corrected.length; ++i) {
74 corrected[i] = -corrected[i];
75 }
76 }
77
78 return hasBackJumps;
79 }
80
81 protected boolean doCorrectionClean(double [] km, double [] ws) {
42 int N = km.length; 82 int N = km.length;
43 83
44 if (N != ws.length) { 84 if (N != ws.length) {
45 throw new IllegalArgumentException("km.length != ws.length"); 85 throw new IllegalArgumentException("km.length != ws.length");
46 } 86 }

http://dive4elements.wald.intevation.org