comparison 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
comparison
equal deleted inserted replaced
415:9f4a0b990d27 540:80630520e25a
1 package de.intevation.gnv.math;
2
3 import java.util.Comparator;
4
5 import com.vividsolutions.jts.geom.Envelope;
6 import com.vividsolutions.jts.geom.Coordinate;
7
8 /**
9 * @author Sascha L. Teichmann
10 */
11 public class Point2d
12 extends Coordinate
13 {
14 public static final double EPSILON = 1e-3d;
15
16 public static final Comparator X_COMPARATOR = new Comparator() {
17 public int compare(Object a, Object b) {
18 double xa = ((Coordinate)a).x;
19 double xb = ((Coordinate)b).x;
20 if (xa < xb) return -1;
21 if (xa > xb) return +1;
22 return 0;
23 }
24 };
25
26 public static final Comparator Y_COMPARATOR = new Comparator() {
27 public int compare(Object a, Object b) {
28 double ya = ((Coordinate)a).y;
29 double yb = ((Coordinate)b).y;
30 if (ya < yb) return -1;
31 if (ya > yb) return +1;
32 return 0;
33 }
34 };
35
36 public static class InverseL1Comparator
37 implements Comparator
38 {
39 private Point2d ref;
40
41 public InverseL1Comparator(Point2d ref) {
42 this.ref = ref;
43 }
44
45 public int compare(Object a, Object b) {
46 Point2d pa = (Point2d)a;
47 Point2d pb = (Point2d)b;
48 double da = ref.L1(pa);
49 double db = ref.L1(pb);
50 if (da < db) return -1;
51 if (da > db) return +1;
52 return 0;
53 }
54 } // class InverseL1Comparator
55
56 public int i;
57 public int j;
58
59 public Point2d() {
60 }
61
62 public Point2d(double x, double y, int i, int j) {
63 super(x, y);
64 this.i = i;
65 this.j = j;
66 }
67
68 public Point2d(double x, double y, double z, int i, int j) {
69 super(x, y, z);
70 this.i = i;
71 this.j = j;
72 }
73
74
75 public double L1(Point2d other) {
76 return L1(this, other);
77 }
78
79 public static double L1(Coordinate a, Coordinate b) {
80 return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
81 }
82
83 public Envelope envelope() {
84 return envelope(EPSILON);
85 }
86
87 public Envelope envelope(double epsilon) {
88 return new Envelope(
89 x-epsilon, x+epsilon,
90 y-epsilon, y+epsilon);
91 }
92
93 public boolean hasIGap(Point2d other) {
94 return Math.abs(i - other.i) > 1;
95 }
96
97 public boolean hasJGap(Point2d other) {
98 return Math.abs(j - other.j) > 1;
99 }
100 }
101 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org