diff --git a/src/main/java/org/marlin/pisces/DStroker.java b/src/main/java/org/marlin/pisces/DStroker.java index 3f1a650..84c2112 100644 --- a/src/main/java/org/marlin/pisces/DStroker.java +++ b/src/main/java/org/marlin/pisces/DStroker.java @@ -580,7 +580,8 @@ public void closePath() { return; } - if (sOutCode == 0) { + // basic acceptance criteria + if ((sOutCode & cOutCode) == 0) { if (cx0 != sx0 || cy0 != sy0) { lineTo(sx0, sy0, true); } diff --git a/src/main/java/org/marlin/pisces/Stroker.java b/src/main/java/org/marlin/pisces/Stroker.java index ff4e954..20a3da3 100644 --- a/src/main/java/org/marlin/pisces/Stroker.java +++ b/src/main/java/org/marlin/pisces/Stroker.java @@ -582,7 +582,8 @@ public void closePath() { return; } - if (sOutCode == 0) { + // basic acceptance criteria + if ((sOutCode & cOutCode) == 0) { if (cx0 != sx0 || cy0 != sy0) { lineTo(sx0, sy0, true); } diff --git a/src/main/java/test/LineTests.java b/src/main/java/test/LineTests.java index a3ea6ba..5369194 100644 --- a/src/main/java/test/LineTests.java +++ b/src/main/java/test/LineTests.java @@ -1,12 +1,10 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. + * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -28,13 +26,13 @@ import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; +import java.awt.geom.Ellipse2D; import java.awt.geom.Path2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; -import org.marlin.pisces.MarlinProperties; -import sun.java2d.pipe.RenderingEngine; +import sun.java2d.marlin.MarlinProperties; /** * Simple Line rendering test using GeneralPath to enable Pisces / marlin / ductus renderers @@ -42,10 +40,26 @@ public class LineTests { public static void main(String[] args) { - final float lineStroke = 2f; - final int size = 2600; - System.out.println("Testing renderer = " + RenderingEngine.getInstance().getClass().getName()); + final float lineStroke = 4f; + final int size = 1000; + + // First display which renderer is tested: + // JDK9 only: + System.setProperty("sun.java2d.renderer.verbose", "true"); + System.out.println("Testing renderer: "); + // Other JDK: + String renderer = "undefined"; + try { + renderer = sun.java2d.pipe.RenderingEngine.getInstance().getClass().getName(); + System.out.println(renderer); + } catch (Throwable th) { + // may fail with JDK9 jigsaw (jake) + if (false) { + System.err.println("Unable to get RenderingEngine.getInstance()"); + th.printStackTrace(); + } + } System.out.println("LineTests: size = " + size); @@ -87,6 +101,10 @@ public static void main(String[] args) { private static void paint(final Graphics2D g2d, final float size) { + final float half = size / 2f; + final float radius = 166f; + g2d.draw(new Ellipse2D.Float(half - radius, half - radius, 2f * radius, 2f * radius)); + final Path2D.Float path = new Path2D.Float(); for (float angle = 1f / 3f; angle <= 90f; angle += 1f) { @@ -103,4 +121,4 @@ private static void paint(final Graphics2D g2d, final float size) { g2d.draw(path); } } -} \ No newline at end of file +} diff --git a/src/main/java/test/QuickSort.java b/src/main/java/test/QuickSort.java index 6fb1da3..2408dc3 100644 --- a/src/main/java/test/QuickSort.java +++ b/src/main/java/test/QuickSort.java @@ -1,12 +1,10 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. + * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -32,7 +30,7 @@ final class QuickSort { /** * Sorts the specified sub-array of integers into ascending order. */ - static void sort1(final int x[], final int y[], final int off, final int len) { + static void sort1(final int[] x, final int[] y, final int off, final int len) { int t; // Insertion sort on smallest arrays if (len < 20) { // 7 in jdk8 or 20 as benchmark ? @@ -150,7 +148,7 @@ static void sort1(final int x[], final int y[], final int off, final int len) { /** * Returns the index of the median of the three indexed integers. */ - private static int med3(final int x[], final int a, final int b, final int c) { + private static int med3(final int[] x, final int a, final int b, final int c) { return (x[a] < x[b] ? (x[b] < x[c] ? b : x[a] < x[c] ? c : a) : (x[b] > x[c] ? b : x[a] > x[c] ? c : a)); diff --git a/src/main/java/test/StrokeClipBugTest.java b/src/main/java/test/StrokeClipBugTest.java new file mode 100644 index 0000000..f66b27c --- /dev/null +++ b/src/main/java/test/StrokeClipBugTest.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.geom.Path2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; + +/** + * Simple Stroke clipping BUG 0.8.1 test using GeneralPath + * + * run it with -Dsun.java2d.renderer.clip=true/false + */ +public class StrokeClipBugTest { + + private final static int N = 1; + + private final static boolean DO_FILL = true; + private final static boolean DO_DRAW = true; + + public static void main(String[] args) { + + final float lineStroke = 4f; + final int size = 400; + + // First display which renderer is tested: + // JDK9 only: + System.setProperty("sun.java2d.renderer.verbose", "true"); + System.out.println("Testing renderer: "); + // Other JDK: + String renderer = "undefined"; + try { + renderer = sun.java2d.pipe.RenderingEngine.getInstance().getClass().getName(); + System.out.println(renderer); + } catch (Throwable th) { + // may fail with JDK9 jigsaw (jake) + if (false) { + System.err.println("Unable to get RenderingEngine.getInstance()"); + th.printStackTrace(); + } + } + + System.out.println("StrokeClipBugTest: size = " + size); + + final BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); + + final Graphics2D g2d = (Graphics2D) image.getGraphics(); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + + g2d.setClip(0, 0, size, size); + g2d.setStroke( + new BasicStroke(lineStroke, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 20f) + ); + + g2d.setBackground(Color.WHITE); + g2d.clearRect(0, 0, size, size); + + for (int i = 0; i < N; i++) { + final long start = System.nanoTime(); + + paint(g2d, size); + + final long time = System.nanoTime() - start; + + System.out.println("paint: duration= " + (1e-6 * time) + " ms."); + } + + final String clipFlag = System.getProperty("sun.java2d.renderer.clip"); + try { + final File file = new File("StrokeClipBugTest-clip-" + clipFlag + ".png"); + + System.out.println("Writing file: " + file.getAbsolutePath()); + ImageIO.write(image, "PNG", file); + } catch (IOException ex) { + ex.printStackTrace(); + } finally { + g2d.dispose(); + } + } + + private static void paint(final Graphics2D g2d, final float size) { + final Shape path = createPath(); + + if (DO_FILL) { + g2d.setColor(Color.BLUE); + g2d.fill(path); + } + + if (DO_DRAW) { + g2d.setColor(Color.RED); + g2d.draw(path); + } + } + + private static Shape createPath() { + final Path2D p = new Path2D.Float(); + // outside top + p.moveTo(100, -100); + + p.lineTo(100.0, 50); + p.lineTo(300.0, 200); + + p.closePath(); + + return p; + } +} diff --git a/src/main/java/test/StrokeClipTest.java b/src/main/java/test/StrokeClipTest.java index 0e2b3a6..3dbe0c4 100644 --- a/src/main/java/test/StrokeClipTest.java +++ b/src/main/java/test/StrokeClipTest.java @@ -36,8 +36,7 @@ import javax.imageio.ImageIO; /** - * Simple Line rendering test using GeneralPath to enable Pisces / marlin / - * ductus renderers + * Simple Stroke clipping test using GeneralPath */ public class StrokeClipTest { @@ -47,13 +46,11 @@ public class StrokeClipTest { private final static boolean DO_CIRCLE = false; - private final static boolean DO_FILL = false; - private final static boolean DO_DRAW = true; + private final static boolean DO_FILL = true; + private final static boolean DO_DRAW = false; private final static float CIRCLE_RADIUS = 100f; - private final static float RECT_SIZE = 100f; - private final static double sqrt2 = Math.sqrt(2); public static void main(String[] args) { @@ -140,8 +137,6 @@ private static void paint(final Graphics2D g2d, final float size) { private static Shape createPath(final float size) { if (DO_CIRCLE) { - final float c = (float) (0.5f * size - CIRCLE_RADIUS / sqrt2); - return new Ellipse2D.Float( -CIRCLE_RADIUS, 100,