summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2009-07-27 15:24:55 -0700
committerCarl Worth <cworth@cworth.org>2009-07-27 15:24:55 -0700
commit3cc9a6050d9704976d8efe373b913e5309bde6d2 (patch)
tree2ad957d7327ff5160c436f7aa6ea27ccb2548a97 /test
parent9d7fd626c39c37368ea05f91a358899e5b5b898c (diff)
Add new test: curve-to-as-line-to
This test anticipates a future optimization, (already pushed upstream but not pulled yet), with a buggy implementation of replacing curve_to with line_to.
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.sources1
-rw-r--r--test/curve-to-as-line-to.c95
-rw-r--r--test/curve-to-as-line-to.ref.pngbin0 -> 95 bytes
3 files changed, 96 insertions, 0 deletions
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 573ca848a..f8c63cd0a 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -35,6 +35,7 @@ test_sources = \
create-from-png.c \
create-from-png-stream.c \
culled-glyphs.c \
+ curve-to-as-line-to.c \
dash-caps-joins.c \
dash-curve.c \
dash-no-dash.c \
diff --git a/test/curve-to-as-line-to.c b/test/curve-to-as-line-to.c
new file mode 100644
index 000000000..07eb005f5
--- /dev/null
+++ b/test/curve-to-as-line-to.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright © 2005 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth@cworth.org>
+ */
+
+#include "cairo-test.h"
+
+#define SIZE 30
+
+/* At one point, an optimization was proposed for cairo in which a
+ * curve_to would be optimized as a line_to. The initial (buggy)
+ * implementation verified that the slopes of several segments of the
+ * spline's control polygon were identical, but left open the
+ * possibility of an anti-parallel slope for one segment.
+ *
+ * For example, given a spline with collinear control points (A,B,C,D)
+ * positioned as follows:
+ *
+ * C--A--B--D
+ *
+ * The code verified identical slopes for AB, CD, and AD. The missing
+ * check for the BC segment allowed it to be anti-parallel to the
+ * others as above, and hence invalid to replace this spline with the
+ * AD line segment.
+ */
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
+ cairo_paint (cr);
+
+ cairo_set_line_width (cr, 1.0);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
+
+ cairo_translate (cr, 0, 1.0);
+
+ /* The CABD spline as described above. We ensure that the spline
+ * folds over on itself outside the bounds of the image to avoid
+ * the reference image having the curved portion of that fold,
+ * (which would just be harder to match in all the backends than
+ * we really want). */
+ cairo_move_to (cr,
+ 10.5, 0.5);
+ cairo_curve_to (cr,
+ 11.5, 0.5,
+ -25.0, 0.5,
+ 31.0, 0.5);
+
+ cairo_stroke (cr);
+
+ cairo_translate (cr, 0, 2.0);
+
+ /* A reflected version: DBAC */
+ cairo_move_to (cr,
+ 19.5, 0.5);
+
+ cairo_curve_to (cr,
+ 18.5, 0.5,
+ 55.0, 0.5,
+ -1.0, 0.5);
+
+ cairo_stroke (cr);
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (curve_to_as_line_to,
+ "Test optimization treating curve_to as line_to",
+ "path", /* keywords */
+ NULL, /* requirements */
+ 30,
+ 5,
+ NULL, draw)
diff --git a/test/curve-to-as-line-to.ref.png b/test/curve-to-as-line-to.ref.png
new file mode 100644
index 000000000..15589db2e
--- /dev/null
+++ b/test/curve-to-as-line-to.ref.png
Binary files differ