1
/*
2
 * Copyright © 2005 Red Hat, Inc.
3
 *
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.
14
 *
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.
22
 *
23
 * Author: Carl D. Worth <cworth@cworth.org>
24
 */
25

            
26
/* Bug history
27
 *
28
 * 2005-06-01  Carl Worth  <cworth@cworth.org>
29
 *
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.
35
 *
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).
43
 */
44

            
45
#include "cairo-test.h"
46

            
47
static cairo_test_status_t
48
3
draw (cairo_t *cr, int width, int height)
49
{
50
3
    cairo_set_source_rgb (cr, 1, 1, 1);
51
3
    cairo_paint (cr);
52

            
53
3
    cairo_translate (cr, 1.0, 1.0);
54

            
55
3
    cairo_set_source_rgb (cr, 1, 0, 0); /* red */
56

            
57
    /* First draw the desired shape with a fill */
58
3
    cairo_rectangle (cr, 0.5, 0.5,  4.0, 4.0);
59
3
    cairo_rectangle (cr, 3.5, 3.5,  4.0, 4.0);
60
3
    cairo_rectangle (cr, 3.5, 1.5, -2.0, 2.0);
61
3
    cairo_rectangle (cr, 6.5, 4.5, -2.0, 2.0);
62

            
63
3
    cairo_fill (cr);
64

            
65
    /* Then try the same thing with a stroke */
66
3
    cairo_translate (cr, 0, 10);
67
3
    cairo_move_to (cr, 1.0, 1.0);
68
3
    cairo_rel_line_to (cr,  3.0,  0.0);
69
3
    cairo_rel_line_to (cr,  0.0,  6.0);
70
3
    cairo_rel_line_to (cr,  3.0,  0.0);
71
3
    cairo_rel_line_to (cr,  0.0, -3.0);
72
3
    cairo_rel_line_to (cr, -6.0,  0.0);
73
3
    cairo_close_path (cr);
74

            
75
3
    cairo_set_line_width (cr, 1.0);
76
3
    cairo_stroke (cr);
77

            
78
3
    return CAIRO_TEST_SUCCESS;
79
}
80

            
81
1
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 */
86
	    10, 20,
87
	    NULL, draw)