Ignore:
Timestamp:
2010-01-24T17:55:56+01:00 (17 years ago)
Author:
bastiK
Message:

Reverse Arrows for 'oneway=-1' and similar (see #2387).
More efficient calculation of arrow geometry.
Test file for Arrow direction added.

File:
1 edited

Legend:

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

    r2801 r2890  
    2727
    2828public class MapPainter {
    29     private static final double PHI = Math.toRadians(20);
    30 
    3129    private final Graphics2D g;
    3230    private final NavigatableComponent nc;
     
    8179
    8280    public void drawWay(Way way, Color color, int width, float dashed[], Color dashedColor, boolean showDirection,
    83             boolean showHeadArrowOnly) {
     81            boolean reversedDirection, boolean showHeadArrowOnly) {
    8482
    8583        GeneralPath path = new GeneralPath();
     
    9189            Point p = nc.getPoint(n);
    9290            if(lastPoint != null) {
    93                 drawSegment(path, lastPoint, p, (showHeadArrowOnly ? !it.hasNext() : showDirection));
     91                drawSegment(path, lastPoint, p, showHeadArrowOnly ? !it.hasNext() : showDirection, reversedDirection);
    9492            }
    9593            lastPoint = p;
     
    128126    }
    129127
    130     private void drawSegment(GeneralPath path, Point p1, Point p2, boolean showDirection) {
     128    private static final double PHI = Math.toRadians(20);
     129    private static final double cosPHI = Math.cos(PHI);
     130    private static final double sinPHI = Math.sin(PHI);
     131
     132    private void drawSegment(GeneralPath path, Point p1, Point p2, boolean showDirection, boolean reversedDirection) {
    131133        if (isSegmentVisible(p1, p2)) {
     134
     135            /* draw segment line */
    132136            path.moveTo(p1.x, p1.y);
    133137            path.lineTo(p2.x, p2.y);
    134138
     139            /* draw arrow */
    135140            if (showDirection) {
    136                 double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI;
    137                 path.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI)));
    138                 path.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI)));
    139                 path.lineTo(p2.x, p2.y);
     141                Point q1 = p1;
     142                Point q2 = p2;
     143                if (reversedDirection) {
     144                    q1 = p2;
     145                    q2 = p1;
     146                    path.moveTo(q2.x, q2.y);
     147                }
     148                final double l =  10. / q1.distance(q2);
     149
     150                final double sx = l * (q1.x - q2.x);
     151                final double sy = l * (q1.y - q2.y);
     152
     153                path.lineTo (q2.x + (int) Math.round(cosPHI * sx - sinPHI * sy), q2.y + (int) Math.round(sinPHI * sx + cosPHI * sy));
     154                path.moveTo (q2.x + (int) Math.round(cosPHI * sx + sinPHI * sy), q2.y + (int) Math.round(- sinPHI * sx + cosPHI * sy));
     155                path.lineTo(q2.x, q2.y);
    140156            }
    141157        }
Note: See TracChangeset for help on using the changeset viewer.