/hg/gfx-test: * src/org/gfxtest/framework/CubicCurvePointSet.java:

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Fri Aug 5 05:34:59 PDT 2011


changeset 504ee1c39140 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=504ee1c39140
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Fri Aug 05 14:36:35 2011 +0200

	* src/org/gfxtest/framework/CubicCurvePointSet.java: Added new
	methods for fetching points arrays.
	* src/org/gfxtest/framework/GfxTest.java: New method for drawing cross
	at end points and control points.
	* src/org/gfxtest/testsuites/NormalCubicCurves.java: Added new
	functionality - drawing crosses at control points.
	* src/org/gfxtest/testsuites/NormalQuadraticCurves.java: Added new
	functionality - drawing crosses at control points.
	* src/org/gfxtest/testsuites/NormalQuadraticCurvesAsPaths.java: Added
	new functionality - drawing crosses at control points. Added new
	test cases.


diffstat:

 ChangeLog                                                    |   13 +
 src/org/gfxtest/framework/CubicCurvePointSet.java            |   28 +-
 src/org/gfxtest/framework/GfxTest.java                       |   30 +-
 src/org/gfxtest/testsuites/NormalCubicCurves.java            |   53 +-
 src/org/gfxtest/testsuites/NormalQuadraticCurves.java        |  115 ++++-
 src/org/gfxtest/testsuites/NormalQuadraticCurvesAsPaths.java |  289 +++++++---
 6 files changed, 421 insertions(+), 107 deletions(-)

diffs (truncated from 817 to 500 lines):

diff -r 6fbdab4d7a3c -r 504ee1c39140 ChangeLog
--- a/ChangeLog	Thu Aug 04 15:43:15 2011 +0200
+++ b/ChangeLog	Fri Aug 05 14:36:35 2011 +0200
@@ -1,3 +1,16 @@
+2011-08-05  Pavel Tisnovsky  <ptisnovs at redhat.com>
+	* src/org/gfxtest/framework/CubicCurvePointSet.java:
+	Added new methods for fetching points arrays.
+	* src/org/gfxtest/framework/GfxTest.java:
+	New method for drawing cross at end points and control points.
+	* src/org/gfxtest/testsuites/NormalCubicCurves.java:
+	Added new functionality - drawing crosses at control points.
+	* src/org/gfxtest/testsuites/NormalQuadraticCurves.java:
+	Added new functionality - drawing crosses at control points.
+	* src/org/gfxtest/testsuites/NormalQuadraticCurvesAsPaths.java:
+	Added new functionality - drawing crosses at control points.
+	Added new test cases.
+
 2011-08-04  Pavel Tisnovsky  <ptisnovs at redhat.com>
 	* src/org/gfxtest/framework/CubicCurvePointSet.java: added
 	* src/org/gfxtest/testsuites/NormalCubicCurves.java:
diff -r 6fbdab4d7a3c -r 504ee1c39140 src/org/gfxtest/framework/CubicCurvePointSet.java
--- a/src/org/gfxtest/framework/CubicCurvePointSet.java	Thu Aug 04 15:43:15 2011 +0200
+++ b/src/org/gfxtest/framework/CubicCurvePointSet.java	Fri Aug 05 14:36:35 2011 +0200
@@ -365,7 +365,7 @@
      *            index of the control point in range 1..4
      * @return x-coordinate of the n-th control point.
      */
