diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java @ 2652:9d2a06c3a134

Added DataType for lines that also stores width, use it. Added HasLabel interface for some series. flys-artifacts/trunk@4318 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 27 Apr 2012 09:58:21 +0000
parents a6fa128e4654
children 0143b44631cc
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java	Thu Apr 26 15:08:51 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java	Fri Apr 27 09:58:21 2012 +0000
@@ -13,6 +13,9 @@
 
 import gnu.trove.TDoubleArrayList;
 
+/**
+ * Utility to create lines (intersect water with cross-section etc).
+ */
 public class Lines
 {
     private static Logger log = Logger.getLogger(Lines.class);
@@ -24,6 +27,9 @@
     protected Lines() {
     }
 
+    /**
+     * Calculate the 'length' of the given lines.
+     */
     public static double length(List<Line2D> lines) {
         double sum = 0d;
         for (Line2D line: lines) {
@@ -261,7 +267,21 @@
         return result;
     }
 
-    public static double [][] createWaterLines(
+
+    /**
+     * Class holding points that form lines and the calculated length.
+     */
+    public static class LineData {
+        public double [][] points;
+        public double width;
+        public LineData(double[][] points, double width) {
+            this.points = points;
+            this.width = width;
+        }
+    }
+
+
+    public static LineData createWaterLines(
         List<Point2D> points,
         double        waterlevel
     ) {
@@ -269,22 +289,32 @@
 
         TDoubleArrayList lxs = new TDoubleArrayList();
         TDoubleArrayList lys = new TDoubleArrayList();
+        double linesLength = 0.0f;
 
         for (Iterator<Line2D> iter = lines.iterator(); iter.hasNext();) {
-            Line2D  l  = iter.next();
-            Point2D p1 = l.getP1();
-            Point2D p2 = l.getP2();
+            Line2D  line = iter.next();
+            Point2D p1   = line.getP1();
+            Point2D p2   = line.getP2();
             lxs.add(p1.getX());
             lys.add(p1.getY());
             lxs.add(p2.getX());
             lys.add(p2.getY());
+
+            // Length calculation.
+            double xDiff = line.getX1() - line.getX2();
+            double yDiff = line.getY1() - line.getY2();
+            linesLength += Math.sqrt(xDiff*xDiff + yDiff*yDiff);
+
             if (iter.hasNext()) {
                 lxs.add(Double.NaN);
                 lys.add(Double.NaN);
             }
         }
 
-        return new double [][] { lxs.toNativeArray(), lys.toNativeArray() };
+        return new LineData(
+            new double [][] { lxs.toNativeArray(), lys.toNativeArray() },
+            linesLength
+            );
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org