[Dive4elements-commits] [PATCH 08 of 10] W80Parser: addPoint and lastIdx functions to add a point and find last points index

Wald Commits scm-commit at wald.intevation.org
Thu Jan 3 10:16:24 CET 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1357203581 -3600
# Node ID 3028037c6293c0652a0329624581c055f21aab7a
# Parent  ea8c3e6c96149673b95e78f497b5c206abc157ca
W80Parser: addPoint and lastIdx functions to add a point and find last points index.

diff -r ea8c3e6c9614 -r 3028037c6293 flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java	Thu Jan 03 09:58:49 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/W80Parser.java	Thu Jan 03 09:59:41 2013 +0100
@@ -138,6 +138,47 @@
     public void reset() {
         data.clear();
         currentLine = new ArrayList<XY>();
+        anchor = null;
+    }
+
+
+    /**
+     * Get the Index of the last cross-section lines point.
+     * @return last points index, -1 if not available.
+     */
+    private int lastPointIdx() {
+        if (currentLine == null || currentLine.isEmpty()) {
+            return -1;
+        }
+        XY lastPoint = this.currentLine.get(currentLine.size()-1);
+        return lastPoint.getIndex();
+    }
+
+    /**
+     * Add a Point (YZ,Index) to the current cross section line.
+     * @param y The y coordinate of new point.
+     * @param z The z coordinate of new point.
+     * @param idx Ignored, the parameter of new point.
+     * @return true if point could been added, false otherwise (e.g. not
+     *         parsable y or z values.
+     */
+    private boolean addPoint(double gkr, double gkh, double height, String idx) {
+        // Calculate distance between this and anchor-point.
+        double dx = gkr - anchor.getCoordinate().getX();
+        double dy = gkh - anchor.getCoordinate().getY();
+        double d  = Math.sqrt(dx * dx + dy * dy);
+
+        // We ignore idx, and increment instead.
+        int index;
+        int lastPointIdx = lastPointIdx();
+        if (lastPointIdx <= 0) {
+            index = 1;
+        } else {
+            index = lastPointIdx + 1;
+        }
+
+        currentLine.add(new XY(d, height/1000d, index));
+        return true;
     }
 
 


More information about the Dive4elements-commits mailing list