Changeset 2890 in josm for trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
- Timestamp:
- 2010-01-24T17:55:56+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r2801 r2890 27 27 28 28 public class MapPainter { 29 private static final double PHI = Math.toRadians(20);30 31 29 private final Graphics2D g; 32 30 private final NavigatableComponent nc; … … 81 79 82 80 public void drawWay(Way way, Color color, int width, float dashed[], Color dashedColor, boolean showDirection, 83 boolean showHeadArrowOnly) {81 boolean reversedDirection, boolean showHeadArrowOnly) { 84 82 85 83 GeneralPath path = new GeneralPath(); … … 91 89 Point p = nc.getPoint(n); 92 90 if(lastPoint != null) { 93 drawSegment(path, lastPoint, p, (showHeadArrowOnly ? !it.hasNext() : showDirection));91 drawSegment(path, lastPoint, p, showHeadArrowOnly ? !it.hasNext() : showDirection, reversedDirection); 94 92 } 95 93 lastPoint = p; … … 128 126 } 129 127 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) { 131 133 if (isSegmentVisible(p1, p2)) { 134 135 /* draw segment line */ 132 136 path.moveTo(p1.x, p1.y); 133 137 path.lineTo(p2.x, p2.y); 134 138 139 /* draw arrow */ 135 140 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); 140 156 } 141 157 }
Note:
See TracChangeset
for help on using the changeset viewer.