changeset 4732:7fdddc6ba296

Initial version of support files for TIMParser, comments and TODOs by Felix Wolfsteller, Code by Sascha Teichmann.
author Sascha Teichmann <sascha.teichmann@intevation.de>
date Fri, 28 Dec 2012 15:01:12 +0100
parents 7d9fcd322c45
children e2e615109a2e
files flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/Coordinate.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/EpsilonComparator.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/LexiComparator.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/Line.java
diffstat 4 files changed, 102 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/Coordinate.java	Fri Dec 28 15:01:12 2012 +0100
@@ -0,0 +1,26 @@
+package de.intevation.flys.importer.parsers.tim;
+
+public class Coordinate
+{
+    public double x;
+    public double y;
+    public double z;
+
+    public Coordinate() {
+    }
+
+    public Coordinate(Coordinate c) {
+        this(c.x, c.y, c.z);
+    }
+
+    public Coordinate(double x, double y) {
+        this(x, y, 0d);
+    }
+
+    public Coordinate(double x, double y, double z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/EpsilonComparator.java	Fri Dec 28 15:01:12 2012 +0100
@@ -0,0 +1,25 @@
+package de.intevation.flys.importer.parsers.tim;
+
+import java.util.Comparator;
+
+public class EpsilonComparator implements Comparator<Double>
+{
+    public static final double EPSILON = 1e-4;
+
+    public static final EpsilonComparator CMP = new EpsilonComparator(EPSILON);
+
+    private double epsilon;
+
+    public EpsilonComparator(double epsilon) {
+        this.epsilon = epsilon;
+    }
+
+    @Override
+    public int compare(Double a, Double b) {
+        double diff = a - b;
+        if (diff < -epsilon) return -1;
+        if (diff >  epsilon) return +1;
+        return 0;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/LexiComparator.java	Fri Dec 28 15:01:12 2012 +0100
@@ -0,0 +1,18 @@
+package de.intevation.flys.importer.parsers.tim;
+
+import java.util.Comparator;
+
+public class LexiComparator implements Comparator<Coordinate> {
+
+    public static final LexiComparator CMP = new LexiComparator();
+
+    @Override
+    public int compare(Coordinate a, Coordinate b) {
+        if (a.x < b.x) return -1;
+        if (a.x > b.x) return +1;
+        if (a.y < b.y) return -1;
+        if (a.y > b.y) return +1;
+        return 0;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/tim/Line.java	Fri Dec 28 15:01:12 2012 +0100
@@ -0,0 +1,33 @@
+package de.intevation.flys.importer.parsers.tim;
+
+public class Line {
+
+    public Coordinate a;
+    public Coordinate b;
+
+    public Line() {
+    }
+
+    public Line(Coordinate a, Coordinate b) {
+        this.a = a;
+        this.b = b;
+    }
+
+    /** Project coordinate to line. */
+    public double distanceToFirst(Coordinate c) {
+
+        double nx = b.x - a.x;
+        double ny = b.y - a.y;
+
+        double len = Math.sqrt(nx*nx + ny*ny);
+
+        nx /= len;
+        ny /= len;
+
+        double px = c.x - a.x;
+        double py = c.y - a.y;
+
+        return nx*px + ny*py;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org