-    public double getNthX(int index)
+    public int getNthX(int index)
     {
         // check index range
         if (indexOutOfBounds(index))
@@ -383,7 +383,7 @@
      *            index of the control point in range 1..4
      * @return y-coordinate of the n-th control point.
      */
-    public double getNthY(int index)
+    public int getNthY(int index)
     {
         // check index range
         if (indexOutOfBounds(index))
@@ -393,6 +393,30 @@
         // return y-coordinate
         return this.y[index - 1];
     }
+    
+    /**
+     * Return an array containing x coordinates of all four cubic curve control
+     * points.
+     * 
+     * @return array containing x coordinates of all four cubic curve control
+     *         points.
+     */
+    public int[] getXPointArray()
+    {
+        return this.x;
+    }
+    
+    /**
+     * Return an array containing y coordinates of all four cubic curve control
+     * points.
+     * 
+     * @return array containing y coordinates of all four cubic curve control
+     *         points.
+     */
+    public int[] getYPointArray()
+    {
+        return this.y;
+    }
 
     /**
      * Check if control point index is inside given range 1..4.
diff -r 6fbdab4d7a3c -r 504ee1c39140 src/org/gfxtest/framework/GfxTest.java
--- a/src/org/gfxtest/framework/GfxTest.java	Thu Aug 04 15:43:15 2011 +0200
+++ b/src/org/gfxtest/framework/GfxTest.java	Fri Aug 05 14:36:35 2011 +0200
@@ -505,11 +505,33 @@
     }
 
     /**
+     * Draw cross into graphics canvas, to mark shape's end points, curves's
+     * control points etc. Size of cross is stored in constant CROSS_SIZE.
      * 
-     * @param graphics graphics context for the image created by test case
-     * @param x x-coordinate of the cross center
-     * @param y y-coordinate of the cross center
-     * @param size size of cross (measured in pixels)
+     * @param graphics
+     *            graphics context for the image created by test case
+     * @param x
+     *            x-coordinate of the cross center
+     * @param y
+     *            y-coordinate of the cross center
+     */
+    protected void drawCross(Graphics2D graphics, int x, int y)
+    {
+        drawCross(graphics, x, y, CROSS_SIZE);
+    }
+
+    /**
+     * Draw cross into graphics canvas, to mark shape's end points, curves's
+     * control points etc.
+     * 
+     * @param graphics
+     *            graphics context for the image created by test case
+     * @param x
+     *            x-coordinate of the cross center
+     * @param y
+     *            y-coordinate of the cross center
+     * @param size
+     *            size of cross (measured in pixels)
      */
     protected void drawCross(Graphics2D graphics, int x, int y, int size)
     {
diff -r 6fbdab4d7a3c -r 504ee1c39140 src/org/gfxtest/testsuites/NormalCubicCurves.java
--- a/src/org/gfxtest/testsuites/NormalCubicCurves.java	Thu Aug 04 15:43:15 2011 +0200
+++ b/src/org/gfxtest/testsuites/NormalCubicCurves.java	Fri Aug 05 14:36:35 2011 +0200
@@ -83,7 +83,31 @@
      * Step between curves drawn by different colors onto the same image.
      */
     private static final int OFFSET_STEP = 20;
-    
+
+    /**
+     * Draw crosses at the both end points and both control points of cubic
+     * curve.
+     * 
+     * @param graphics
+     *            graphics canvas
+     * @param x
+     *            array containing x coordinates of all four control points of
+     *            cubic curve
+     * @param y
+     *            array containing y coordinates of all four control points of
+     *            cubic curve
+     * @param pointIndexes 
+     *            indexes of control point to use to draw the curve (default
+     *            value should be {1,2,3,4})
+     */
+    private void drawCrossesAtControlPoints(Graphics2D graphics, int[] x, int[] y, int[] pointIndexes)
+    {
+        for (int i = 0; i < 4; i++)
+        {
+            this.drawCross(graphics, x[pointIndexes[i]-1], y[pointIndexes[i]-1]);
+        }
+    }
+
     /**
      * Draw cubic curve onto canvas specified by Graphics2D class.
      * 
@@ -105,12 +129,15 @@
         // construct point set which consists of all four curve control points
         CubicCurvePointSet pointSet = new CubicCurvePointSet(image);
 
+        // fill in arrays containing coordinates for all cubic curve control points
+        int[] x = pointSet.getXPointArray();
+        int[] y = pointSet.getYPointArray();
+
         // construct CubicCurve2D.Float with set coordinates
-        cubicCurve.setCurve(
-                        pointSet.getNthX(pointIndexes[0]), pointSet.getNthY(pointIndexes[0]),
-                        pointSet.getNthX(pointIndexes[1]), pointSet.getNthY(pointIndexes[1]),
-                        pointSet.getNthX(pointIndexes[2]), pointSet.getNthY(pointIndexes[2]),
-                        pointSet.getNthX(pointIndexes[3]), pointSet.getNthY(pointIndexes[3]));
+        cubicCurve.setCurve(x[pointIndexes[0]-1], y[pointIndexes[0]-1],
+                            x[pointIndexes[1]-1], y[pointIndexes[1]-1],
+                            x[pointIndexes[2]-1], y[pointIndexes[2]-1],
+                            x[pointIndexes[3]-1], y[pointIndexes[3]-1]);
 
         // set the specified color
         graphics.setColor(color == null ? Color.BLACK : color);
@@ -118,6 +145,10 @@
         // draw CubicCurve2D
         graphics.draw(cubicCurve);
 
+        // Draw crosses at the both end points and both control points of cubic
+        // curve.
+        drawCrossesAtControlPoints(graphics, x, y, pointIndexes);
+
         // test return value
         return TestResult.PASSED;
     }
@@ -208,12 +239,12 @@
             // create new CubicCurve2D.Float
             CubicCurve2D cubicCurve = new CubicCurve2D.Float();
 
+            // fill in arrays containing coordinates for all cubic curve control points
+            int[] x = pointSet.getXPointArray();
+            int[] y = pointSet.getYPointArray();
+
             // construct CubicCurve2D.Float with set coordinates
-            cubicCurve.setCurve(
-                            pointSet.getX1(), pointSet.getY1() + offset,
-                            pointSet.getX2(), pointSet.getY2() + offset,
-                            pointSet.getX3(), pointSet.getY3() + offset,
-                            pointSet.getX4(), pointSet.getY4() + offset);
+            cubicCurve.setCurve(x[0], y[0] + offset, x[1], y[1] + offset, x[2], y[2] + offset, x[3], y[3] + offset);
 
             // set the specified color
             graphics.setColor(color);
diff -r 6fbdab4d7a3c -r 504ee1c39140 src/org/gfxtest/testsuites/NormalQuadraticCurves.java
--- a/src/org/gfxtest/testsuites/NormalQuadraticCurves.java	Thu Aug 04 15:43:15 2011 +0200
+++ b/src/org/gfxtest/testsuites/NormalQuadraticCurves.java	Fri Aug 05 14:36:35 2011 +0200
@@ -83,7 +83,32 @@
     /**
      * Step between curves drawn by different colors onto the same image.
      */
-    private static final int OFFSET_STEP = 10;
+    private static final int OFFSET_STEP = 20;
+
+    /**
+     * Draw crosses at the both end points and control point of quadratic curve.
+     * 
+     * @param graphics
+     *            graphics canvas
+     * @param x1
+     *            first quadratic curve x coordinate
+     * @param y1
+     *            first quadratic curve y coordinate
+     * @param x2
+     *            second quadratic curve x coordinate
+     * @param y2
+     *            second quadratic curve y coordinate
+     * @param x3
+     *            third quadratic curve x coordinate
+     * @param y3
+     *            third quadratic curve x coordinate
+     */
+    private void drawCrossesAtControlPoints(Graphics2D graphics, int x1, int y1, int x2, int y2, int x3, int y3)
+    {
+        this.drawCross(graphics, x1, y1);
+        this.drawCross(graphics, x2, y2);
+        this.drawCross(graphics, x3, y3);
+    }
 
     /**
      * Draw quadratic curve onto canvas specified by Graphics2D class.
@@ -104,8 +129,16 @@
         int width =  image.getWidth();
         int height =  image.getHeight();
 
+        // get curve coordinates
+        int x1 = computeX1(width);
+        int y1 = computeY1();
+        int x2 = computeX2(width);
+        int y2 = computeY2(height);
+        int x3 = computeX3(width);
+        int y3 = computeY3();
+
         // construct QuadCurve2D.Float with set coordinates
-        quadCurve.setCurve(computeX1(width), computeY1(), computeX2(width), computeY2(height), computeX3(width), computeY3());
+        quadCurve.setCurve(x1, y1, x2, y2, x3, y3);
 
         // set the specified color
         graphics.setColor(color == null ? Color.BLACK : color);
@@ -113,6 +146,9 @@
         // draw QuadCurve2D
         graphics.draw(quadCurve);
 
+        // draw crosses at all control points
+        drawCrossesAtControlPoints(graphics, x1, y1, x2, y2, x3, y3);
+
         // test return value
         return TestResult.PASSED;
     }
@@ -534,12 +570,23 @@
         // create new QuadCurve2D.Float
         QuadCurve2D quadCurve = new QuadCurve2D.Float();
 
+        // get curve coordinates
+        int x1 = computeX1(width);
+        int y1 = centerY;
+        int x2 = x1;
+        int y2 = y1;
+        int x3 = computeX3(width);
+        int y3 = centerY;
+
         // construct QuadCurve2D.Float with set coordinates
-        quadCurve.setCurve(computeX1(width), centerY, computeX1(width), centerY, computeX3(width), centerY);
+        quadCurve.setCurve(x1, y1, x2, y2, x3, y3);
 
         // draw QuadCurve2D
         graphics.draw(quadCurve);
 
+        // draw crosses at all control points
+        drawCrossesAtControlPoints(graphics, x1, y1, x2, y2, x3, y3);
+
         // test return value
         return TestResult.PASSED;
     }
@@ -569,12 +616,23 @@
         // create new QuadCurve2D.Float
         QuadCurve2D quadCurve = new QuadCurve2D.Float();
 
+        // get curve coordinates
+        int x1 = computeX1(width);
+        int y1 = centerY;
+        int x2 = computeX3(width);
+        int y2 = y1;
+        int x3 = x2;
+        int y3 = y1;
+
         // construct QuadCurve2D.Float with set coordinates
-        quadCurve.setCurve(computeX1(width), centerY, computeX3(width), centerY, computeX3(width), centerY);
+        quadCurve.setCurve(x1, y1, x2, y2, x3, y3);
 
         // draw QuadCurve2D
         graphics.draw(quadCurve);
 
+        // draw crosses at all control points
+        drawCrossesAtControlPoints(graphics, x1, y1, x2, y2, x3, y3);
+
         // test return value
         return TestResult.PASSED;
     }
@@ -603,12 +661,59 @@
         // create new QuadCurve2D.Float
         QuadCurve2D quadCurve = new QuadCurve2D.Float();
 
+        // get curve coordinates
+        int x1 = computeX1(width);
+        int y1 = centerY;
+        int x2 = computeX3(width);
+        int y2 = y1;
+        int x3 = x1;
+        int y3 = y1;
+
         // construct QuadCurve2D.Float with set coordinates
-        quadCurve.setCurve(computeX1(width), centerY, computeX3(width), centerY, computeX1(width), centerY);
+        quadCurve.setCurve(x1, y1, x2, y2, x3, y3);
 
         // draw QuadCurve2D
         graphics.draw(quadCurve);
 
+        // draw crosses at all control points
+        drawCrossesAtControlPoints(graphics, x1, y1, x2, y2, x3, y3);
+
+        // test return value
+        return TestResult.PASSED;
+    }
+
+    /**
+     * Test special test case - quadratic curve with all identical points.
+     *
+     * @param image
+     *            image to which two dimensional shape is to be rendered
+     * @param graphics
+     *            graphics context for image
+     * @return test result status - PASSED, FAILED or ERROR
+     */
+    public TestResult testIdenticalPoints123(TestImage image, Graphics2D graphics)
+    {
+        int centerX = image.getCenterX();
+        int centerY = image.getCenterY();
+
+        // set 10 pixels wide stroke
+        graphics.setStroke(new BasicStroke(STROKE_WIDTH_THICK, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL));
+
+        // set curve color
+        graphics.setColor(Color.BLACK);
+
+        // create new QuadCurve2D.Float
+        QuadCurve2D quadCurve = new QuadCurve2D.Float();
+
+        // construct QuadCurve2D.Float with set coordinates
+        quadCurve.setCurve(centerX, centerY, centerX, centerY, centerX, centerY);
+
+        // draw QuadCurve2D
+        graphics.draw(quadCurve);
+
+        // draw crosses at all control points
+        drawCrossesAtControlPoints(graphics, centerX, centerY, centerX, centerY, centerX, centerY);
+
         // test return value
         return TestResult.PASSED;
     }
diff -r 6fbdab4d7a3c -r 504ee1c39140 src/org/gfxtest/testsuites/NormalQuadraticCurvesAsPaths.java
--- a/src/org/gfxtest/testsuites/NormalQuadraticCurvesAsPaths.java	Thu Aug 04 15:43:15 2011 +0200
+++ b/src/org/gfxtest/testsuites/NormalQuadraticCurvesAsPaths.java	Fri Aug 05 14:36:35 2011 +0200
@@ -64,10 +64,72 @@
 public class NormalQuadraticCurvesAsPaths 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 crosses at the both end points and control point of quadratic curve.
+     * 
+     * @param graphics
+     *            graphics canvas
+     * @param x1
+     *            first quadratic curve x coordinate
+     * @param y1
+     *            first quadratic curve y coordinate
+     * @param x2
+     *            second quadratic curve x coordinate
+     * @param y2
+     *            second quadratic curve y coordinate
+     * @param x3
+     *            third quadratic curve x coordinate
+     * @param y3
+     *            third quadratic curve x coordinate
+     */
+    private void drawCrossesAtControlPoints(Graphics2D graphics, int x1, int y1, int x2, int y2, int x3, int y3)
+    {
+        this.drawCross(graphics, x1, y1);
+        this.drawCross(graphics, x2, y2);
+        this.drawCross(graphics, x3, y3);
+    }
+
+    /**
+     * Draw crosses at the both end points and control point of quadratic curve.
+     * 
+     * @param graphics
+     *            graphics canvas
+     * @param width
+     *            test image width
+     * @param height
+     *            test image height
+     */
+    private void drawCrossesAtControlPoints(Graphics2D graphics, int width, int height)
+    {
+        // get curve coordinates
+        int x1 = computeX1(width);
+        int y1 = computeY1();
+        int x2 = computeX2(width);
+        int y2 = computeY2(height);
+        int x3 = computeX3(width);
+        int y3 = computeY3();
+        drawCrossesAtControlPoints(graphics, x1, y1, x2, y2, x3, y3);
+    }
+
     /**
      * Draw quadratic curve contained in the path onto canvas specified by
      * Graphics2D class.
@@ -92,6 +154,9 @@
         // draw QuadCurve2D
         graphics.draw(path);
 
+        // draw crosses at control points
+        drawCrossesAtControlPoints(graphics, width, height);
+
         // test return value
         return TestResult.PASSED;
     }
@@ -114,7 +179,7 @@
     {
         return drawPath(graphics, w, h, path, Color.BLACK);
     }
-    
+
     /**
      * Create new path using Path2D.Float() which contains just one quadratic
      * curve.
@@ -132,7 +197,7 @@
         path.quadTo(computeX2(width), computeY2(height), computeX3(width), computeY3());
         return path;
     }
-    
+
     /**
      * Create new path using Path2D.Double() which contains just one quadratic
      * curve.
@@ -150,7 +215,29 @@
         path.quadTo(computeX2(width), computeY2(height), computeX3(width), computeY3());
         return path;
     }
-    
+
+    /**
+     * Create quadratic cube and draw it.
+     * 
+     * @param image
+     *            image to which two dimensional shape is to be rendered
+     * @param graphics
+     *            graphics context for image
+     * @return test result status - PASSED, FAILED or ERROR
+     */
+    private TestResult createAndDrawPath(TestImage image, Graphics2D graphics)
+    {
+        // calculate image dimensions
+        int width =  image.getWidth();



More information about the distro-pkg-dev mailing list