/hg/gfx-test: Updated src/org/gfxtest/testsuites/PrintTestCubicC...

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Wed Aug 29 08:53:45 PDT 2012


changeset 54be940ff585 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=54be940ff585
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Wed Aug 29 17:56:15 2012 +0200

	Updated src/org/gfxtest/testsuites/PrintTestCubicCurves.java added basic
	test & functionality to create a Shape based on CubicCurve.


diffstat:

 ChangeLog                                            |    6 +
 src/org/gfxtest/testsuites/PrintTestCubicCurves.java |  120 +++++++++++++++++++
 2 files changed, 126 insertions(+), 0 deletions(-)

diffs (151 lines):

diff -r 1c6da3a3b4fc -r 54be940ff585 ChangeLog
--- a/ChangeLog	Mon Aug 27 11:39:20 2012 +0200
+++ b/ChangeLog	Wed Aug 29 17:56:15 2012 +0200
@@ -1,3 +1,9 @@
+2012-08-29  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/gfxtest/testsuites/PrintTestCubicCurves.java:
+	Updated: added basic test & functionality to create a Shape
+	based on CubicCurve.
+
 2012-08-27  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/gfxtest/testsuites/PrintTestLines.java:
diff -r 1c6da3a3b4fc -r 54be940ff585 src/org/gfxtest/testsuites/PrintTestCubicCurves.java
--- a/src/org/gfxtest/testsuites/PrintTestCubicCurves.java	Mon Aug 27 11:39:20 2012 +0200
+++ b/src/org/gfxtest/testsuites/PrintTestCubicCurves.java	Wed Aug 29 17:56:15 2012 +0200
@@ -40,7 +40,16 @@
 
 package org.gfxtest.testsuites;
 
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.CubicCurve2D;
+
+
+
+import org.gfxtest.callbacks.CubicCurveDrawCallbacks;
 import org.gfxtest.framework.PrintTest;
+import org.gfxtest.framework.TestImage;
+import org.gfxtest.framework.TestResult;
 import org.gfxtest.framework.annotations.GraphicsPrimitive;
 import org.gfxtest.framework.annotations.GraphicsPrimitives;
 import org.gfxtest.framework.annotations.RenderStyle;
@@ -65,6 +74,117 @@
 {
 
     /**
+     * Create Shape which contains one cubic curve.
+     *
+     * @param x1
+     *            x coordinate of the first control point
+     * @param y1
+     *            y coordinate of the first control point
+     * @param x2
+     *            x coordinate of the second control point
+     * @param y2
+     *            y coordinate of the second control point
+     * @param x3
+     *            x coordinate of third control point
+     * @param y3
+     *            y coordinate of third control point
+     * @param x4
+     *            x coordinate of fourth control point
+     * @param y4
+     *            y coordinate of fourth control point
+     * @return newly created shape
+     */
+    private static Shape createCubicCurveShape(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
+    {
+        CubicCurve2D cubicCurve = new CubicCurve2D.Float();
+        // set all four control points
+        cubicCurve.setCurve(x1, y1, x2, y2, x3, y3, x4, y4);
+        return cubicCurve;
+    }
+
+    /**
+     * Method which renders set of cubic curves using various colors and
+     * stroke styles. For each curve, the callback function/method is called to
+     * perform all required setup. Curves are represented by a Shape object.
+     * 
+     * @param image
+     *            image to which lines are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @param verticalStep
+     *            between two near curves
+     * @param cubicCurveCallback
+     *            class containing set of callback methods
+     */
+    private static void drawCubicCurve(TestImage image, Graphics2D graphics, int verticalStep, CubicCurveDrawCallbacks cubicCurveCallback)
+    {
+        // setup rendering
+        cubicCurveCallback.setup(image, graphics);
+
+        // image width and height
+        final int width = image.getWidth();
+        final int height = image.getHeight();
+
+        // horizontal coordinates of curve endpoints
+        final int x1 = BORDER;
+        final int x4 = width - BORDER;
+        final int x2 = (x1 + x4) * 1 / 3;
+        final int x3 = (x1 + x4) * 2 / 3;
+
+        // index to color palette
+        int colorIndex = 0;
+
+        // draw all lines onto a paper
+        for (int y = BORDER * 10; y < height - BORDER * 10; y += verticalStep)
+        {
+            // compute other control points coordinates
+            final int y1 = y;
+            final int y2 = y - (BORDER << 4);
+            final int y3 = y + (BORDER << 4);
+            final int y4 = y;
+            // setup can be made for each line
+            cubicCurveCallback.iterationCallBack(x1, y1, x2, y2, x3, y3, x4, y4, colorIndex++);
+            // create new shape which contains just one line
+            Shape shape = createCubicCurveShape(x1, y1, x2, y2, x3, y3, x4, y4);
+            // render the cubic curve
+            graphics.draw(shape);
+        }
+
+        // cleanup rendering
+        cubicCurveCallback.cleanup();
+    }
+
+    /**
+     * Test basic behavior of method Graphics.draw(Shape).
+     * Cubic curves are rendered with default width and default end caps.
+     * Color of all rendered curves are set to black.
+     * All rendered cubic curves are represented by a Shape object.
+     *
+     * @param image
+     *            image to which lines are to be drawn
+     * @param graphics2d
+     *            graphics canvas
+     * @return test result status - PASSED, FAILED or ERROR
+     */
+    public TestResult testDrawCubicCurvesBasicStyle(TestImage image, Graphics2D graphics)
+    {
+        drawCubicCurve(image, graphics, CUBIC_CURVE_STEP, new CubicCurveDrawCallbacks()
+        {
+            /**
+             * Callback function called before each cubic curve is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int index)
+            {
+                return;
+            }
+        });
+
+        // test return value
+        return TestResult.PASSED;
+    }
+
+    /**
      * Entry point to the test suite.
      * 
      * @param args



More information about the distro-pkg-dev mailing list