Ignore:
Timestamp:
2017-07-24T19:24:44+02:00 (7 years ago)
Author:
michael2402
Message:

Add a method that allows traversing an offset version of a MapViewPath

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/OffsetIterator.java

    r11992 r12505  
    2323public class OffsetIterator implements Iterator<MapViewPoint> {
    2424    private final MapViewState mapState;
    25     private final List<Node> nodes;
     25    private final List<MapViewPoint> nodes;
    2626    private final double offset;
    2727    private int idx;
     
    3737    /**
    3838     * 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
    3953     * @param mapState The map view state this iterator is for.
    4054     * @param nodes The nodes of the original line
     
    4357    public OffsetIterator(MapViewState mapState, List<Node> nodes, double offset) {
    4458        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());
    4660        this.offset = offset;
    47         idx = 0;
    4861    }
    4962
     
    160173
    161174    private MapViewPoint getForIndex(int i) {
    162         return mapState.getPointFor(nodes.get(i));
     175        return nodes.get(i);
    163176    }
    164177
Note: See TracChangeset for help on using the changeset viewer.