Changeset 12505 in josm for trunk/src/org/openstreetmap/josm/gui/draw/MapViewPath.java
- Timestamp:
- 2017-07-24T19:24:44+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/draw/MapViewPath.java
r12455 r12505 7 7 import java.awt.geom.Path2D; 8 8 import java.awt.geom.PathIterator; 9 import java.util.ArrayList; 9 10 10 11 import org.openstreetmap.josm.data.coor.EastNorth; 11 12 import org.openstreetmap.josm.data.coor.ILatLon; 13 import org.openstreetmap.josm.data.osm.visitor.paint.OffsetIterator; 12 14 import org.openstreetmap.josm.gui.MapView; 13 15 import org.openstreetmap.josm.gui.MapViewState; … … 280 282 public double getLength() { 281 283 return visitLine((inLineOffset, start, end, startIsOldEnd) -> { }); 284 } 285 286 /** 287 * Create a new {@link MapViewPath} that is the same as the current one except that it is offset in the view. 288 * @param viewOffset The offset in view pixels 289 * @return The new path 290 * @since 12505 291 */ 292 public MapViewPath offset(double viewOffset) { 293 OffsetPathVisitor visitor = new OffsetPathVisitor(state, viewOffset); 294 visitor.visit(this); 295 return visitor.getPath(); 282 296 } 283 297 … … 447 461 } 448 462 463 private class OffsetPathVisitor extends AbstractMapPathVisitor { 464 private final MapViewPath collector; 465 private final ArrayList<MapViewPoint> points = new ArrayList<>(); 466 private final double offset; 467 468 OffsetPathVisitor(MapViewState state, double offset) { 469 this.collector = new MapViewPath(state); 470 this.offset = offset; 471 } 472 473 @Override 474 void visitMoveTo(MapViewPoint p) { 475 finishLineSegment(); 476 points.add(p); 477 } 478 479 @Override 480 void visitLineTo(MapViewPoint p) { 481 points.add(p); 482 } 483 484 MapViewPath getPath() { 485 finishLineSegment(); 486 return collector; 487 } 488 489 private void finishLineSegment() { 490 if (points.size() > 2) { 491 OffsetIterator iterator = new OffsetIterator(points, offset); 492 collector.moveTo(iterator.next()); 493 while (iterator.hasNext()) { 494 collector.lineTo(iterator.next()); 495 } 496 points.clear(); 497 } 498 } 499 } 449 500 }
Note:
See TracChangeset
for help on using the changeset viewer.