comparison gnv-artifacts/src/main/java/de/intevation/gnv/math/Point2d.java @ 361:aec85d00d82c

Added code to do 2D interpolations along a digitied track on the map. Not connected to the transition model, yet. gnv-artifacts/trunk@435 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 15 Dec 2009 22:25:53 +0000
parents
children f66088a43ecc
comparison
equal deleted inserted replaced
360:ee760729f6b8 361:aec85d00d82c
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-5d;
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, double z, int i, int j) {
63 super(x, y, z);
64 this.i = i;
65 this.j = j;
66 }
67
68
69 public double L1(Point2d other) {
70 return L1(this, other);
71 }
72
73 public static double L1(Coordinate a, Coordinate b) {
74 return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
75 }
76
77 public Envelope envelope() {
78 return envelope(EPSILON);
79 }
80
81 public Envelope envelope(double epsilon) {
82 return new Envelope(
83 x-epsilon, x+epsilon,
84 y-epsilon, y+epsilon);
85 }
86
87 public boolean hasIGap(Point2d other) {
88 return Math.abs(i - other.i) > 1;
89 }
90
91 public boolean hasJGap(Point2d other) {
92 return Math.abs(j - other.j) > 1;
93 }
94 }
95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org