Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Polygon2D.java @ 1801:6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
flys-artifacts/trunk@3125 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 31 Oct 2011 17:05:14 +0000 |
parents | 1402991208d5 |
children | 5642a83420f2 |
comparison
equal
deleted
inserted
replaced
1800:1402991208d5 | 1801:6f83d9d434f2 |
---|---|
255 double yan = Y(as[ai]); | 255 double yan = Y(as[ai]); |
256 double ybn = Y(bs[ai]); | 256 double ybn = Y(bs[ai]); |
257 | 257 |
258 if (neg) { | 258 if (neg) { |
259 if (yan > ybn) { // intersection | 259 if (yan > ybn) { // intersection |
260 // TODO: calculate intersection point | 260 Point2D ip = VectorUtils.intersection( |
261 // finish polygon and start a new one | 261 apoints.get(apoints.size()-1), as[ai], |
262 bpoints.get(bpoints.size()-1), bs[bi]); | |
263 addCheck(ip, apoints); | |
264 addCheck(ip, bpoints); | |
265 Polygon2D p = new Polygon2D( | |
266 new ArrayList<Point2D>(apoints)); | |
267 p.addReversed(bpoints); | |
268 negatives.add(p); | |
269 apoints.clear(); | |
270 bpoints.clear(); | |
271 apoints.add(ip); | |
272 bpoints.add(ip); | |
273 neg = !neg; | |
262 } | 274 } |
263 else { // no intersection | 275 else { // no intersection |
264 addCheck(as[ai], apoints); | 276 addCheck(as[ai], apoints); |
265 addCheck(bs[bi], bpoints); | 277 addCheck(bs[bi], bpoints); |
266 ++ai; | |
267 ++bi; | |
268 } | 278 } |
269 } | 279 } |
270 else { // not neg | 280 else { // not neg |
271 if (ybn > yan) { // intersection | 281 if (ybn > yan) { // intersection |
272 // TODO: calculate intersection point | 282 Point2D ip = VectorUtils.intersection( |
273 // finish polygon and start a new one | 283 apoints.get(apoints.size()-1), as[ai], |
284 bpoints.get(bpoints.size()-1), bs[bi]); | |
285 addCheck(ip, apoints); | |
286 addCheck(ip, bpoints); | |
287 Polygon2D p = new Polygon2D( | |
288 new ArrayList<Point2D>(apoints)); | |
289 p.addReversed(bpoints); | |
290 positives.add(p); | |
291 apoints.clear(); | |
292 bpoints.clear(); | |
293 apoints.add(ip); | |
294 bpoints.add(ip); | |
295 neg = !neg; | |
274 } | 296 } |
275 else { // no intersection | 297 else { // no intersection |
276 addCheck(as[ai], apoints); | 298 addCheck(as[ai], apoints); |
277 addCheck(bs[bi], bpoints); | 299 addCheck(bs[bi], bpoints); |
278 ++ai; | |
279 ++bi; | |
280 } | 300 } |
281 } | 301 } |
302 ++ai; | |
303 ++bi; | |
282 } | 304 } |
283 else if (xan > xbn) { | 305 else if (xan > xbn) { |
284 line.set(apoints.get(apoints.size()-1), as[ai]); | 306 line.set(apoints.get(apoints.size()-1), as[ai]); |
285 double dir = neg ? -1d: 1d; // XXX: correct sign? | 307 double dir = neg ? -1d: 1d; // XXX: correct sign? |
286 while (bi < bs.length | 308 while (bi < bs.length |
294 X(bs[bi-1]), | 316 X(bs[bi-1]), |
295 X(apoints.get(apoints.size()-1)), X(as[ai]), | 317 X(apoints.get(apoints.size()-1)), X(as[ai]), |
296 Y(apoints.get(apoints.size()-1)), Y(as[ai])); | 318 Y(apoints.get(apoints.size()-1)), Y(as[ai])); |
297 addCheck(new Point2D.Double(X(bs[bi-1]), ay1), apoints); | 319 addCheck(new Point2D.Double(X(bs[bi-1]), ay1), apoints); |
298 addCheck(bs[bi-1], bpoints); | 320 addCheck(bs[bi-1], bpoints); |
321 Polygon2D p = new Polygon2D( | |
322 new ArrayList<Point2D>(apoints)); | |
323 p.addReversed(bpoints); | |
324 apoints.clear(); | |
325 bpoints.clear(); | |
326 (neg ? negatives : positives).add(p); | |
299 break; | 327 break; |
300 } | 328 } |
301 else { | 329 else { |
302 // TODO: intersect line and/or X(bs[bi]) >= xan? | 330 // TODO: intersect line and/or X(bs[bi]) >= xan? |
303 } | 331 } |