Changeset 12505 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-07-24T19:24:44+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/OffsetIterator.java
r11992 r12505 23 23 public class OffsetIterator implements Iterator<MapViewPoint> { 24 24 private final MapViewState mapState; 25 private final List< Node> nodes;25 private final List<MapViewPoint> nodes; 26 26 private final double offset; 27 27 private int idx; … … 37 37 /** 38 38 * Creates a new offset iterator 39 * @param nodes The nodes of the original line 40 * @param offset The offset of the line. 41 */ 42 public OffsetIterator(List<MapViewPoint> nodes, double offset) { 43 if (nodes.size() < 2) { 44 throw new IllegalArgumentException("There must be at least 2 nodes."); 45 } 46 this.mapState = nodes.get(0).getMapViewState(); 47 this.nodes = nodes; 48 this.offset = offset; 49 } 50 51 /** 52 * Creates a new offset iterator 39 53 * @param mapState The map view state this iterator is for. 40 54 * @param nodes The nodes of the original line … … 43 57 public OffsetIterator(MapViewState mapState, List<Node> nodes, double offset) { 44 58 this.mapState = mapState; 45 this.nodes = nodes.stream().filter(Node::isLatLonKnown). collect(Collectors.toList());59 this.nodes = nodes.stream().filter(Node::isLatLonKnown).map(mapState::getPointFor).collect(Collectors.toList()); 46 60 this.offset = offset; 47 idx = 0;48 61 } 49 62 … … 160 173 161 174 private MapViewPoint getForIndex(int i) { 162 return mapState.getPointFor(nodes.get(i));175 return nodes.get(i); 163 176 } 164 177 -
trunk/src/org/openstreetmap/josm/gui/MapViewState.java
r12213 r12505 419 419 */ 420 420 public abstract class MapViewPoint { 421 /** 422 * Gets the map view state this path is used for. 423 * @return The state. 424 * @since 12505 425 */ 426 public MapViewState getMapViewState() { 427 return MapViewState.this; 428 } 421 429 422 430 /** -
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.