diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Polygon2D.java @ 1797:5eec623db50a

Polygon2D: moved 2D vector operation to separate class. flys-artifacts/trunk@3120 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 31 Oct 2011 10:03:32 +0000
parents fe7f9264a2ed
children 552888e9c64a
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Polygon2D.java	Mon Oct 31 10:01:08 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Polygon2D.java	Mon Oct 31 10:03:32 2011 +0000
@@ -16,8 +16,6 @@
 public class Polygon2D
 implements   Serializable
 {
-    public static final double EPSILON = 1e-4;
-
     private static final double X(Point2D p) {
         return p.getX();
     }
@@ -52,11 +50,6 @@
         points = new ArrayList<Point2D>();
     }
 
-    public static boolean epsilonEquals(Point2D a, Point2D b) {
-        return Math.abs(X(a)-X(b)) < EPSILON 
-            && Math.abs(Y(a)-Y(b)) < EPSILON;
-    }
-
     public void add(double x, double y) {
         points.add(new Point2D.Double(x, y));
     }
@@ -67,7 +60,7 @@
                 points.add(p);
                 return true;
             case 1:
-                if (epsilonEquals(points.get(0), p)) {
+                if (VectorUtils.epsilonEquals(points.get(0), p)) {
                     return false;
                 }
                 points.add(p);
@@ -75,11 +68,11 @@
             default:
                 int L = points.size()-1;
                 Point2D last = points.get(L);
-                if (epsilonEquals(last, p)) {
+                if (VectorUtils.epsilonEquals(last, p)) {
                     return false;
                 }
                 Point2D before = points.get(L-1);
-                if (collinear(before, last, p)) {
+                if (VectorUtils.collinear(before, last, p)) {
                     points.set(L, p);
                 }
                 else {
@@ -95,56 +88,6 @@
         }
     }
 
-    private static final double L1(Point2D a, Point2D b) {
-        return Math.abs(X(a)-X(b)) + Math.abs(Y(a)-Y(b));
-    }
-
-    public static boolean collinear(Point2D a, Point2D b, Point2D c) {
-        double dab = L1(a, b);
-        double dac = L1(a, c);
-        double dbc = L1(b, c);
-
-        Point2D p1, p2, p3;
-
-        if (dab > dac) {
-            if (dab > dbc) {
-                p1 = a;
-                p2 = b;
-                p3 = c;
-            }
-            else { // dbc >= dab
-                p1 = b;
-                p2 = c;
-                p3 = a;
-            }
-        }
-        else { // dac >= dab
-            if (dac > dbc) {
-                p1 = a;
-                p2 = c;
-                p3 = b;
-            }
-            else { // dbc >= dac
-                p1 = b;
-                p2 = c;
-                p3 = a;
-            }
-        }
-
-        // TODO: Continue here.
-
-
-        return true;
-    }
-
-    public static Point2D sub(Point2D a, Point2D b) {
-        return new Point2D.Double(X(a)-X(b), Y(a)-Y(b));
-    }
-
-    public static Point2D scale(Point2D a, double s) {
-        return new Point2D.Double(s*X(a), s*Y(a));
-    }
-
     public double area() {
         double area = 0d;
 

http://dive4elements.wald.intevation.org