diff gnv-artifacts/src/main/java/de/intevation/gnv/math/Point2d.java @ 361:aec85d00d82c

Added code to do 2D interpolations along a digitied track on the map. Not connected to the transition model, yet. gnv-artifacts/trunk@435 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 15 Dec 2009 22:25:53 +0000
parents
children f66088a43ecc
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/Point2d.java	Tue Dec 15 22:25:53 2009 +0000
@@ -0,0 +1,95 @@
+package de.intevation.gnv.math;
+
+import java.util.Comparator;
+
+import com.vividsolutions.jts.geom.Envelope;
+import com.vividsolutions.jts.geom.Coordinate;
+
+/**
+ *  @author Sascha L. Teichmann
+ */
+public class Point2d
+extends      Coordinate
+{
+    public static final double EPSILON = 1e-5d;
+
+    public static final Comparator X_COMPARATOR = new Comparator() {
+        public int compare(Object a, Object b) {
+            double xa = ((Coordinate)a).x;
+            double xb = ((Coordinate)b).x;
+            if (xa < xb) return -1;
+            if (xa > xb) return +1;
+            return 0;
+        }
+    };
+
+    public static final Comparator Y_COMPARATOR = new Comparator() {
+        public int compare(Object a, Object b) {
+            double ya = ((Coordinate)a).y;
+            double yb = ((Coordinate)b).y;
+            if (ya < yb) return -1;
+            if (ya > yb) return +1;
+            return 0;
+        }
+    };
+
+    public static class InverseL1Comparator
+    implements          Comparator
+    {
+        private Point2d ref;
+
+        public InverseL1Comparator(Point2d ref) {
+            this.ref = ref;
+        }
+
+        public int compare(Object a, Object b) {
+            Point2d pa = (Point2d)a;
+            Point2d pb = (Point2d)b;
+            double da = ref.L1(pa);
+            double db = ref.L1(pb);
+            if (da < db) return -1;
+            if (da > db) return +1;
+            return 0;
+        }
+    } // class InverseL1Comparator
+
+    public int i;
+    public int j;
+
+    public Point2d() {
+    }
+
+    public Point2d(double x, double y, double z, int i, int j) {
+        super(x, y, z);
+        this.i = i;
+        this.j = j;
+    }
+
+
+    public double L1(Point2d other) {
+        return L1(this, other);
+    }
+
+    public static double L1(Coordinate a, Coordinate b) {
+        return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
+    }
+
+    public Envelope envelope() {
+        return envelope(EPSILON);
+    }
+
+    public Envelope envelope(double epsilon) {
+        return new Envelope(
+            x-epsilon, x+epsilon,
+            y-epsilon, y+epsilon);
+    }
+
+    public boolean hasIGap(Point2d other) {
+        return Math.abs(i - other.i) > 1;
+    }
+
+    public boolean hasJGap(Point2d other) {
+        return Math.abs(j - other.j) > 1;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org