# HG changeset patch # User Sascha L. Teichmann # Date 1329479970 0 # Node ID 33e4481933e21976f466e8b3647fa73cf6596ad4 # Parent adb8641f5b5d4ffdf0921988e09b89b4152ea439 WstValueTable: Added method to find the w extent for a given km range. flys-artifacts/trunk@4080 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r adb8641f5b5d -r 33e4481933e2 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Feb 17 11:29:14 2012 +0000 +++ b/flys-artifacts/ChangeLog Fri Feb 17 11:59:30 2012 +0000 @@ -1,3 +1,8 @@ +2012-02-17 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java(getMinMaxW): + Added signature to give w extend for a given km range. + 2012-02-17 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java(getMinMaxW): diff -r adb8641f5b5d -r 33e4481933e2 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java Fri Feb 17 11:29:14 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java Fri Feb 17 11:59:30 2012 +0000 @@ -497,7 +497,7 @@ return qs.toNativeArray(); } - public double [] getMinMaxW() { + public double [] getMinMaxW(double [] result) { double minW = Double.MAX_VALUE; double maxW = -Double.MAX_VALUE; for (int i = 0; i < ws.length; ++i) { @@ -505,17 +505,18 @@ if (w < minW) minW = w; if (w > maxW) maxW = w; } - return new double [] { minW, maxW }; + result[0] = minW; + result[1] = maxW; + return result; } - public double [] getMinMaxW(Row other, double km) { - double [] m1 = this .getMinMaxW(); - double [] m2 = other.getMinMaxW(); + public double [] getMinMaxW(Row other, double km, double [] result) { + double [] m1 = this .getMinMaxW(new double [2]); + double [] m2 = other.getMinMaxW(new double [2]); double factor = Linear.factor(km, this.km, other.km); - return new double [] { - Linear.weight(factor, m1[0], m2[0]), - Linear.weight(factor, m1[1], m2[1]) - }; + result[0] = Linear.weight(factor, m1[0], m2[0]); + result[1] = Linear.weight(factor, m1[1], m2[1]); + return result; } } // class Row @@ -607,10 +608,14 @@ } public double [] getMinMaxW(double km) { + return getMinMaxW(km, new double [2]); + + } + public double [] getMinMaxW(double km, double [] result) { int rowIndex = Collections.binarySearch(rows, new Row(km)); if (rowIndex >= 0) { - return rows.get(rowIndex).getMinMaxW(); + return rows.get(rowIndex).getMinMaxW(result); } rowIndex = -rowIndex -1; @@ -623,9 +628,42 @@ Row r1 = rows.get(rowIndex-1); Row r2 = rows.get(rowIndex); - return r1.getMinMaxW(r2, km); + return r1.getMinMaxW(r2, km, result); } + public double [] getMinMaxW(double from, double to, double step) { + double [] result = new double[2]; + + double minW = Double.MAX_VALUE; + double maxW = -Double.MAX_VALUE; + + if (from > to) { + double tmp = from; + from = to; + to = tmp; + } + + step = Math.max(Math.abs(step), 0.0001); + + double d = from; + for (; d <= to; d += step) { + if (getMinMaxW(d, result) != null) { + if (result[0] < minW) minW = result[0]; + if (result[1] > maxW) maxW = result[1]; + } + } + + if (d != to) { + if (getMinMaxW(to, result) != null) { + if (result[0] < minW) minW = result[0]; + if (result[1] > maxW) maxW = result[1]; + } + } + + return minW < Double.MAX_VALUE + ? new double [] { minW, maxW } + : null; + } /** * Interpolate W and Q values at a given km.