Changeset 3565 in josm for trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
- Timestamp:
- 2010-09-25T16:35:08+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
r3398 r3565 54 54 private final Collection<String> regionalNameOrder; 55 55 56 private static final double PHI = Math.toRadians(20); 57 private static final double cosPHI = Math.cos(PHI); 58 private static final double sinPHI = Math.sin(PHI); 59 56 60 public MapPainter(MapPaintSettings settings, Graphics2D g, boolean inactive, NavigatableComponent nc, boolean virtual, double dist, double circum) { 57 61 this.g = g; … … 85 89 86 90 GeneralPath path = new GeneralPath(); 91 GeneralPath arrows = new GeneralPath(); 92 Rectangle bounds = g.getClipBounds(); 93 bounds.grow(100, 100); // avoid arrow heads at the border 87 94 88 95 Point lastPoint = null; 96 boolean initialMoveToNeeded = true; 89 97 Iterator<Node> it = way.getNodes().iterator(); 90 98 while (it.hasNext()) { … … 92 100 Point p = nc.getPoint(n); 93 101 if(lastPoint != null) { 94 drawSegment(path, lastPoint, p, showHeadArrowOnly ? !it.hasNext() : showDirection, reversedDirection); 102 Point p1 = lastPoint; 103 Point p2 = p; 104 105 /** 106 * Do custom clipping to work around openjdk bug. It leads to 107 * drawing artefacts when zooming in a lot. (#4289, #4424) 108 * (Looks like int overflow.) 109 */ 110 LineClip clip = new LineClip(p1, p2, bounds); 111 if (clip.execute()) { 112 if (!p1.equals(clip.getP1())) { 113 p1 = clip.getP1(); 114 path.moveTo(p1.x, p1.y); 115 } else if (initialMoveToNeeded) { 116 initialMoveToNeeded = false; 117 path.moveTo(p1.x, p1.y); 118 } 119 p2 = clip.getP2(); 120 path.lineTo(p2.x, p2.y); 121 122 /* draw arrow */ 123 if (showHeadArrowOnly ? !it.hasNext() : showDirection) { 124 if (reversedDirection) { 125 Point tmp = p1; 126 p1 = p2; 127 p2 = tmp; 128 } 129 final double l = 10. / p1.distance(p2); 130 131 final double sx = l * (p1.x - p2.x); 132 final double sy = l * (p1.y - p2.y); 133 134 arrows.moveTo(p2.x, p2.y); 135 arrows.lineTo (p2.x + (int) Math.round(cosPHI * sx - sinPHI * sy), p2.y + (int) Math.round(sinPHI * sx + cosPHI * sy)); 136 arrows.moveTo (p2.x + (int) Math.round(cosPHI * sx + sinPHI * sy), p2.y + (int) Math.round(- sinPHI * sx + cosPHI * sy)); 137 arrows.lineTo(p2.x, p2.y); 138 } 139 } 95 140 } 96 141 lastPoint = p; 97 142 } 98 displaySegments(path, color, width, dashed, dashedColor);99 } 100 101 private void displaySegments(GeneralPath path, Color color, int width, float dashed[], Color dashedColor) {143 displaySegments(path, arrows, color, width, dashed, dashedColor); 144 } 145 146 private void displaySegments(GeneralPath path, GeneralPath arrows, Color color, int width, float dashed[], Color dashedColor) { 102 147 g.setColor(inactive ? inactiveColor : color); 103 148 if (useStrokes) { … … 109 154 } 110 155 g.draw(path); 156 g.draw(arrows); 111 157 112 158 if(!inactive && useStrokes && dashedColor != null) { … … 122 168 } 123 169 g.draw(path); 170 g.draw(arrows); 124 171 } 125 172 126 173 if(useStrokes) { 127 174 g.setStroke(new BasicStroke()); 128 }129 }130 131 private static final double PHI = Math.toRadians(20);132 private static final double cosPHI = Math.cos(PHI);133 private static final double sinPHI = Math.sin(PHI);134 135 private void drawSegment(GeneralPath path, Point p1, Point p2, boolean showDirection, boolean reversedDirection) {136 boolean drawIt = false;137 if (Main.isOpenjdk) {138 /**139 * Work around openjdk bug. It leads to drawing artefacts when zooming in a lot. (#4289, #4424)140 * (It looks like int overflow when clipping.) We do custom clipping.141 */142 Rectangle bounds = g.getClipBounds();143 bounds.grow(100, 100); // avoid arrow heads at the border144 LineClip clip = new LineClip();145 drawIt = clip.cohenSutherland(p1.x, p1.y, p2.x, p2.y, bounds.x, bounds.y, bounds.x+bounds.width, bounds.y+bounds.height);146 p1 = clip.getP1();147 p2 = clip.getP2();148 } else {149 drawIt = isSegmentVisible(p1, p2);150 }151 if (drawIt) {152 /* draw segment line */153 path.moveTo(p1.x, p1.y);154 path.lineTo(p2.x, p2.y);155 156 /* draw arrow */157 if (showDirection) {158 Point q1 = p1;159 Point q2 = p2;160 if (reversedDirection) {161 q1 = p2;162 q2 = p1;163 path.moveTo(q2.x, q2.y);164 }165 final double l = 10. / q1.distance(q2);166 167 final double sx = l * (q1.x - q2.x);168 final double sy = l * (q1.y - q2.y);169 170 path.lineTo (q2.x + (int) Math.round(cosPHI * sx - sinPHI * sy), q2.y + (int) Math.round(sinPHI * sx + cosPHI * sy));171 path.moveTo (q2.x + (int) Math.round(cosPHI * sx + sinPHI * sy), q2.y + (int) Math.round(- sinPHI * sx + cosPHI * sy));172 path.lineTo(q2.x, q2.y);173 }174 175 } 175 176 }
Note:
See TracChangeset
for help on using the changeset viewer.