/hg/gfx-test: Added more tests - rendering cubic Bezier curves - to
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Wed Aug 1 01:45:48 PDT 2012
changeset c1e86da11351 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=c1e86da11351
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Wed Aug 01 10:48:19 2012 +0200
Added more tests - rendering cubic Bezier curves - to
the test suite src/org/gfxtest/testsuites/PrintTestPaths.java.
diffstat:
ChangeLog | 5 +
src/org/gfxtest/testsuites/PrintTestPaths.java | 126 ++++++++++++++++++++++++-
2 files changed, 126 insertions(+), 5 deletions(-)
diffs (183 lines):
diff -r df77617740d9 -r c1e86da11351 ChangeLog
--- a/ChangeLog Mon Jul 30 12:10:45 2012 +0200
+++ b/ChangeLog Wed Aug 01 10:48:19 2012 +0200
@@ -1,3 +1,8 @@
+2012-08-01 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/org/gfxtest/testsuites/PrintTestPaths.java:
+ Added more tests - rendering cubic Bezier curves.
+
2012-07-30 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/gfxtest/callbacks/CommonCurveDrawCallbacks.java:
diff -r df77617740d9 -r c1e86da11351 src/org/gfxtest/testsuites/PrintTestPaths.java
--- a/src/org/gfxtest/testsuites/PrintTestPaths.java Mon Jul 30 12:10:45 2012 +0200
+++ b/src/org/gfxtest/testsuites/PrintTestPaths.java Wed Aug 01 10:48:19 2012 +0200
@@ -45,6 +45,7 @@
+import org.gfxtest.callbacks.CubicCurveDrawCallback;
import org.gfxtest.callbacks.DiagonalLineDrawCallbacks;
import org.gfxtest.callbacks.HorizontalLineDrawCallbacks;
import org.gfxtest.callbacks.VerticalLineDrawCallbacks;
@@ -77,10 +78,15 @@
{
/**
* Create Path2D which contains just one line.
- * @param x1 the first point's x coordinate.
- * @param y1 the first point's y coordinate.
- * @param x2 the second point's x coordinate.
- * @param y2 the second point's y coordinate.
+ *
+ * @param x1
+ * the first point's x coordinate.
+ * @param y1
+ * the first point's y coordinate.
+ * @param x2
+ * the second point's x coordinate.
+ * @param y2
+ * the second point's y coordinate.
* @return newly created path
*/
private static Path2D createLinePath(int x1, int y1, int x2, int y2)
@@ -92,6 +98,35 @@
}
/**
+ * Create Path2D which contains just 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 path
+ */
+ private static Path2D createCubicCurvePath(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
+ {
+ Path2D path = new Path2D.Float();
+ path.moveTo(x1, y1);
+ path.curveTo(x2, y2, x3, y3, x4, y4);
+ return path;
+ }
+
+ /**
* Method which renders set of horizontal lines using various colors and
* stroke styles. For each line, the callback function/method is called to
* perform all required setup. Lines are represented by a Path object.
@@ -159,7 +194,7 @@
final int width = image.getWidth();
final int height = image.getHeight();
- // horizontal coordinates of line endpoints
+ // vertical coordinates of line endpoints
final int y1 = BORDER;
final int y2 = height - BORDER;
@@ -250,6 +285,57 @@
}
/**
+ * 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 Path 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, CubicCurveDrawCallback cubicCurveCallback)
+ {
+ // setup rendering
+ cubicCurveCallback.setup(image, graphics);
+
+ // image width and height
+ final int width = image.getWidth();
+ final int height = image.getHeight();
+
+ // horizontal coordinates of line 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)
+ {
+ 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 path which contains just one line
+ Path2D path = createCubicCurvePath(x1, y1, x2, y2, x3, y3, x4, y4);
+ // render the line
+ graphics.draw(path);
+ }
+
+ // cleanup rendering
+ cubicCurveCallback.cleanup();
+ }
+
+ /**
* Test basic behavior of method Graphics.draw(Path). Horizontal lines are
* rendered with default width and default end caps. Color of all rendered
* lines are set to black. Lines are represented by a Path object.
@@ -338,6 +424,36 @@
}
/**
+ * Test basic behavior of method Graphics.draw(Path).
+ * 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 Path 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 CubicCurveDrawCallback()
+ {
+ /**
+ * 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