[cairo-commit] test/caps-tails-curve.c test/caps-tails-curve.ref.png test/drunkard-tails.c test/drunkard-tails.ref.png test/Makefile.refs test/Makefile.sources

Chris Wilson ickle at kemper.freedesktop.org
Fri Aug 5 09:28:29 PDT 2011


 test/Makefile.refs            |    2 
 test/Makefile.sources         |    2 
 test/caps-tails-curve.c       |  127 +++++++++++++++++++++++++++++++++++++++
 test/caps-tails-curve.ref.png |binary
 test/drunkard-tails.c         |  135 ++++++++++++++++++++++++++++++++++++++++++
 test/drunkard-tails.ref.png   |binary
 6 files changed, 266 insertions(+)

New commits:
commit 3424e91ec767c8a8f1c4adb3917759e6c59d409a
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Aug 5 17:04:08 2011 +0100

    test: Add a couple of tests to exercise stroking of short tail segments
    
    Are the reference images correct? Discuss.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/test/Makefile.refs b/test/Makefile.refs
index 3bc41b1..6be80eb 100644
--- a/test/Makefile.refs
+++ b/test/Makefile.refs
@@ -76,6 +76,7 @@ REFERENCE_IMAGES = \
 	caps-sub-paths.image16.ref.png \
 	caps-sub-paths.ps.ref.png \
 	caps-sub-paths.ref.png \
+	caps-tails-curve.ref.png \
 	caps.image16.ref.png \
 	caps.ps.ref.png \
 	caps.ref.png \
@@ -366,6 +367,7 @@ REFERENCE_IMAGES = \
 	device-offset-scale.svg.xfail.png \
 	device-offset.ref.png \
 	device-offset.rgb24.ref.png \
+	drunkard-tails.ref.png \
 	extend-pad-border.image16.ref.png \
 	extend-pad-border.ps.ref.png \
 	extend-pad-border.quartz.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 4781e01..e8e2b4f 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -23,6 +23,7 @@ test_sources = \
 	caps-joins.c					\
 	caps-joins-alpha.c				\
 	caps-joins-curve.c				\
+	caps-tails-curve.c				\
 	caps-sub-paths.c				\
 	clear.c						\
 	clear-source.c					\
@@ -86,6 +87,7 @@ test_sources = \
 	degenerate-pen.c				\
 	degenerate-radial-gradient.c			\
 	degenerate-rel-curve-to.c			\
+	drunkard-tails.c				\
 	device-offset.c					\
 	device-offset-fractional.c			\
 	device-offset-positive.c			\
