Mercurial > dive4elements > river
changeset 2316:61b32380ffdb
Be more conservative about arrays and indices in "Bezugslinienverfahren".
flys-artifacts/trunk@3997 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 09 Feb 2012 12:13:28 +0000 |
parents | c0dfa36add96 |
children | 9b5541dcc01f |
files | flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java |
diffstat | 1 files changed, 20 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java Thu Feb 09 11:47:25 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java Thu Feb 09 12:13:28 2012 +0000 @@ -940,31 +940,30 @@ return new double[2][0]; } - int N = sf1.splineQs.length; + int N = Math.min(sf1.splineQs.length, sf2.splineQs.length); double stepWidth = N/(double)numSamples; PolynomialSplineFunction qW1 = sf1.spline; PolynomialSplineFunction qW2 = sf2.spline; - double [] ws1 = new double[numSamples]; - double [] ws2 = new double[numSamples]; - double [] qs1 = new double[numSamples]; - double [] qs2 = new double[numSamples]; - - Arrays.fill(ws1, Double.NaN); - Arrays.fill(ws2, Double.NaN); - Arrays.fill(qs1, Double.NaN); - Arrays.fill(qs2, Double.NaN); + TDoubleArrayList ws1 = new TDoubleArrayList(numSamples); + TDoubleArrayList ws2 = new TDoubleArrayList(numSamples); + TDoubleArrayList qs1 = new TDoubleArrayList(numSamples); + TDoubleArrayList qs2 = new TDoubleArrayList(numSamples); boolean hadErrors = false; - double p = 0d; - for (int i = 0; i < numSamples; ++i, p += stepWidth) { + int i = 0; + for (double p = 0d; p <= N-1; p += stepWidth, ++i) { try { - qs1[i] = iQ1.value(p); - ws1[i] = qW1.value(qs1[i]); - qs2[i] = iQ2.value(p); - ws2[i] = qW2.value(qs2[i]); + double q1 = iQ1.value(p); + double w1 = qW1.value(q1); + double q2 = iQ2.value(p); + double w2 = qW2.value(q2); + ws1.add(w1); + ws2.add(w2); + qs1.add(q1); + qs2.add(q2); } catch (ArgumentOutsideDomainException aode) { if (!hadErrors) { @@ -979,7 +978,11 @@ } } - return new double [][] { ws1, qs1, ws2, qs2 }; + return new double [][] { + ws1.toNativeArray(), + qs1.toNativeArray(), + ws2.toNativeArray(), + qs2.toNativeArray() }; } public QPosition getQPosition(double km, double q) {