annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/IndexBuffer.java @ 1118:c01c220312d0

Made it compile again with an updated ArtifactDatabase. gnv-artifacts/trunk@4137 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 12 Mar 2012 08:31:46 +0000
parents f953c9a559d8
children
rev   line source
1115
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 798
diff changeset
1 /*
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 798
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 798
diff changeset
3 *
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 798
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 798
diff changeset
5 * Read the file LGPL.txt coming with the software for details
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 798
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 798
diff changeset
7 */
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 798
diff changeset
8
349
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 package de.intevation.gnv.utils;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 349
diff changeset
11 import java.awt.Point;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 349
diff changeset
12
349
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import java.awt.geom.Point2D;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import java.util.List;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 /**
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 * Create buffers around integer pairs (i_1..n), j_1..n).
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 *
780
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
20 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
349
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 */
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 public class IndexBuffer
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 public static final double EPSILON = 1e-6d;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 public static final double OFFSET = 1.0d;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 public static final String I_COLUMN = "IPOSITION";
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 public static final String J_COLUMN = "JPOSITION";
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 public static final class Segment {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 private Segment next;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 private Point2D.Double n;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 private double d1;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 private double d2;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 private int iMin;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 private int iMax;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 private int jMin;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 private int jMax;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 public Segment(Point a, Point b, Segment next) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 this.next = next;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 iMin = Math.min(a.x, b.x)-1;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 iMax = Math.max(a.x, b.x)+1;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 jMin = Math.min(a.y, b.y)-1;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 jMax = Math.max(a.y, b.y)+1;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 if (a.x > b.x) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 Point p = a; a = b; b = p;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 Point2D.Double p1, p2, p3;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 if (a.y < b.y) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 p1 = new Point2D.Double(a.x - OFFSET, a.y + 1 + OFFSET);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 p2 = new Point2D.Double(b.x - OFFSET, b.y + 1 + OFFSET);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 p3 = new Point2D.Double(a.x + 1 + OFFSET, a.y - OFFSET);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 else {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 p1 = new Point2D.Double(a.x + 1 + OFFSET, a.y + 1 + OFFSET);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 p2 = new Point2D.Double(b.x + 1 + OFFSET, b.y + 1 + OFFSET);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 p3 = new Point2D.Double(b.x - OFFSET, b.y - OFFSET);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 n = normalize(orthogonal(sub(p1, p2)));
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 d1 = dot(n, p1);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 d2 = dot(n, p3);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 if (d1 > d2) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 double d = d1;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 d1 = d2;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 d2 = d;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 public boolean check(int i, int j) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 if (i < iMin || i > iMax || j < jMin || j > jMax) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 return false;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 double v = dot(n, i, j);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 return v >= d1 && v <= d2;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 public void toWhereClause(StringBuilder sb, String iColumn, String jColumn) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 sb.append('(')
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 .append(iColumn).append(" >= ").append(iMin).append(" AND ")
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 .append(iColumn).append(" <= ").append(iMax).append(" AND ")
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 .append(jColumn).append(" >= ").append(jMin).append(" AND ")
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 .append(jColumn).append(" <= ").append(jMax).append(" AND (")
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 .append(n.x).append('*').append(iColumn).append(" + ")
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 .append(n.y).append('*').append(jColumn)
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 .append(") BETWEEN ").append(d1).append(" AND ").append(d2).append(')');
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 } // class Segment
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 protected Segment head;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 protected String iColumn;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 protected String jColumn;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 public IndexBuffer(List<? extends Point> points) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 this(points, I_COLUMN, J_COLUMN);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 public IndexBuffer(List<? extends Point> points, String iColumn, String jColumn) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 this.iColumn = iColumn;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 this.jColumn = jColumn;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 for (int i = 1, N = points.size(); i < N; ++i) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 Point p1 = (Point)points.get(i-1);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 Point p2 = (Point)points.get(i);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 head = new Segment(p1, p2, head);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 public boolean check(int i, int j) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 Segment current = head;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 while (current != null) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127 if (current.check(i, j)) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128 return true;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130 current = current.next;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132 return false;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 public String toWhereClause() {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 StringBuilder sb = new StringBuilder();
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 Segment current = head;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141 while (current != null) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142 if (current != head) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 sb.append(" OR ");
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 current.toWhereClause(sb, iColumn, jColumn);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 current = current.next;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 return sb.toString();
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 public static Point2D.Double sub(Point2D.Double p1, Point2D.Double p2) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 return new Point2D.Double(p1.x - p2.x, p1.y - p2.y);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 public static final double dot(Point2D.Double p1, Point2D.Double p2) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 return p1.x*p2.x + p1.y*p2.y;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 public static final double dot(Point2D.Double p1, double x, double y) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 return p1.x*x + p1.y*y;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 public static final Point2D.Double scale(Point2D.Double p, double s) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 return new Point2D.Double(s*p.x, s*p.y);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 public static final Point2D.Double normalize(Point2D.Double p) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 double len2 = Math.sqrt(dot(p, p));
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 return len2 > EPSILON ? scale(p, 1d/len2) : p;
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 public static final Point2D.Double orthogonal(Point2D.Double p) {
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 return new Point2D.Double(p.y, -p.x);
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 }
555483213f78 Added buffer creator in index (i, j) space.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 }
798
6cff63d0c434 Fixed vim modeline. Added some Javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
177 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org