diff --git a/test/caps-tails-curve.c b/test/caps-tails-curve.c
new file mode 100644
index 0000000..0dc8b31
--- /dev/null
+++ b/test/caps-tails-curve.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+#define LINE_WIDTH	30.
+#define SIZE		(2 * LINE_WIDTH)
+#define PAD		(2 * LINE_WIDTH)
+
+static void
+make_path (cairo_t *cr, double theta)
+{
+    double line_width = cairo_get_line_width (cr) / 4;
+
+    cairo_move_to (cr, 0, 0);
+    cairo_rel_curve_to (cr,
+			SIZE/3, -SIZE/4,
+			SIZE/3, -SIZE/4,
+			SIZE, 0);
+
+    cairo_rel_line_to (cr,
+		       cos (theta) * line_width,
+		       sin (theta) * line_width);
+}
+
+static void
+draw_joins (cairo_t *cr, double theta)
+{
+    make_path (cr, theta);
+    cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
+    cairo_stroke (cr);
+
+    cairo_translate (cr, SIZE + PAD, 0.);
+
+    make_path (cr, theta);
+    cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+    cairo_stroke (cr);
+
+    cairo_translate (cr, SIZE + PAD, 0.);
+
+    make_path (cr, theta);
+    cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
+    cairo_stroke (cr);
+
+    cairo_translate (cr, SIZE + PAD, 0.);
+}
+
+static void
+draw_caps_joins (cairo_t *cr, double theta)
+{
+    cairo_translate (cr, PAD, 0);
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
+    draw_joins (cr, theta);
+
+    cairo_translate (cr, PAD, 0);
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+    draw_joins (cr, theta);
+
+    cairo_translate (cr, PAD, 0);
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+    draw_joins (cr, theta);
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    const double theta[] = {
+	-M_PI/2, -M_PI/4, 0, M_PI/8, M_PI/3, M_PI
+    };
+    unsigned int t;
+
+    /* We draw in the default black, so paint white first. */
+    cairo_save (cr);
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+    cairo_paint (cr);
+    cairo_restore (cr);
+
+    cairo_set_line_width (cr, LINE_WIDTH);
+
+    for (t = 0; t < sizeof(theta)/sizeof (theta[0]); t++) {
+	cairo_save (cr);
+	cairo_translate (cr, 0, t * (SIZE + PAD) + PAD);
+	draw_caps_joins (cr, theta[t]);
+	cairo_restore (cr);
+
+	cairo_save (cr);
+	/* and reflect to generate the opposite vertex ordering */
+	cairo_translate (cr, 0, height - t * (SIZE + PAD) - PAD);
+	cairo_scale (cr, 1, -1);
+	draw_caps_joins (cr, theta[t]);
+	cairo_restore (cr);
+    }
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (caps_tails_curve,
+	    "Test caps and joins on short tail segments",
+	    "stroke cap join", /* keywords */
+	    NULL, /* requirements */
+	    9 * (PAD + SIZE) + 4*PAD,
+	    12 * (PAD + SIZE) + PAD,
+	    NULL, draw)
+
diff --git a/test/caps-tails-curve.ref.png b/test/caps-tails-curve.ref.png
new file mode 100644
index 0000000..c521aa8
Binary files /dev/null and b/test/caps-tails-curve.ref.png differ
diff --git a/test/drunkard-tails.c b/test/drunkard-tails.c
new file mode 100644
index 0000000..3d3e09a
--- /dev/null
+++ b/test/drunkard-tails.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+#define LINE_WIDTH	10.
+#define SIZE		(5 * LINE_WIDTH)
+#define PAD		(3 * LINE_WIDTH)
+
+static uint32_t state;
+
+static double
+uniform_random (double minval, double maxval)
+{
+    static uint32_t const poly = 0x9a795537U;
+    uint32_t n = 32;
+    while (n-->0)
+	state = 2*state < state ? (2*state ^ poly) : 2*state;
+    return minval + state * (maxval - minval) / 4294967296.0;
+}
+
+static void
+make_path (cairo_t *cr)
+{
+    int i;
+
+    state = 0xdeadbeef;
+
+    cairo_move_to (cr, SIZE/2, SIZE/2);
+    for (i = 0; i < 200; i++) {
+	double theta = uniform_random (-M_PI, M_PI);
+	cairo_rel_line_to (cr,
+			   cos (theta) * LINE_WIDTH / 4,
+			   sin (theta) * LINE_WIDTH / 4);
+    }
+}
+
+static void
+draw_caps_joins (cairo_t *cr)
+{
+    cairo_save (cr);
+
+    cairo_translate (cr, PAD, PAD);
+
+    cairo_reset_clip (cr);
+    cairo_rectangle (cr, 0, 0, SIZE, SIZE);
+    cairo_clip (cr);
+
+    make_path (cr);
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
+    cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
+    cairo_stroke (cr);
+
+    cairo_translate (cr, SIZE + PAD, 0.);
+
+    cairo_reset_clip (cr);
+    cairo_rectangle (cr, 0, 0, SIZE, SIZE);
+    cairo_clip (cr);
+
+    make_path (cr);
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+    cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+    cairo_stroke (cr);
+
+    cairo_translate (cr, SIZE + PAD, 0.);
+
+    cairo_reset_clip (cr);
+    cairo_rectangle (cr, 0, 0, SIZE, SIZE);
+    cairo_clip (cr);
+
+    make_path (cr);
+    cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+    cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
+    cairo_stroke (cr);
+
+    cairo_restore (cr);
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    /* We draw in the default black, so paint white first. */
+    cairo_save (cr);
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+    cairo_paint (cr);
+    cairo_restore (cr);
+
+    cairo_set_line_width (cr, LINE_WIDTH);
+
+    draw_caps_joins (cr);
+
+    cairo_save (cr);
+    /* and reflect to generate the opposite vertex ordering */
+    cairo_translate (cr, 0, height);
+    cairo_scale (cr, 1, -1);
+
+    draw_caps_joins (cr);
+    cairo_restore (cr);
+
+    cairo_translate (cr, 0, SIZE + PAD);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (drunkard_tails,
+	    "Test caps and joins on short tail segments",
+	    "stroke cap join", /* keywords */
+	    NULL, /* requirements */
+	    3 * (PAD + SIZE) + PAD,
+	    2 * (PAD + SIZE) + PAD,
+	    NULL, draw)
+
diff --git a/test/drunkard-tails.ref.png b/test/drunkard-tails.ref.png
new file mode 100644
index 0000000..166320e
Binary files /dev/null and b/test/drunkard-tails.ref.png differ


More information about the cairo-commit mailing list