Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/math/Point2d.java @ 540:80630520e25a
merged gnv-artifacts/0.4
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:49 +0200 |
parents | 422275fc9927 |
children | b248531fa20b |
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 Fri Sep 28 12:13:49 2012 +0200 @@ -0,0 +1,101 @@ +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-3d; + + 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, int i, int j) { + super(x, y); + this.i = i; + this.j = j; + } + + 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: