diff flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java @ 4564:080411ac948f

More solid S/Q function sampling
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 16 Nov 2012 17:39:47 +0100
parents 5a8f8fd5310c
children
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java	Fri Nov 16 14:57:14 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/JFreeUtil.java	Fri Nov 16 17:39:47 2012 +0100
@@ -116,5 +116,28 @@
 
         return series;
     }
+
+    public static StyledXYSeries sampleFunction2DPositive(
+        Function func,
+        Document theme,
+        String   seriesKey,
+        int      samples,
+        double   start,
+        double   end
+    ) {
+        StyledXYSeries series = new StyledXYSeries(seriesKey, theme);
+
+        double step = (end - start) / (samples - 1);
+
+        for (int i = 0; i < samples; i++) {
+            double x = start + (step * i);
+            double v = func.value(x);
+            if (x > 0d && v > 0d) {
+                series.add(x, v);
+            }
+        }
+
+        return series;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org