changeset 2558:33e4481933e2

WstValueTable: Added method to find the w extent for a given km range. flys-artifacts/trunk@4080 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 17 Feb 2012 11:59:30 +0000
parents adb8641f5b5d
children 407bbc74fe0b
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java
diffstat 2 files changed, 54 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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	<sascha.teichmann@intevation.de>
+
+	* 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	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java(getMinMaxW):
--- 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.

http://dive4elements.wald.intevation.org