Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 17-377
Link Here
|
17 |
|
17 |
|
18 |
import org.eclipse.draw2d.geometry.Point; |
18 |
import org.eclipse.draw2d.geometry.Point; |
19 |
import org.eclipse.draw2d.geometry.PointList; |
19 |
import org.eclipse.draw2d.geometry.PointList; |
20 |
import org.eclipse.draw2d.geometry.Ray; |
20 |
import org.eclipse.draw2d.geometry.PrecisionPoint; |
21 |
import org.eclipse.draw2d.geometry.Rectangle; |
21 |
import org.eclipse.draw2d.geometry.Rectangle; |
|
|
22 |
import org.eclipse.draw2d.geometry.Vector; |
22 |
|
23 |
|
23 |
/** |
24 |
/** |
24 |
* Provides a {@link Connection} with an orthogonal route between the Connection's source |
25 |
* Provides a {@link Connection} with an orthogonal route between the |
25 |
* and target anchors. |
26 |
* Connection's source and target anchors. |
26 |
*/ |
27 |
*/ |
27 |
public final class ManhattanConnectionRouter |
28 |
public final class ManhattanConnectionRouter extends AbstractRouter { |
28 |
extends AbstractRouter |
|
|
29 |
{ |
30 |
|
31 |
private Map rowsUsed = new HashMap(); |
32 |
private Map colsUsed = new HashMap(); |
33 |
//private Hashtable offsets = new Hashtable(7); |
34 |
|
35 |
private Map reservedInfo = new HashMap(); |
36 |
|
37 |
private class ReservedInfo { |
38 |
public List reservedRows = new ArrayList(2); |
39 |
public List reservedCols = new ArrayList(2); |
40 |
} |
41 |
|
42 |
private static Ray UP = new Ray(0, -1), |
43 |
DOWN = new Ray(0, 1), |
44 |
LEFT = new Ray(-1, 0), |
45 |
RIGHT = new Ray(1, 0); |
46 |
|
29 |
|
|
|
30 |
private Map rowsUsed = new HashMap(); |
31 |
private Map colsUsed = new HashMap(); |
32 |
// private Hashtable offsets = new Hashtable(7); |
47 |
|
33 |
|
48 |
/** |
34 |
private Map reservedInfo = new HashMap(); |
49 |
* @see ConnectionRouter#invalidate(Connection) |
|
|
50 |
*/ |
51 |
public void invalidate(Connection connection) { |
52 |
removeReservedLines(connection); |
53 |
} |
54 |
|
35 |
|
55 |
private int getColumnNear(Connection connection, int r, int n, int x) { |
36 |
private class ReservedInfo { |
56 |
int min = Math.min(n, x), |
37 |
public List reservedRows = new ArrayList(2); |
57 |
max = Math.max(n, x); |
38 |
public List reservedCols = new ArrayList(2); |
58 |
if (min > r) { |
|
|
59 |
max = min; |
60 |
min = r - (min - r); |
61 |
} |
62 |
if (max < r) { |
63 |
min = max; |
64 |
max = r + (r - max); |
65 |
} |
66 |
int proximity = 0; |
67 |
int direction = -1; |
68 |
if (r % 2 == 1) |
69 |
r--; |
70 |
Integer i; |
71 |
while (proximity < r) { |
72 |
i = new Integer(r + proximity * direction); |
73 |
if (!colsUsed.containsKey(i)) { |
74 |
colsUsed.put(i, i); |
75 |
reserveColumn(connection, i); |
76 |
return i.intValue(); |
77 |
} |
78 |
int j = i.intValue(); |
79 |
if (j <= min) |
80 |
return j + 2; |
81 |
if (j >= max) |
82 |
return j - 2; |
83 |
if (direction == 1) |
84 |
direction = -1; |
85 |
else { |
86 |
direction = 1; |
87 |
proximity += 2; |
88 |
} |
89 |
} |
39 |
} |
90 |
return r; |
|
|
91 |
} |
92 |
|
40 |
|
93 |
/** |
41 |
private static Vector UP = new Vector(0, -1), DOWN = new Vector(0, 1), |
94 |
* Returns the direction the point <i>p</i> is in relation to the given rectangle. |
42 |
LEFT = new Vector(-1, 0), RIGHT = new Vector(1, 0); |
95 |
* Possible values are LEFT (-1,0), RIGHT (1,0), UP (0,-1) and DOWN (0,1). |
|
|
96 |
* |
97 |
* @param r the rectangle |
98 |
* @param p the point |
99 |
* @return the direction from <i>r</i> to <i>p</i> |
100 |
*/ |
101 |
protected Ray getDirection(Rectangle r, Point p) { |
102 |
int i, distance = Math.abs(r.x - p.x); |
103 |
Ray direction; |
104 |
|
105 |
direction = LEFT; |
106 |
|
43 |
|
107 |
i = Math.abs(r.y - p.y); |
44 |
/** |
108 |
if (i <= distance) { |
45 |
* @see ConnectionRouter#invalidate(Connection) |
109 |
distance = i; |
46 |
*/ |
110 |
direction = UP; |
47 |
public void invalidate(Connection connection) { |
|
|
48 |
removeReservedLines(connection); |
111 |
} |
49 |
} |
112 |
|
50 |
|
113 |
i = Math.abs(r.bottom() - p.y); |
51 |
private int getColumnNear(Connection connection, int r, int n, int x) { |
114 |
if (i <= distance) { |
52 |
int min = Math.min(n, x), max = Math.max(n, x); |
115 |
distance = i; |
53 |
if (min > r) { |
116 |
direction = DOWN; |
54 |
max = min; |
|
|
55 |
min = r - (min - r); |
56 |
} |
57 |
if (max < r) { |
58 |
min = max; |
59 |
max = r + (r - max); |
60 |
} |
61 |
int proximity = 0; |
62 |
int direction = -1; |
63 |
if (r % 2 == 1) |
64 |
r--; |
65 |
Integer i; |
66 |
while (proximity < r) { |
67 |
i = new Integer(r + proximity * direction); |
68 |
if (!colsUsed.containsKey(i)) { |
69 |
colsUsed.put(i, i); |
70 |
reserveColumn(connection, i); |
71 |
return i.intValue(); |
72 |
} |
73 |
int j = i.intValue(); |
74 |
if (j <= min) |
75 |
return j + 2; |
76 |
if (j >= max) |
77 |
return j - 2; |
78 |
if (direction == 1) |
79 |
direction = -1; |
80 |
else { |
81 |
direction = 1; |
82 |
proximity += 2; |
83 |
} |
84 |
} |
85 |
return r; |
117 |
} |
86 |
} |
118 |
|
87 |
|
119 |
i = Math.abs(r.right() - p.x); |
88 |
/** |
120 |
if (i < distance) { |
89 |
* Returns the direction the point <i>p</i> is in relation to the given |
121 |
distance = i; |
90 |
* rectangle. Possible values are LEFT (-1,0), RIGHT (1,0), UP (0,-1) and |
122 |
direction = RIGHT; |
91 |
* DOWN (0,1). |
123 |
} |
92 |
* |
|
|
93 |
* @param r |
94 |
* the rectangle |
95 |
* @param p |
96 |
* the point |
97 |
* @return the direction from <i>r</i> to <i>p</i> |
98 |
*/ |
99 |
protected Vector getDirection(Rectangle r, Point p) { |
100 |
int i, distance = Math.abs(r.x - p.x); |
101 |
Vector direction; |
102 |
|
103 |
direction = LEFT; |
104 |
|
105 |
i = Math.abs(r.y - p.y); |
106 |
if (i <= distance) { |
107 |
distance = i; |
108 |
direction = UP; |
109 |
} |
124 |
|
110 |
|
125 |
return direction; |
111 |
i = Math.abs(r.bottom() - p.y); |
126 |
} |
112 |
if (i <= distance) { |
|
|
113 |
distance = i; |
114 |
direction = DOWN; |
115 |
} |
127 |
|
116 |
|
128 |
protected Ray getEndDirection(Connection conn) { |
117 |
i = Math.abs(r.right() - p.x); |
129 |
ConnectionAnchor anchor = conn.getTargetAnchor(); |
118 |
if (i < distance) { |
130 |
Point p = getEndPoint(conn); |
119 |
distance = i; |
131 |
Rectangle rect; |
120 |
direction = RIGHT; |
132 |
if (anchor.getOwner() == null) |
121 |
} |
133 |
rect = new Rectangle(p.x - 1, p.y - 1, 2, 2); |
122 |
|
134 |
else { |
123 |
return direction; |
135 |
rect = conn.getTargetAnchor().getOwner().getBounds().getCopy(); |
|
|
136 |
conn.getTargetAnchor().getOwner().translateToAbsolute(rect); |
137 |
} |
124 |
} |
138 |
return getDirection(rect, p); |
|
|
139 |
} |
140 |
|
125 |
|
141 |
protected int getRowNear(Connection connection, int r, int n, int x) { |
126 |
protected Vector getEndDirection(Connection conn) { |
142 |
int min = Math.min(n, x), |
127 |
ConnectionAnchor anchor = conn.getTargetAnchor(); |
143 |
max = Math.max(n, x); |
128 |
Point p = getEndPoint(conn); |
144 |
if (min > r) { |
129 |
Rectangle rect; |
145 |
max = min; |
130 |
if (anchor.getOwner() == null) |
146 |
min = r - (min - r); |
131 |
rect = new Rectangle(p.x - 1, p.y - 1, 2, 2); |
147 |
} |
|
|
148 |
if (max < r) { |
149 |
min = max; |
150 |
max = r + (r - max); |
151 |
} |
152 |
|
153 |
int proximity = 0; |
154 |
int direction = -1; |
155 |
if (r % 2 == 1) |
156 |
r--; |
157 |
Integer i; |
158 |
while (proximity < r) { |
159 |
i = new Integer(r + proximity * direction); |
160 |
if (!rowsUsed.containsKey(i)) { |
161 |
rowsUsed.put(i, i); |
162 |
reserveRow(connection, i); |
163 |
return i.intValue(); |
164 |
} |
165 |
int j = i.intValue(); |
166 |
if (j <= min) |
167 |
return j + 2; |
168 |
if (j >= max) |
169 |
return j - 2; |
170 |
if (direction == 1) |
171 |
direction = -1; |
172 |
else { |
132 |
else { |
173 |
direction = 1; |
133 |
rect = conn.getTargetAnchor().getOwner().getBounds().getCopy(); |
174 |
proximity += 2; |
134 |
conn.getTargetAnchor().getOwner().translateToAbsolute(rect); |
175 |
} |
135 |
} |
|
|
136 |
return getDirection(rect, p); |
176 |
} |
137 |
} |
177 |
return r; |
|
|
178 |
} |
179 |
|
180 |
protected Ray getStartDirection(Connection conn) { |
181 |
ConnectionAnchor anchor = conn.getSourceAnchor(); |
182 |
Point p = getStartPoint(conn); |
183 |
Rectangle rect; |
184 |
if (anchor.getOwner() == null) |
185 |
rect = new Rectangle(p.x - 1, p.y - 1, 2, 2); |
186 |
else { |
187 |
rect = conn.getSourceAnchor().getOwner().getBounds().getCopy(); |
188 |
conn.getSourceAnchor().getOwner().translateToAbsolute(rect); |
189 |
} |
190 |
return getDirection(rect, p); |
191 |
} |
192 |
|
138 |
|
193 |
protected void processPositions(Ray start, Ray end, List positions, |
139 |
protected int getRowNear(Connection connection, int r, int n, int x) { |
194 |
boolean horizontal, Connection conn) { |
140 |
int min = Math.min(n, x), max = Math.max(n, x); |
195 |
removeReservedLines(conn); |
141 |
if (min > r) { |
196 |
|
142 |
max = min; |
197 |
int pos[] = new int[positions.size() + 2]; |
143 |
min = r - (min - r); |
198 |
if (horizontal) |
144 |
} |
199 |
pos[0] = start.x; |
145 |
if (max < r) { |
200 |
else |
146 |
min = max; |
201 |
pos[0] = start.y; |
147 |
max = r + (r - max); |
202 |
int i; |
148 |
} |
203 |
for (i = 0; i < positions.size(); i++) { |
|
|
204 |
pos[i + 1] = ((Integer)positions.get(i)).intValue(); |
205 |
} |
206 |
if (horizontal == (positions.size() % 2 == 1)) |
207 |
pos[++i] = end.x; |
208 |
else |
209 |
pos[++i] = end.y; |
210 |
|
211 |
PointList points = new PointList(); |
212 |
points.addPoint(new Point(start.x, start.y)); |
213 |
Point p; |
214 |
int current, prev, min, max; |
215 |
boolean adjust; |
216 |
for (i = 2; i < pos.length - 1; i++) { |
217 |
horizontal = !horizontal; |
218 |
prev = pos[i - 1]; |
219 |
current = pos[i]; |
220 |
|
149 |
|
221 |
adjust = (i != pos.length - 2); |
150 |
int proximity = 0; |
222 |
if (horizontal) { |
151 |
int direction = -1; |
223 |
if (adjust) { |
152 |
if (r % 2 == 1) |
224 |
min = pos[i - 2]; |
153 |
r--; |
225 |
max = pos[i + 2]; |
154 |
Integer i; |
226 |
pos[i] = current = getRowNear(conn, current, min, max); |
155 |
while (proximity < r) { |
|
|
156 |
i = new Integer(r + proximity * direction); |
157 |
if (!rowsUsed.containsKey(i)) { |
158 |
rowsUsed.put(i, i); |
159 |
reserveRow(connection, i); |
160 |
return i.intValue(); |
227 |
} |
161 |
} |
228 |
p = new Point(prev, current); |
162 |
int j = i.intValue(); |
229 |
} else { |
163 |
if (j <= min) |
230 |
if (adjust) { |
164 |
return j + 2; |
231 |
min = pos[i - 2]; |
165 |
if (j >= max) |
232 |
max = pos[i + 2]; |
166 |
return j - 2; |
233 |
pos[i] = current = getColumnNear(conn, current, min, max); |
167 |
if (direction == 1) |
|
|
168 |
direction = -1; |
169 |
else { |
170 |
direction = 1; |
171 |
proximity += 2; |
234 |
} |
172 |
} |
235 |
p = new Point(current, prev); |
|
|
236 |
} |
173 |
} |
237 |
points.addPoint(p); |
174 |
return r; |
238 |
} |
175 |
} |
239 |
points.addPoint(new Point(end.x, end.y)); |
|
|
240 |
conn.setPoints(points); |
241 |
} |
242 |
|
176 |
|
243 |
/** |
177 |
protected Vector getStartDirection(Connection conn) { |
244 |
* @see ConnectionRouter#remove(Connection) |
178 |
ConnectionAnchor anchor = conn.getSourceAnchor(); |
245 |
*/ |
179 |
Point p = getStartPoint(conn); |
246 |
public void remove(Connection connection) { |
180 |
Rectangle rect; |
247 |
removeReservedLines(connection); |
181 |
if (anchor.getOwner() == null) |
248 |
} |
182 |
rect = new Rectangle(p.x - 1, p.y - 1, 2, 2); |
|
|
183 |
else { |
184 |
rect = conn.getSourceAnchor().getOwner().getBounds().getCopy(); |
185 |
conn.getSourceAnchor().getOwner().translateToAbsolute(rect); |
186 |
} |
187 |
return getDirection(rect, p); |
188 |
} |
249 |
|
189 |
|
250 |
protected void removeReservedLines(Connection connection) { |
190 |
protected void processPositions(Vector start, Vector end, List positions, |
251 |
ReservedInfo rInfo = (ReservedInfo) reservedInfo.get(connection); |
191 |
boolean horizontal, Connection conn) { |
252 |
if (rInfo == null) |
192 |
removeReservedLines(conn); |
253 |
return; |
193 |
|
254 |
|
194 |
int pos[] = new int[positions.size() + 2]; |
255 |
for (int i = 0; i < rInfo.reservedRows.size(); i++) { |
195 |
if (horizontal) |
256 |
rowsUsed.remove(rInfo.reservedRows.get(i)); |
196 |
pos[0] = (int) start.x; |
|
|
197 |
else |
198 |
pos[0] = (int) start.y; |
199 |
int i; |
200 |
for (i = 0; i < positions.size(); i++) { |
201 |
pos[i + 1] = ((Integer) positions.get(i)).intValue(); |
202 |
} |
203 |
if (horizontal == (positions.size() % 2 == 1)) |
204 |
pos[++i] = (int) end.x; |
205 |
else |
206 |
pos[++i] = (int) end.y; |
207 |
|
208 |
PointList points = new PointList(); |
209 |
points.addPoint(new Point(start.x, start.y)); |
210 |
Point p; |
211 |
int current, prev, min, max; |
212 |
boolean adjust; |
213 |
for (i = 2; i < pos.length - 1; i++) { |
214 |
horizontal = !horizontal; |
215 |
prev = pos[i - 1]; |
216 |
current = pos[i]; |
217 |
|
218 |
adjust = (i != pos.length - 2); |
219 |
if (horizontal) { |
220 |
if (adjust) { |
221 |
min = pos[i - 2]; |
222 |
max = pos[i + 2]; |
223 |
pos[i] = current = getRowNear(conn, current, min, max); |
224 |
} |
225 |
p = new Point(prev, current); |
226 |
} else { |
227 |
if (adjust) { |
228 |
min = pos[i - 2]; |
229 |
max = pos[i + 2]; |
230 |
pos[i] = current = getColumnNear(conn, current, min, max); |
231 |
} |
232 |
p = new Point(current, prev); |
233 |
} |
234 |
points.addPoint(p); |
235 |
} |
236 |
points.addPoint(new Point(end.x, end.y)); |
237 |
conn.setPoints(points); |
257 |
} |
238 |
} |
258 |
for (int i = 0; i < rInfo.reservedCols.size(); i++) { |
239 |
|
259 |
colsUsed.remove(rInfo.reservedCols.get(i)); |
240 |
/** |
|
|
241 |
* @see ConnectionRouter#remove(Connection) |
242 |
*/ |
243 |
public void remove(Connection connection) { |
244 |
removeReservedLines(connection); |
260 |
} |
245 |
} |
261 |
reservedInfo.remove(connection); |
|
|
262 |
} |
263 |
|
246 |
|
264 |
protected void reserveColumn(Connection connection, Integer column) { |
247 |
protected void removeReservedLines(Connection connection) { |
265 |
ReservedInfo info = (ReservedInfo) reservedInfo.get(connection); |
248 |
ReservedInfo rInfo = (ReservedInfo) reservedInfo.get(connection); |
266 |
if (info == null) { |
249 |
if (rInfo == null) |
267 |
info = new ReservedInfo(); |
250 |
return; |
268 |
reservedInfo.put(connection, info); |
251 |
|
|
|
252 |
for (int i = 0; i < rInfo.reservedRows.size(); i++) { |
253 |
rowsUsed.remove(rInfo.reservedRows.get(i)); |
254 |
} |
255 |
for (int i = 0; i < rInfo.reservedCols.size(); i++) { |
256 |
colsUsed.remove(rInfo.reservedCols.get(i)); |
257 |
} |
258 |
reservedInfo.remove(connection); |
269 |
} |
259 |
} |
270 |
info.reservedCols.add(column); |
|
|
271 |
} |
272 |
|
260 |
|
273 |
protected void reserveRow(Connection connection, Integer row) { |
261 |
protected void reserveColumn(Connection connection, Integer column) { |
274 |
ReservedInfo info = (ReservedInfo) reservedInfo.get(connection); |
262 |
ReservedInfo info = (ReservedInfo) reservedInfo.get(connection); |
275 |
if (info == null) { |
263 |
if (info == null) { |
276 |
info = new ReservedInfo(); |
264 |
info = new ReservedInfo(); |
277 |
reservedInfo.put(connection, info); |
265 |
reservedInfo.put(connection, info); |
|
|
266 |
} |
267 |
info.reservedCols.add(column); |
278 |
} |
268 |
} |
279 |
info.reservedRows.add(row); |
|
|
280 |
} |
281 |
|
269 |
|
282 |
/** |
270 |
protected void reserveRow(Connection connection, Integer row) { |
283 |
* @see ConnectionRouter#route(Connection) |
271 |
ReservedInfo info = (ReservedInfo) reservedInfo.get(connection); |
284 |
*/ |
272 |
if (info == null) { |
285 |
public void route(Connection conn) { |
273 |
info = new ReservedInfo(); |
286 |
if ((conn.getSourceAnchor() == null) || (conn.getTargetAnchor() == null)) |
274 |
reservedInfo.put(connection, info); |
287 |
return; |
275 |
} |
288 |
int i; |
276 |
info.reservedRows.add(row); |
289 |
Point startPoint = getStartPoint(conn); |
277 |
} |
290 |
conn.translateToRelative(startPoint); |
|
|
291 |
Point endPoint = getEndPoint(conn); |
292 |
conn.translateToRelative(endPoint); |
293 |
|
294 |
Ray start = new Ray(startPoint); |
295 |
Ray end = new Ray(endPoint); |
296 |
Ray average = start.getAveraged(end); |
297 |
|
298 |
Ray direction = new Ray(start, end); |
299 |
Ray startNormal = getStartDirection(conn); |
300 |
Ray endNormal = getEndDirection(conn); |
301 |
|
302 |
List positions = new ArrayList(5); |
303 |
boolean horizontal = startNormal.isHorizontal(); |
304 |
if (horizontal) |
305 |
positions.add(new Integer(start.y)); |
306 |
else |
307 |
positions.add(new Integer(start.x)); |
308 |
horizontal = !horizontal; |
309 |
|
310 |
if (startNormal.dotProduct(endNormal) == 0) { |
311 |
if ((startNormal.dotProduct(direction) >= 0) |
312 |
&& (endNormal.dotProduct(direction) <= 0)) { |
313 |
// 0 |
314 |
} else { |
315 |
// 2 |
316 |
if (startNormal.dotProduct(direction) < 0) |
317 |
i = startNormal.similarity(start.getAdded(startNormal.getScaled(10))); |
318 |
else { |
319 |
if (horizontal) |
320 |
i = average.y; |
321 |
else |
322 |
i = average.x; |
323 |
} |
324 |
positions.add(new Integer(i)); |
325 |
horizontal = !horizontal; |
326 |
|
278 |
|
327 |
if (endNormal.dotProduct(direction) > 0) |
279 |
/** |
328 |
i = endNormal.similarity(end.getAdded(endNormal.getScaled(10))); |
280 |
* @see ConnectionRouter#route(Connection) |
329 |
else { |
281 |
*/ |
330 |
if (horizontal) |
282 |
public void route(Connection conn) { |
331 |
i = average.y; |
283 |
if ((conn.getSourceAnchor() == null) |
332 |
else |
284 |
|| (conn.getTargetAnchor() == null)) |
333 |
i = average.x; |
285 |
return; |
|
|
286 |
int i; |
287 |
Point startPoint = getStartPoint(conn); |
288 |
conn.translateToRelative(startPoint); |
289 |
Point endPoint = getEndPoint(conn); |
290 |
conn.translateToRelative(endPoint); |
291 |
|
292 |
Vector start = new Vector(new PrecisionPoint(startPoint)); |
293 |
Vector end = new Vector(new PrecisionPoint(endPoint)); |
294 |
Vector average = start.getAveraged(end); |
295 |
|
296 |
Vector direction = new Vector(start, end); |
297 |
Vector startNormal = getStartDirection(conn); |
298 |
Vector endNormal = getEndDirection(conn); |
299 |
|
300 |
List positions = new ArrayList(5); |
301 |
boolean horizontal = startNormal.isHorizontal(); |
302 |
if (horizontal) |
303 |
positions.add(new Integer((int) start.y)); |
304 |
else |
305 |
positions.add(new Integer((int) start.x)); |
306 |
horizontal = !horizontal; |
307 |
|
308 |
if (startNormal.getDotProduct(endNormal) == 0) { |
309 |
if ((startNormal.getDotProduct(direction) >= 0) |
310 |
&& (endNormal.getDotProduct(direction) <= 0)) { |
311 |
// 0 |
312 |
} else { |
313 |
// 2 |
314 |
if (startNormal.getDotProduct(direction) < 0) |
315 |
i = (int) startNormal.getSimilarity(start |
316 |
.getAdded(startNormal.getMultiplied(10))); |
317 |
else { |
318 |
if (horizontal) |
319 |
i = (int) average.y; |
320 |
else |
321 |
i = (int) average.x; |
322 |
} |
323 |
positions.add(new Integer(i)); |
324 |
horizontal = !horizontal; |
325 |
|
326 |
if (endNormal.getDotProduct(direction) > 0) |
327 |
i = (int) endNormal.getSimilarity(end.getAdded(endNormal |
328 |
.getMultiplied(10))); |
329 |
else { |
330 |
if (horizontal) |
331 |
i = (int) average.y; |
332 |
else |
333 |
i = (int) average.x; |
334 |
} |
335 |
positions.add(new Integer(i)); |
336 |
horizontal = !horizontal; |
334 |
} |
337 |
} |
335 |
positions.add(new Integer(i)); |
|
|
336 |
horizontal = !horizontal; |
337 |
} |
338 |
} else { |
339 |
if (startNormal.dotProduct(endNormal) > 0) { |
340 |
//1 |
341 |
if (startNormal.dotProduct(direction) >= 0) |
342 |
i = startNormal.similarity(start.getAdded(startNormal.getScaled(10))); |
343 |
else |
344 |
i = endNormal.similarity(end.getAdded(endNormal.getScaled(10))); |
345 |
positions.add(new Integer(i)); |
346 |
horizontal = !horizontal; |
347 |
} else { |
338 |
} else { |
348 |
//3 or 1 |
339 |
if (startNormal.getDotProduct(endNormal) > 0) { |
349 |
if (startNormal.dotProduct(direction) < 0) { |
340 |
// 1 |
350 |
i = startNormal.similarity(start.getAdded(startNormal.getScaled(10))); |
341 |
if (startNormal.getDotProduct(direction) >= 0) |
|
|
342 |
i = (int) startNormal.getSimilarity(start |
343 |
.getAdded(startNormal.getMultiplied(10))); |
344 |
else |
345 |
i = (int) endNormal.getSimilarity(end.getAdded(endNormal |
346 |
.getMultiplied(10))); |
351 |
positions.add(new Integer(i)); |
347 |
positions.add(new Integer(i)); |
352 |
horizontal = !horizontal; |
348 |
horizontal = !horizontal; |
353 |
} |
349 |
} else { |
354 |
|
350 |
// 3 or 1 |
355 |
if (horizontal) |
351 |
if (startNormal.getDotProduct(direction) < 0) { |
356 |
i = average.y; |
352 |
i = (int) startNormal.getSimilarity(start |
357 |
else |
353 |
.getAdded(startNormal.getMultiplied(10))); |
358 |
i = average.x; |
354 |
positions.add(new Integer(i)); |
359 |
positions.add(new Integer(i)); |
355 |
horizontal = !horizontal; |
360 |
horizontal = !horizontal; |
356 |
} |
361 |
|
357 |
|
362 |
if (startNormal.dotProduct(direction) < 0) { |
358 |
if (horizontal) |
363 |
i = endNormal.similarity(end.getAdded(endNormal.getScaled(10))); |
359 |
i = (int) average.y; |
|
|
360 |
else |
361 |
i = (int) average.x; |
364 |
positions.add(new Integer(i)); |
362 |
positions.add(new Integer(i)); |
365 |
horizontal = !horizontal; |
363 |
horizontal = !horizontal; |
|
|
364 |
|
365 |
if (startNormal.getDotProduct(direction) < 0) { |
366 |
i = (int) endNormal.getSimilarity(end.getAdded(endNormal |
367 |
.getMultiplied(10))); |
368 |
positions.add(new Integer(i)); |
369 |
horizontal = !horizontal; |
370 |
} |
366 |
} |
371 |
} |
367 |
} |
372 |
} |
|
|
373 |
if (horizontal) |
374 |
positions.add(new Integer((int) end.y)); |
375 |
else |
376 |
positions.add(new Integer((int) end.x)); |
377 |
|
378 |
processPositions(start, end, positions, startNormal.x > 0, conn); |
368 |
} |
379 |
} |
369 |
if (horizontal) |
|
|
370 |
positions.add(new Integer(end.y)); |
371 |
else |
372 |
positions.add(new Integer(end.x)); |
373 |
|
374 |
processPositions(start, end, positions, startNormal.isHorizontal(), conn); |
375 |
} |
376 |
|
380 |
|
377 |
} |
381 |
} |