sascha@361: package de.intevation.gnv.math; sascha@361: sascha@361: import java.util.Comparator; sascha@361: sascha@361: import com.vividsolutions.jts.geom.Envelope; sascha@361: import com.vividsolutions.jts.geom.Coordinate; sascha@361: sascha@361: /** sascha@361: * @author Sascha L. Teichmann sascha@361: */ sascha@361: public class Point2d sascha@361: extends Coordinate sascha@361: { ingo@365: public static final double EPSILON = 1e-3d; sascha@361: sascha@361: public static final Comparator X_COMPARATOR = new Comparator() { sascha@361: public int compare(Object a, Object b) { sascha@361: double xa = ((Coordinate)a).x; sascha@361: double xb = ((Coordinate)b).x; sascha@361: if (xa < xb) return -1; sascha@361: if (xa > xb) return +1; sascha@361: return 0; sascha@361: } sascha@361: }; sascha@361: sascha@361: public static final Comparator Y_COMPARATOR = new Comparator() { sascha@361: public int compare(Object a, Object b) { sascha@361: double ya = ((Coordinate)a).y; sascha@361: double yb = ((Coordinate)b).y; sascha@361: if (ya < yb) return -1; sascha@361: if (ya > yb) return +1; sascha@361: return 0; sascha@361: } sascha@361: }; sascha@361: sascha@361: public static class InverseL1Comparator sascha@361: implements Comparator sascha@361: { sascha@361: private Point2d ref; sascha@361: sascha@361: public InverseL1Comparator(Point2d ref) { sascha@361: this.ref = ref; sascha@361: } sascha@361: sascha@361: public int compare(Object a, Object b) { sascha@361: Point2d pa = (Point2d)a; sascha@361: Point2d pb = (Point2d)b; sascha@361: double da = ref.L1(pa); sascha@361: double db = ref.L1(pb); sascha@361: if (da < db) return -1; sascha@361: if (da > db) return +1; sascha@361: return 0; sascha@361: } sascha@361: } // class InverseL1Comparator sascha@361: sascha@361: public int i; sascha@361: public int j; sascha@361: sascha@361: public Point2d() { sascha@361: } sascha@361: sascha@361: public Point2d(double x, double y, double z, int i, int j) { sascha@361: super(x, y, z); sascha@361: this.i = i; sascha@361: this.j = j; sascha@361: } sascha@361: sascha@361: sascha@361: public double L1(Point2d other) { sascha@361: return L1(this, other); sascha@361: } sascha@361: sascha@361: public static double L1(Coordinate a, Coordinate b) { sascha@361: return Math.abs(a.x - b.x) + Math.abs(a.y - b.y); sascha@361: } sascha@361: sascha@361: public Envelope envelope() { sascha@361: return envelope(EPSILON); sascha@361: } sascha@361: sascha@361: public Envelope envelope(double epsilon) { sascha@361: return new Envelope( sascha@361: x-epsilon, x+epsilon, sascha@361: y-epsilon, y+epsilon); sascha@361: } sascha@361: sascha@361: public boolean hasIGap(Point2d other) { sascha@361: return Math.abs(i - other.i) > 1; sascha@361: } sascha@361: sascha@361: public boolean hasJGap(Point2d other) { sascha@361: return Math.abs(j - other.j) > 1; sascha@361: } sascha@361: } sascha@361: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: