jfree / jfreesvg

A fast, lightweight Java library for creating Scalable Vector Graphics (SVG) output.
http://www.jfree.org/jfreesvg
GNU General Public License v3.0
319 stars 58 forks source link

Problem when rotating to horizontal #39

Closed rmcdouga closed 3 years ago

rmcdouga commented 3 years ago

I'm seeing an issue when I run the following test:

    @Test
    void testSvgProblem() throws Exception {
        SVGGraphics2D g2 = new SVGGraphics2D(4986, 3216);

        int marker_size = 65;
        int local_diameter = 600;
        int radius = local_diameter/2;
        double arc_size = Math.PI / 12;

        g2.translate(1000, 500);

        g2.setColor(Color.BLUE);
        g2.setStroke(new BasicStroke(2));
        g2.drawOval(-radius, -radius, local_diameter, local_diameter);

        // draw sector lines
        g2.drawLine(0, -radius - marker_size / 2, 0, -radius + marker_size / 2);

        g2.rotate(arc_size*2);  // rotate past the orbit arc

        // draw sector lines
        int halfMarkerSize = marker_size / 2;
        g2.drawLine(0, -radius - halfMarkerSize, 0, -radius + halfMarkerSize);

        for (int i = 0; i < 6; i++) {
            g2.rotate(arc_size);
            g2.drawLine(0, -radius - halfMarkerSize, 0, -radius + halfMarkerSize);
            g2.drawString(Integer.toString(i), 0, -radius);
        }

        String result = g2.getSVGDocument();
        Files.writeString(TestConstants.ACTUAL_RESULTS_DIR.resolve("TestSvgProblem.svg"), result);
    }

It creates a circle and then creates a series of lines that are perpendicular to the circle. When the line is horizontal (as in line 3), the transformation matrix looks like it is incorrect.

jfree commented 3 years ago

Does this happen with version 4.2? I think it is probably related to https://github.com/jfree/jfreesvg/issues/35 which is fixed for the next release. I have a couple more things to tidy up then version 5.0 will be released. For now I would recommend to drop back to version 4.1.

rmcdouga commented 3 years ago

You're correct. This happens in 4.2 but does not in 4.1.

I have backed off to 4.1 for now. Thanks for the help!