2 * Copyright © 2005 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Red Hat, Inc. makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: Carl D. Worth <cworth@cworth.org>
28 * 2005-06-01 Carl Worth <cworth@cworth.org>
30 * There's a long-standing bug in that self-intersecting paths give
31 * an incorrect result when stroked. The problem is that the
32 * trapezoids are generated incrementally along the stroke and as
33 * such, are not disjoint. The errant intersections of these
34 * trapezoids then leads to overfilled pixels.
36 * The test belows first creates and fills a path. Then it creates a
37 * second path which has a stroked boundary identical to the first
38 * filled path. But the results of the two operations are
39 * different. The most obvious difference is in the central region
40 * where the entire path intersects itself. But notice that every
41 * time the path turns there are also errors on the inside of the
42 * turn, (since the subsequent trapezoids along the path intersect).
45 #include "cairo-test.h"
47 static cairo_test_status_t
48 draw (cairo_t *cr, int width, int height)
50 cairo_set_source_rgb (cr, 1, 1, 1);
53 cairo_translate (cr, 1.0, 1.0);
55 cairo_set_source_rgb (cr, 1, 0, 0); /* red */
57 /* First draw the desired shape with a fill */
58 cairo_rectangle (cr, 0.5, 0.5, 4.0, 4.0);
59 cairo_rectangle (cr, 3.5, 3.5, 4.0, 4.0);
60 cairo_rectangle (cr, 3.5, 1.5, -2.0, 2.0);
61 cairo_rectangle (cr, 6.5, 4.5, -2.0, 2.0);
65 /* Then try the same thing with a stroke */
66 cairo_translate (cr, 0, 10);
67 cairo_move_to (cr, 1.0, 1.0);
68 cairo_rel_line_to (cr, 3.0, 0.0);
69 cairo_rel_line_to (cr, 0.0, 6.0);
70 cairo_rel_line_to (cr, 3.0, 0.0);
71 cairo_rel_line_to (cr, 0.0, -3.0);
72 cairo_rel_line_to (cr, -6.0, 0.0);
73 cairo_close_path (cr);
75 cairo_set_line_width (cr, 1.0);
78 return CAIRO_TEST_SUCCESS;
81 CAIRO_TEST (self_intersecting,
82 "Test strokes of self-intersecting paths"
83 "\nSelf-intersecting strokes are wrong due to incremental trapezoidization.",
84 "stroke, trap", /* keywords */
85 NULL, /* requirements */