/hg/gfx-test: NormalCubicCurves: refactoring, added more test ca...
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Thu Aug 4 06:41:38 PDT 2011
changeset 6fbdab4d7a3c in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=6fbdab4d7a3c
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Thu Aug 04 15:43:15 2011 +0200
NormalCubicCurves: refactoring, added more test cases including
special cases (multiple control points).
diffstat:
ChangeLog | 6 +
src/org/gfxtest/framework/CubicCurvePointSet.java | 409 +++++++++
src/org/gfxtest/testsuites/NormalCubicCurves.java | 786 +++++++++++++----
src/org/gfxtest/testsuites/NormalQuadraticCurves.java | 7 +-
4 files changed, 993 insertions(+), 215 deletions(-)
diffs (truncated from 1431 to 500 lines):
diff -r 98d8ac4bd4cb -r 6fbdab4d7a3c ChangeLog
--- a/ChangeLog Thu Aug 04 12:01:15 2011 +0200
+++ b/ChangeLog Thu Aug 04 15:43:15 2011 +0200
@@ -1,3 +1,9 @@
+2011-08-04 Pavel Tisnovsky <ptisnovs at redhat.com>
+ * src/org/gfxtest/framework/CubicCurvePointSet.java: added
+ * src/org/gfxtest/testsuites/NormalCubicCurves.java:
+ Refactoring, added more test cases including special cases (multiple
+ control points).
+
2011-08-04 Pavel Tisnovsky <ptisnovs at redhat.com>
* diff.diff: removed as it's just a garbage.
* src/org/gfxtest/testsuites/NormalQuadraticCurves.java:
diff -r 98d8ac4bd4cb -r 6fbdab4d7a3c src/org/gfxtest/framework/CubicCurvePointSet.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/gfxtest/framework/CubicCurvePointSet.java Thu Aug 04 15:43:15 2011 +0200
@@ -0,0 +1,409 @@
+/*
+ Java gfx-test framework
+
+ Copyright (C) 2010, 2011 Red Hat
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version.
+*/
+
+package org.gfxtest.framework;
+
+
+
+/**
+ * Class used to store all four control points of cubic curve. Coordinates of
+ * control points are computed from test image width and height.
+ *
+ * @author Pavel Tisnovsky
+ */
+public class CubicCurvePointSet
+{
+ /**
+ * Default Y offset of curve end points.
+ */
+ private static final int DEFAULT_Y_OFFSET = 40;
+
+ /**
+ * Set of points x-coordinates.
+ */
+ private int[] x = new int[4];
+
+ /**
+ * Set of points t-coordinates.
+ */
+ private int[] y = new int[4];
+
+ /**
+ * Constructor which computes all four control points from the dimensions of
+ * test image.
+ *
+ * @param image
+ */
+ public CubicCurvePointSet(TestImage image)
+ {
+ // compute width and height of test image
+ int width = image.getWidth();
+ int height = image.getHeight();
+
+ // compute control points coordinates
+ this.x[0] = computeX1(width);
+ this.y[0] = computeY1();
+ this.x[1] = computeX2(width);
+ this.y[1] = computeY2(height);
+ this.x[2] = computeX3(width);
+ this.y[2] = computeY3(height);
+ this.x[3] = computeX4(width);
+ this.y[3] = computeY4(height);
+ }
+
+ /**
+ * Compute X coordinate of first curve end point.
+ *
+ * @param width
+ * canvas width
+ * @return X coordinate of first curve end point.
+ */
+ private int computeX1(int width)
+ {
+ return width >> 2;
+ }
+
+ /**
+ * Compute X coordinate of curve first control point.
+ *
+ * @param width
+ * canvas width
+ * @return X coordinate of curve first control point.
+ */
+ private int computeX2(int width)
+ {
+ return width - DEFAULT_Y_OFFSET;
+ }
+
+ /**
+ * Compute X coordinate of curve second control point.
+ *
+ * @param width
+ * canvas width
+ * @return X coordinate of curve second control point.
+ */
+ private int computeX3(int width)
+ {
+ return DEFAULT_Y_OFFSET;
+ }
+
+ /**
+ * Compute X coordinate of second curve end point.
+ *
+ * @param width
+ * canvas width
+ * @return X coordinate of second curve end point.
+ */
+ private int computeX4(int width)
+ {
+ return width * 3 / 4;
+ }
+
+ /**
+ * Compute Y coordinate of first curve end point.
+ *
+ * @return Y coordinate of first curve end point.
+ */
+ private int computeY1()
+ {
+ return DEFAULT_Y_OFFSET;
+ }
+
+ /**
+ * Compute Y coordinate of curve first control point.
+ *
+ * @param height
+ * canvas height
+ * @return Y coordinate of curve first control point.
+ */
+ private int computeY2(int height)
+ {
+ return height * 3/4;
+ }
+
+ /**
+ * Compute Y coordinate of curve second control point.
+ *
+ * @param height
+ * canvas height
+ * @return Y coordinate of curve second control point.
+ */
+ private int computeY3(int height)
+ {
+ return height * 3/4;
+ }
+
+ /**
+ * Compute Y coordinate of second curve end point.
+ *
+ * @return Y coordinate of second curve end point.
+ */
+ private int computeY4(int height)
+ {
+ return DEFAULT_Y_OFFSET;
+ }
+
+ /**
+ * Set x-coordinate of the first control point.
+ *
+ * @param x1
+ * x-coordinate of the first control point
+ */
+ public void setX1(int x1)
+ {
+ this.x[0] = x1;
+ }
+
+ /**
+ * Set x-coordinate of the second control point.
+ *
+ * @param x2
+ * x-coordinate of the second control point
+ */
+ public void setX2(int x2)
+ {
+ this.x[1] = x2;
+ }
+
+ /**
+ * Set x-coordinate of the third control point.
+ *
+ * @param x3
+ * x-coordinate of the third control point
+ */
+ public void setX3(int x3)
+ {
+ this.x[2] = x3;
+ }
+
+ /**
+ * Set x-coordinate of the fourth control point.
+ *
+ * @param x4
+ * x-coordinate of the fourth control point
+ */
+ public void setX4(int x4)
+ {
+ this.x[3] = x4;
+ }
+
+ /**
+ * Set y-coordinate of the first control point.
+ *
+ * @param y1
+ * y-coordinate of the first control point
+ */
+ public void setY1(int y1)
+ {
+ this.y[0] = y1;
+ }
+
+ /**
+ * Set y-coordinate of the second control point.
+ *
+ * @param y2
+ * y-coordinate of the second control point
+ */
+ public void setY2(int y2)
+ {
+ this.y[1] = y2;
+ }
+
+ /**
+ * Set y-coordinate of the third control point.
+ *
+ * @param y3
+ * y-coordinate of the third control point
+ */
+ public void setY3(int y3)
+ {
+ this.y[2] = y3;
+ }
+
+ /**
+ * Set y-coordinate of the fourth control point.
+ *
+ * @param y4
+ * y-coordinate of the fourth control point
+ */
+ public void setY4(int y4)
+ {
+ this.y[3] = y4;
+ }
+
+ /**
+ * Return x-coordinate of the first control point.
+ *
+ * @return x-coordinate of the first control point.
+ */
+ public int getX1()
+ {
+ return this.x[0];
+ }
+
+ /**
+ * Return x-coordinate of the second control point.
+ *
+ * @return x-coordinate of the second control point.
+ */
+ public int getX2()
+ {
+ return this.x[1];
+ }
+
+ /**
+ * Return x-coordinate of the third control point.
+ *
+ * @return x-coordinate of the third control point.
+ */
+ public int getX3()
+ {
+ return this.x[2];
+ }
+
+ /**
+ * Return x-coordinate of the fourth control point.
+ *
+ * @return x-coordinate of the fourth control point.
+ */
+ public int getX4()
+ {
+ return this.x[3];
+ }
+
+ /**
+ * Return y-coordinate of the first control point.
+ *
+ * @return y-coordinate of the first control point.
+ */
+ public int getY1()
+ {
+ return this.y[0];
+ }
+
+ /**
+ * Return y-coordinate of the second control point.
+ *
+ * @return y-coordinate of the second control point.
+ */
+ public int getY2()
+ {
+ return this.y[1];
+ }
+
+ /**
+ * Return y-coordinate of the third control point.
+ *
+ * @return y-coordinate of the third control point.
+ */
+ public int getY3()
+ {
+ return this.y[2];
+ }
+
+ /**
+ * Return y-coordinate of the fourth control point.
+ *
+ * @return y-coordinate of the fourth control point.
+ */
+ public int getY4()
+ {
+ return this.y[3];
+ }
+
+ /**
+ * Return offset used to move curve away from the image border.
+ *
+ * @return the default y offset
+ */
+ public static int getDefaultYOffset()
+ {
+ return DEFAULT_Y_OFFSET;
+ }
+
+ /**
+ * Return x-coordinate of the n-th control point of cubic curve.
+ *
+ * @param index
+ * index of the control point in range 1..4
+ * @return x-coordinate of the n-th control point.
+ */
+ public double getNthX(int index)
+ {
+ // check index range
+ if (indexOutOfBounds(index))
+ {
+ throw new IndexOutOfBoundsException("invalid index " + index + " (should be 1..4)");
+ }
+ // return x-coordinate
+ return this.x[index - 1];
+ }
+
+ /**
+ * Return y-coordinate of the n-th control point of cubic curve.
+ *
+ * @param index
+ * index of the control point in range 1..4
+ * @return y-coordinate of the n-th control point.
+ */
+ public double getNthY(int index)
+ {
+ // check index range
+ if (indexOutOfBounds(index))
+ {
+ throw new IndexOutOfBoundsException("invalid index " + index + " (should be 1..4)");
+ }
+ // return y-coordinate
+ return this.y[index - 1];
+ }
+
+ /**
+ * Check if control point index is inside given range 1..4.
+ *
+ * @param index
+ * index of the control point
+ * @return true if index is inside defined range, false otherwise
+ */
+ private boolean indexOutOfBounds(int index)
+ {
+ return index < 1 || index > 4;
+ }
+
+}
diff -r 98d8ac4bd4cb -r 6fbdab4d7a3c src/org/gfxtest/testsuites/NormalCubicCurves.java
--- a/src/org/gfxtest/testsuites/NormalCubicCurves.java Thu Aug 04 12:01:15 2011 +0200
+++ b/src/org/gfxtest/testsuites/NormalCubicCurves.java Thu Aug 04 15:43:15 2011 +0200
@@ -51,8 +51,8 @@
/**
* This test renders various cubic curves using identity transformation matrix.
- * Cubic curves are constructed using CubicCurve2D class. Curves are drawn
- * using various colors and stroke width.
+ * Cubic curves are constructed using CubicCurve2D class. Curves are drawn using
+ * various colors and stroke width.
*
* @author Pavel Tisnovsky
*/
@@ -63,34 +63,54 @@
@Zoom(1)
public class NormalCubicCurves extends GfxTest
{
+
+ /**
+ * Stroke width used for drawing "thick" curves.
+ */
+ private static final int STROKE_WIDTH_THICK = 10;
+
+ /**
+ * Stroke width used for drawing extra "thick" curves.
+ */
+ private static final int STROKE_WIDTH_EXTRA_THICK = 30;
+
/**
* Default Y offset of curve end points.
*/
- private static final int DEFAULT_Y_OFFSET = 20;
+ private static final int DEFAULT_Y_OFFSET = 40;
/**
+ * Step between curves drawn by different colors onto the same image.
+ */
+ private static final int OFFSET_STEP = 20;
+
+ /**
* Draw cubic curve onto canvas specified by Graphics2D class.
*
+ * @param image
+ * image to which two dimensional shape is to be rendered
* @param graphics
* graphics canvas
- * @param width
- * canvas width
- * @param height
- * canvas height
* @param cubicCurve
* cubic curve to be drawn
* @param color
* curve color or null when Color.BLACK can be used.
+ * @param pointIndexes
+ * indexes of control point to use to draw the curve (default
+ * value should be {1,2,3,4})
* @return test result status - PASSED, FAILED or ERROR
*/
- private TestResult drawCubicCurve(Graphics2D graphics, int width, int height, CubicCurve2D cubicCurve, Color color)
+ private TestResult drawCubicCurve(TestImage image, Graphics2D graphics, CubicCurve2D cubicCurve, Color color, int[] pointIndexes)
{
+ // construct point set which consists of all four curve control points
+ CubicCurvePointSet pointSet = new CubicCurvePointSet(image);
+
// construct CubicCurve2D.Float with set coordinates
cubicCurve.setCurve(
- computeX1(width), computeY1(),
- computeX2(width), computeY2(height),
- computeX3(width), computeY3(height),
- computeX4(width), computeY4(height));
+ pointSet.getNthX(pointIndexes[0]), pointSet.getNthY(pointIndexes[0]),
+ pointSet.getNthX(pointIndexes[1]), pointSet.getNthY(pointIndexes[1]),
More information about the distro-pkg-dev
mailing list