[Dive4elements-commits] [PATCH 01 of 11] New class storing configuration about zoom dependent filter levels

Wald Commits scm-commit at wald.intevation.org
Mon Dec 3 17:27:21 CET 2012


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1354550002 -3600
# Node ID e8c6fbed889b5229f28a56842f53444ac9f8b33f
# Parent  95e23bcf6a5038a4c052314b6c62247cc5c5f162
New class storing configuration about zoom dependent filter levels.

diff -r 95e23bcf6a50 -r e8c6fbed889b flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ZoomScale.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ZoomScale.java	Mon Dec 03 16:53:22 2012 +0100
@@ -0,0 +1,75 @@
+package de.intevation.flys.artifacts.model;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.flys.artifacts.math.Linear;
+
+
+public class ZoomScale
+{
+    private static Logger logger = Logger.getLogger(ZoomScale.class);
+
+    private HashMap<String, TreeMap<Double, Double>> rivers;
+
+    public ZoomScale() {
+        this.rivers = new HashMap<String, TreeMap<Double, Double>>();
+    }
+
+    public ZoomScale(String river) {
+        this();
+        rivers.put(river, new TreeMap<Double, Double>());
+    }
+
+    public double getRadius(String river, double lower, double upper) {
+        double range = Math.abs(upper) - Math.abs(lower);
+        TreeMap<Double, Double> ranges = rivers.get(river);
+        if (ranges == null) {
+            return 0.001;
+        }
+        Map.Entry<Double, Double> next = ranges.higherEntry(range);
+        Map.Entry<Double, Double> prev = ranges.lowerEntry(range);
+        double x0 = 0d;
+        double x1 = 0d;
+        double y0 = 0d;
+        double y1 = 0d;
+        if (prev == null && next != null) {
+            x1 = next.getKey();
+            y1 = next.getValue();
+        }
+        else if (prev != null && next == null) {
+            return prev.getValue();
+        }
+        else {
+            x0 = prev.getKey();
+            x1 = next.getKey();
+            y0 = prev.getValue();
+            y1 = next.getValue();
+        }
+        return Linear.linear(range, x0, x1, y0, y1);
+    }
+
+    public void addRiver(String river) {
+        if (!this.rivers.containsKey(river)) {
+            this.rivers.put(river, new TreeMap<Double, Double>());
+        }
+    }
+
+    public Set<String> getRivers() {
+        return this.rivers.keySet();
+    }
+
+    public void addRange(String river, double range, double radius) {
+        if (this.rivers.containsKey(river)) {
+            this.rivers.get(river).put(range, radius);
+        }
+        else {
+            this.rivers.put(river, new TreeMap<Double, Double>());
+            this.rivers.get(river).put(range, radius);
+        }
+    }
+}


More information about the Dive4elements-commits mailing list