[cairo-commit] 5 commits - src/cairo-path-fixed.c src/cairo-spline.c test/curve-to-as-line-to.c test/curve-to-as-line-to.ps.xfail.png test/curve-to-as-line-to.ref.png test/Makefile.sources

Carl Worth cworth at kemper.freedesktop.org
Mon Jul 27 15:59:36 PDT 2009


 src/cairo-path-fixed.c                |   12 ----
 src/cairo-spline.c                    |    9 ---
 test/Makefile.sources                 |    1 
 test/curve-to-as-line-to.c            |   95 ++++++++++++++++++++++++++++++++++
 test/curve-to-as-line-to.ps.xfail.png |binary
 test/curve-to-as-line-to.ref.png      |binary
 6 files changed, 96 insertions(+), 21 deletions(-)

New commits:
commit d31de83e01468eaf9e1a906aef536b63e77cb752
Author: Carl Worth <cworth at cworth.org>
Date:   Mon Jul 27 15:58:27 2009 -0700

    Mark curve-to-as-line-to as XFAIL for PS backend.
    
    Looks like ghostscript has a similar buggy optimization like we
    just fixed in cairo. I'm just waiting on a new bugzilla account
    from bugs.ghostscript.com after which I plan to report the bug
    there.

diff --git a/test/curve-to-as-line-to.ps.xfail.png b/test/curve-to-as-line-to.ps.xfail.png
new file mode 100644
index 0000000..3f31058
Binary files /dev/null and b/test/curve-to-as-line-to.ps.xfail.png differ
commit 45919a4f0c94a247b1c6941dbc4a57f6c9399396
Author: Carl Worth <cworth at cworth.org>
Date:   Mon Jul 27 15:45:55 2009 -0700

    Revert "[path] Convert straight curve-to to line-to"
    
    This reverts commit c72ca2f2296b5fbc5859059b98221e5ffe087dae.
    
    This commit was broken as verified by the curve-to-as-line-to test
    case.

diff --git a/src/cairo-path-fixed.c b/src/cairo-path-fixed.c
index 3befe42..9819353 100644
--- a/src/cairo-path-fixed.c
+++ b/src/cairo-path-fixed.c
@@ -488,7 +488,6 @@ _cairo_path_fixed_curve_to (cairo_path_fixed_t	*path,
 {
     cairo_status_t status;
     cairo_point_t point[3];
-    cairo_slope_t slope, tangent;
 
     /* make sure subpaths are started properly */
     if (! path->has_current_point) {
@@ -503,17 +502,6 @@ _cairo_path_fixed_curve_to (cairo_path_fixed_t	*path,
     point[0].x = x0; point[0].y = y0;
     point[1].x = x1; point[1].y = y1;
     point[2].x = x2; point[2].y = y2;
-
-    _cairo_slope_init (&slope, &path->current_point, &point[2]);
-    _cairo_slope_init (&tangent, &path->current_point, &point[0]);
-    if (_cairo_slope_compare (&slope, &tangent) == 0) {
-	_cairo_slope_init (&tangent, &point[1], &point[2]);
-	if (_cairo_slope_compare (&slope, &tangent) == 0) {
-	    /* just a straight line... */
-	    return _cairo_path_fixed_line_to (path, x2, y2);
-	}
-    }
-
     status = _cairo_path_fixed_add (path, CAIRO_PATH_OP_CURVE_TO, point, 3);
     if (unlikely (status))
 	return status;
commit 5bed405b278a6b934369873f55117d497f69bc3a
Author: Carl Worth <cworth at cworth.org>
Date:   Mon Jul 27 15:45:15 2009 -0700

    Revert "[spline] Treat a straight spline as degenerate."
    
    This reverts commit f3d265559a2f97152ce8f307ea3ce83463083088.
    
    This commit was broken as verified by the curve-to-as-line-to test
    case.

diff --git a/src/cairo-spline.c b/src/cairo-spline.c
index 8bebcb2..45eedbd 100644
--- a/src/cairo-spline.c
+++ b/src/cairo-spline.c
@@ -43,8 +43,6 @@ _cairo_spline_init (cairo_spline_t *spline,
 		    const cairo_point_t *a, const cairo_point_t *b,
 		    const cairo_point_t *c, const cairo_point_t *d)
 {
-    cairo_slope_t slope;
-
     spline->add_point_func = add_point_func;
     spline->closure = closure;
 
@@ -69,13 +67,6 @@ _cairo_spline_init (cairo_spline_t *spline,
     else
 	_cairo_slope_init (&spline->final_slope, &spline->knots.a, &spline->knots.d);
 
-    _cairo_slope_init (&slope, &spline->knots.a, &spline->knots.d);
-    if (_cairo_slope_compare (&slope, &spline->initial_slope) == 0 &&
-	_cairo_slope_compare (&slope, &spline->final_slope) == 0)
-    {
-	return FALSE; /* just a straight line... */
-    }
-
     return TRUE;
 }
 
commit 01acad1659caf766c57849f85dc3536fe2167608
Merge: 3cc9a60... cf15aed...
Author: Carl Worth <cworth at cworth.org>
Date:   Mon Jul 27 15:26:19 2009 -0700

    Merge branch 'master' of git.cairographics.org:/git/cairo

commit 3cc9a6050d9704976d8efe373b913e5309bde6d2
Author: Carl Worth <cworth at cworth.org>
Date:   Mon Jul 27 15:24:55 2009 -0700

    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.

diff --git a/test/Makefile.sources b/test/Makefile.sources
index 573ca84..f8c63cd 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 0000000..07eb005
--- /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 at 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 0000000..15589db
Binary files /dev/null and b/test/curve-to-as-line-to.ref.png differ


More information about the cairo-commit mailing list