diff flys-backend/src/main/java/de/intevation/flys/importer/XY.java @ 5083:7bbee0cfc171 slt-simplify-cross-sections

Added experimental Douglas Peuker simplification of cross sections.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 24 Feb 2013 17:29:52 +0100
parents 2b0426b79a92
children
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/XY.java	Sun Feb 24 13:03:44 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/XY.java	Sun Feb 24 17:29:52 2013 +0100
@@ -14,6 +14,10 @@
     public XY() {
     }
 
+    public XY(XY other) {
+        this(other.x, other.y, other.index);
+    }
+
     public XY(double x, double y, int index) {
         this.x     = x;
         this.y     = y;
@@ -52,5 +56,43 @@
     public void setIndex(int index) {
         this.index = index;
     }
+
+    public double dot(double ox, double oy) {
+        return x*ox + y*oy;
+    }
+
+    public double dot(XY other) {
+        return dot(other.x, other.y);
+    }
+
+    public XY sub(XY other) {
+        x -= other.x;
+        y -= other.y;
+        return this;
+    }
+
+    public XY ortho() {
+        double z = x;
+        x = y;
+        y = -z;
+        return this;
+    }
+
+    public XY normalize() {
+        double len = dot(this);
+
+        if (len > 1e-6) {
+            len = 1d/Math.sqrt(len);
+            x *= len;
+            y *= len;
+        }
+
+        return this;
+    }
+
+    // x*nx + y*ny + d = 0 <=> d = -x*nx -y*ny
+    public double lineOffset(XY p) {
+         return -x*p.x -y*p.y;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org