Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8316741

BasicStroke.createStrokedShape miter-limits failing on small shapes

    XMLWordPrintable

Details

    • 2d
    • b25
    • 20
    • b21
    • generic
    • generic

    Backports

      Description

        ADDITIONAL SYSTEM INFORMATION :
        Linux / OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)


        A DESCRIPTION OF THE PROBLEM :
        The below source code is expected to create a sharp point at the join of the two lines, and does in all versions of the JVM from about Java through Java 19

        In Java 21 the point is being rounded.

        It looks to be related to the fact that the shape is very small but drawn through an AffineTransform, and it looks to be related to createStrokedShape: if I simple draw the path, I get a sharp point.

        REGRESSION : Last worked in version 19

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the attached, look at the output file "out.png"

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        A sharp point
        ACTUAL -
        A round point

        ---------- BEGIN SOURCE ----------
        import java.io.*;
        import java.awt.*;
        import java.awt.image.*;
        import java.awt.geom.*;
        import javax.imageio.*;

        public class Test {
            public static void main(String[] args) throws Exception {
                // Gives incorrect results in Java 21, correct in Java 19 and earlier.
                BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
                Graphics2D g = image.createGraphics();
                g.setPaint(Color.WHITE);
                g.fillRect(0, 0, 100, 100);
                g.setPaint(Color.BLACK);
                g.setTransform(new AffineTransform(100, 0, 0, 100, 0, 0));
                BasicStroke stroke = new BasicStroke(0.1f, 0, 0, 10);
                Path2D p = new Path2D.Float();
                p.moveTo(1, 0.2f);
                p.lineTo(0.4f, 0.4f);
                p.lineTo(1, 0.6f);
                Shape outline = stroke.createStrokedShape(p);
                g.fill(outline);
                g.dispose();
                ImageIO.write(image, "png", new File("out.png"));
            }
        }

        ---------- END SOURCE ----------

        FREQUENCY : always


        Attachments

          1. 20b24out.png
            20b24out.png
            0.6 kB
          2. 20b25out.png
            20b25out.png
            0.6 kB
          3. Test.java
            0.9 kB

          Issue Links

            Activity

              People

                lbourges Laurent Bourgès
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: