Changeset 12455 in josm for trunk


Ignore:
Timestamp:
2017-07-07T21:27:45+02:00 (7 years ago)
Author:
michael2402
Message:

Fix #14926: Preserve image phase when clamping a line.

Location:
trunk
Files:
5 added
3 edited

Legend:

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

    r12450 r12455  
    655655        }
    656656
    657         double startOffset = phase % repeat;
    658         if (startOffset < 0) {
    659             startOffset += repeat;
    660         }
     657        double startOffset = computeStartOffset(phase, repeat);
    661658
    662659        BufferedImage image = pattern.getImage(disabled);
    663660
    664         path.visitClippedLine(startOffset, repeat, (inLineOffset, start, end, startIsOldEnd) -> {
     661        path.visitClippedLine(repeat, (inLineOffset, start, end, startIsOldEnd) -> {
    665662            final double segmentLength = start.distanceToInView(end);
    666663            if (segmentLength < 0.1) {
     
    679676
    680677            // The start of the next image
    681             double imageStart = -(inLineOffset % repeat);
     678            double imageStart = -((inLineOffset + startOffset) % repeat);
    682679
    683680            while (imageStart < segmentLength) {
     
    691688            g.setTransform(saveTransform);
    692689        });
     690    }
     691
     692    private static double computeStartOffset(double phase, final double repeat) {
     693        double startOffset = phase % repeat;
     694        if (startOffset < 0) {
     695            startOffset += repeat;
     696        }
     697        return startOffset;
    693698    }
    694699
     
    12911296            double interval = 60;
    12921297
    1293             path.visitClippedLine(0, 60, (inLineOffset, start, end, startIsOldEnd) -> {
     1298            path.visitClippedLine(60, (inLineOffset, start, end, startIsOldEnd) -> {
    12941299                double segmentLength = start.distanceToInView(end);
    12951300                if (segmentLength > 0.001) {
  • trunk/src/org/openstreetmap/josm/gui/draw/MapViewPath.java

    r12450 r12455  
    254254                length += f;
    255255            }
    256             return visitClippedLine(((BasicStroke) stroke).getDashPhase(), length, consumer);
     256            return visitClippedLine(length, consumer);
    257257        } else {
    258             return visitClippedLine(0, 0, consumer);
     258            return visitClippedLine(0, consumer);
    259259        }
    260260    }
     
    263263     * Visits all straight segments of this path. The segments are clamped to the view.
    264264     * If they are clamped, the start points are aligned with the pattern.
    265      * @param strokeOffset The initial offset of the pattern
    266      * @param strokeLength The dash pattern length. 0 to use no pattern.
     265     * @param strokeLength The dash pattern length. 0 to use no pattern. Only segments of this length will be removed from the line.
    267266     * @param consumer The consumer to call for each segment
    268267     * @return false if visiting the path failed because there e.g. were non-straight segments.
    269268     * @since 11147
    270269     */
    271     public boolean visitClippedLine(double strokeOffset, double strokeLength, PathSegmentConsumer consumer) {
    272         return new ClampingPathVisitor(state.getViewClipRectangle(), strokeOffset, strokeLength, consumer)
     270    public boolean visitClippedLine(double strokeLength, PathSegmentConsumer consumer) {
     271        return new ClampingPathVisitor(state.getViewClipRectangle(), strokeLength, consumer)
    273272            .visit(this);
    274273    }
     
    400399         * Create a new {@link ClampingPathVisitor}
    401400         * @param clip View clip rectangle
    402          * @param strokeOffset Initial stroke offset
    403401         * @param strokeLength Total length of a stroke sequence
    404402         * @param consumer The consumer to notify of the path segments.
    405403         */
    406         ClampingPathVisitor(MapViewRectangle clip, double strokeOffset, double strokeLength, PathSegmentConsumer consumer) {
     404        ClampingPathVisitor(MapViewRectangle clip, double strokeLength, PathSegmentConsumer consumer) {
    407405            this.clip = clip;
    408             this.strokeProgress = Math.min(strokeLength - strokeOffset, 0);
    409406            this.strokeLength = strokeLength;
    410407            this.consumer = consumer;
  • trunk/test/functional/org/openstreetmap/josm/gui/mappaint/MapCSSRendererTest.java

    r12454 r12455  
    111111
    112112                /** Tests repeat-image feature for ways */
    113                 new TestConfig("way-repeat-image", AREA_DEFAULT)
     113                new TestConfig("way-repeat-image", AREA_DEFAULT),
     114                /** Tests the clamping for repeat-images and repeat-image-phase */
     115                new TestConfig("way-repeat-image-clamp", AREA_DEFAULT)
    114116
    115117                ).map(e -> new Object[] {e, e.testDirectory})
Note: See TracChangeset for help on using the changeset viewer.