Changeset 4042 in josm


Ignore:
Timestamp:
2011-04-20T11:00:29+02:00 (13 years ago)
Author:
bastiK
Message:

fixed #6218 - horizontal lines with larger dataset (openjdk does not like NaN in Path2D)

File:
1 edited

Legend:

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

    r4006 r4042  
    156156                    /* draw arrow */
    157157                    if (showHeadArrowOnly ? !it.hasNext() : showOrientation) {
    158                         final double l =  (10. + line.getLineWidth()) / p1.distance(p2);
    159 
    160                         final double sx = l * (p1.x - p2.x);
    161                         final double sy = l * (p1.y - p2.y);
    162 
    163                         orientationArrows.moveTo(p2.x, p2.y);
    164                         orientationArrows.lineTo (p2.x + cosPHI * sx - sinPHI * sy, p2.y + sinPHI * sx + cosPHI * sy);
    165                         orientationArrows.moveTo (p2.x + cosPHI * sx + sinPHI * sy, p2.y - sinPHI * sx + cosPHI * sy);
    166                         orientationArrows.lineTo(p2.x, p2.y);
     158                        final double segmentLength = p1.distance(p2);
     159                        if (segmentLength != 0.0) {
     160                            final double l =  (10. + line.getLineWidth()) / segmentLength;
     161
     162                            final double sx = l * (p1.x - p2.x);
     163                            final double sy = l * (p1.y - p2.y);
     164
     165                            double tmp = p2.x + cosPHI * sx - sinPHI * sy;
     166                            orientationArrows.moveTo (p2.x + cosPHI * sx - sinPHI * sy, p2.y + sinPHI * sx + cosPHI * sy);
     167                            orientationArrows.lineTo(p2.x, p2.y);
     168                            orientationArrows.lineTo (p2.x + cosPHI * sx + sinPHI * sy, p2.y - sinPHI * sx + cosPHI * sy);
     169                        }
    167170                    }
    168171                    if (showOneway) {
    169172                        final double segmentLength = p1.distance(p2);
    170                         final double nx = (p2.x - p1.x) / segmentLength;
    171                         final double ny = (p2.y - p1.y) / segmentLength;
    172 
    173                         final double interval = 60;
    174                         // distance from p1
    175                         double dist = interval - (wayLength % interval);
    176 
    177                         while (dist < segmentLength) {
    178                             for (Pair<Float, GeneralPath> sizeAndPath : Arrays.asList(new Pair[] {
    179                                     new Pair<Float, GeneralPath>(3f, onewayArrowsCasing),
    180                                     new Pair<Float, GeneralPath>(2f, onewayArrows)})) {
    181 
    182                                 // scale such that border is 1 px
    183                                 final double fac = - (onewayReversed ? -1 : 1) * sizeAndPath.a * (1 + sinPHI) / (sinPHI * cosPHI);
    184                                 final double sx = nx * fac;
    185                                 final double sy = ny * fac;
    186 
    187                                 // Attach the triangle at the incenter and not at the tip.
    188                                 // Makes the border even at all sides.
    189                                 final double x = p1.x + nx * (dist + (onewayReversed ? -1 : 1) * (sizeAndPath.a / sinPHI));
    190                                 final double y = p1.y + ny * (dist + (onewayReversed ? -1 : 1) * (sizeAndPath.a / sinPHI));
    191 
    192                                 sizeAndPath.b.moveTo(x, y);
    193                                 sizeAndPath.b.lineTo (x + cosPHI * sx - sinPHI * sy, y + sinPHI * sx + cosPHI * sy);
    194                                 sizeAndPath.b.lineTo (x + cosPHI * sx + sinPHI * sy, y - sinPHI * sx + cosPHI * sy);
    195                                 sizeAndPath.b.lineTo(x, y);
     173                        if (segmentLength != 0.0) {
     174                            final double nx = (p2.x - p1.x) / segmentLength;
     175                            final double ny = (p2.y - p1.y) / segmentLength;
     176
     177                            final double interval = 60;
     178                            // distance from p1
     179                            double dist = interval - (wayLength % interval);
     180
     181                            while (dist < segmentLength) {
     182                                for (Pair<Float, GeneralPath> sizeAndPath : Arrays.asList(new Pair[] {
     183                                        new Pair<Float, GeneralPath>(3f, onewayArrowsCasing),
     184                                        new Pair<Float, GeneralPath>(2f, onewayArrows)})) {
     185
     186                                    // scale such that border is 1 px
     187                                    final double fac = - (onewayReversed ? -1 : 1) * sizeAndPath.a * (1 + sinPHI) / (sinPHI * cosPHI);
     188                                    final double sx = nx * fac;
     189                                    final double sy = ny * fac;
     190
     191                                    // Attach the triangle at the incenter and not at the tip.
     192                                    // Makes the border even at all sides.
     193                                    final double x = p1.x + nx * (dist + (onewayReversed ? -1 : 1) * (sizeAndPath.a / sinPHI));
     194                                    final double y = p1.y + ny * (dist + (onewayReversed ? -1 : 1) * (sizeAndPath.a / sinPHI));
     195
     196                                    sizeAndPath.b.moveTo(x, y);
     197                                    sizeAndPath.b.lineTo (x + cosPHI * sx - sinPHI * sy, y + sinPHI * sx + cosPHI * sy);
     198                                    sizeAndPath.b.lineTo (x + cosPHI * sx + sinPHI * sy, y - sinPHI * sx + cosPHI * sy);
     199                                    sizeAndPath.b.lineTo(x, y);
     200                                }
     201                                dist += interval;
    196202                            }
    197                             dist += interval;
    198203                        }
    199204                        wayLength += segmentLength;
Note: See TracChangeset for help on using the changeset viewer.