# HG changeset patch # User Sascha L. Teichmann # Date 1347292774 0 # Node ID 51f76225823bc4d984092a226a60213c5fb82190 # Parent 467efea19d153976ffc722a6c2f0c883c77a6a33 Extreme waterlevels: calculate the segments for Q km ranges. flys-artifacts/trunk@5426 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 467efea19d15 -r 51f76225823b flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon Sep 10 14:38:58 2012 +0000 +++ b/flys-artifacts/ChangeLog Mon Sep 10 15:59:34 2012 +0000 @@ -1,3 +1,15 @@ +2012-09-10 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/artifacts/model/Range.java: + Added disjoint method. + + * src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java: + Find a list of segments intersecting a given range. + + * src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java: + Generate a list of ranges needed for the input of Qs + in the "Auslagerung extremer Wasserspiegellagen.". + 2012-09-10 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/model/extreme/Curve.java: diff -r 467efea19d15 -r 51f76225823b flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java Mon Sep 10 14:38:58 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java Mon Sep 10 15:59:34 2012 +0000 @@ -212,6 +212,35 @@ return root != null ? root.findQ(pos) : Double.NaN; } + protected Node head() { + Node head = root; + while (head.left != null) { + head = head.left; + } + return head; + } + + public List findSegments(double a, double b) { + if (a > b) { double t = a; a = b; b = t; } + return findSegments(new Range(a, b)); + } + + public List findSegments(Range range) { + List segments = new ArrayList(); + + // Linear scan should be good enough here. + for (Node curr = head(); curr != null; curr = curr.next) { + if (!range.disjoint(curr.a, curr.b)) { + Range r = new Range(curr.a, curr.b); + if (r.clip(range)) { + segments.add(r); + } + } + } + + return segments; + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); diff -r 467efea19d15 -r 51f76225823b flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Range.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Range.java Mon Sep 10 14:38:58 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Range.java Mon Sep 10 15:59:34 2012 +0000 @@ -30,6 +30,10 @@ return end; } + public boolean disjoint(double ostart, double oend) { + return start > oend || ostart > end; + } + public boolean disjoint(Range other) { return start > other.end || other.start > end; } diff -r 467efea19d15 -r 51f76225823b 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 Mon Sep 10 14:38:58 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java Mon Sep 10 15:59:34 2012 +0000 @@ -1252,5 +1252,11 @@ } return result; } + + public List findSegments(double km1, double km2) { + return columns.length != 0 + ? columns[columns.length-1].getQRangeTree().findSegments(km1, km2) + : Collections.emptyList(); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :