Ignore:
Timestamp:
2011-08-13T20:04:52+02:00 (13 years ago)
Author:
bastiK
Message:

fix last commit

Location:
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint
Files:
2 edited

Legend:

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

    r4087 r4317  
    2424import java.util.Collection;
    2525import java.util.Iterator;
     26import java.util.List;
    2627
    2728import javax.swing.ImageIcon;
     
    114115     * @param onewayReversed for oneway=-1 and similar
    115116     */
    116     public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor,
     117    public void drawWay(Way way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor, int offset,
    117118            boolean showOrientation, boolean showHeadArrowOnly,
    118119            boolean showOneway, boolean onewayReversed) {
     
    128129        Point lastPoint = null;
    129130        boolean initialMoveToNeeded = true;
    130         Iterator<Node> it = way.getNodes().iterator();
     131        List<Node> wayNodes = way.getNodes();
     132        if (wayNodes.size() < 2) return;
     133       
     134        Iterator<Point> it = new OffsetIterator(way.getNodes(), offset);
    131135        while (it.hasNext()) {
    132             Node n = it.next();
    133             Point p = nc.getPoint(n);
    134             if(lastPoint != null) {
     136            Point p = it.next();
     137            if (lastPoint != null) {
    135138                Point p1 = lastPoint;
    136139                Point p2 = p;
     
    209212    }
    210213
     214    /**
     215     * Iterates over a list of Way Nodes and returns screen coordinates that
     216     * represent a line that is shifted by a certain offset perpendicular
     217     * to the way direction.
     218     *
     219     * There is no intention, to handle consecutive duplicate Nodes in a
     220     * perfect way, but it is should not throw an exception.
     221     */
     222    public class OffsetIterator implements Iterator<Point> {
     223       
     224        private List<Node> nodes;
     225        private int offset;
     226        private int idx;
     227       
     228        private Point prev = null;
     229        /* 'prev0' is a point that has distance 'offset' from 'prev' and the
     230         * line from 'prev' to 'prev0' is perpendicular to the way segment from
     231         * 'prev' to the next point.
     232         */
     233        private int x_prev0, y_prev0;
     234
     235        public OffsetIterator(List<Node> nodes, int offset) {
     236            this.nodes = nodes;
     237            this.offset = offset;
     238            idx = 0;
     239        }
     240       
     241        @Override
     242        public boolean hasNext() {
     243            return idx < nodes.size();
     244        }
     245
     246        @Override
     247        public Point next() {
     248            if (offset == 0) return nc.getPoint(nodes.get(idx++));
     249           
     250            Point current = nc.getPoint(nodes.get(idx));
     251           
     252            if (idx == nodes.size() - 1) {
     253                ++idx;
     254                return new Point(x_prev0 + current.x - prev.x, y_prev0 + current.y - prev.y);
     255            }
     256
     257            Point next = nc.getPoint(nodes.get(idx+1));
     258
     259            int dx_next = next.x - current.x;
     260            int dy_next = next.y - current.y;
     261            double len_next = Math.sqrt(dx_next*dx_next + dy_next*dy_next);
     262
     263            if (len_next == 0) {
     264                len_next = 1; // value does not matter, because dy_next and dx_next is 0
     265            }
     266
     267            int x_current0 = current.x + (int) Math.round(offset * dy_next / len_next);
     268            int y_current0 = current.y - (int) Math.round(offset * dx_next / len_next);
     269
     270            if (idx==0) {
     271                ++idx;
     272                prev = current;
     273                x_prev0 = x_current0;
     274                y_prev0 = y_current0;
     275                return new Point(x_current0, y_current0);
     276            } else {
     277                int dx_prev = current.x - prev.x;
     278                int dy_prev = current.y - prev.y;
     279               
     280                // determine intersection of the lines parallel to the two
     281                // segments
     282                int det = dx_next*dy_prev - dx_prev*dy_next;
     283               
     284                if (det == 0) {
     285                    ++idx;
     286                    prev = current;
     287                    x_prev0 = x_current0;
     288                    y_prev0 = y_current0;
     289                    return new Point(x_current0, y_current0);
     290                }
     291
     292                int m = dx_next*(y_current0 - y_prev0) - dy_next*(x_current0 - x_prev0);
     293
     294                int cx_ = x_prev0 + (int) Math.round(m * dx_prev / det);
     295                int cy_ = y_prev0 + (int) Math.round(m * dy_prev / det);
     296                ++idx;
     297                prev = current;
     298                x_prev0 = x_current0;
     299                y_prev0 = y_current0;
     300                return new Point(cx_, cy_);
     301            }
     302        }
     303
     304        @Override
     305        public void remove() {
     306            throw new UnsupportedOperationException();
     307        }
     308    }
     309   
    211310    private void displaySegments(GeneralPath path, GeneralPath orientationArrows, GeneralPath onewayArrows, GeneralPath onewayArrowsCasing,
    212311            Color color, BasicStroke line, BasicStroke dashes, Color dashedColor) {
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r4316 r4317  
    202202    @Override
    203203    public void render(final DataSet data, boolean renderVirtualNodes, Bounds bounds) {
    204         long start = System.currentTimeMillis();
     204        //long start = System.currentTimeMillis();
    205205        BBox bbox = new BBox(bounds);
    206206
     
    226226        collectWayStyles(data, sc, bbox);
    227227        collectRelationStyles(data, sc, bbox);
    228         long phase1 = System.currentTimeMillis();
     228        //long phase1 = System.currentTimeMillis();
    229229        sc.drawAll();
    230230        sc = null;
    231231        painter.drawVirtualNodes(data.searchWays(bbox));
    232232
    233         long now = System.currentTimeMillis();
    234         System.err.println(String.format("PAINTING TOOK %d [PHASE1 took %d] (at scale %s)", now - start, phase1 - start, circum));
     233        //long now = System.currentTimeMillis();
     234        //System.err.println(String.format("PAINTING TOOK %d [PHASE1 took %d] (at scale %s)", now - start, phase1 - start, circum));
    235235    }
    236236}
Note: See TracChangeset for help on using the changeset viewer.