1
/*
2
 * Copyright © 2006 M Joonas Pihlaja
3
 *
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use, copy,
8
 * modify, merge, publish, distribute, sublicense, and/or sell copies
9
 * of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be
13
 * included in all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 *
24
 * Author: M Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
25
 */
26

            
27
/* Bug history
28
 *
29
 * 2006-12-05  M Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
30
 *
31
 *  The cairo_in_fill () function can sometimes produce false
32
 *  positives when the tessellator produces empty trapezoids
33
 *  and the query point lands exactly on a trapezoid edge.
34
 */
35

            
36
#include "cairo-test.h"
37

            
38
static cairo_test_status_t
39
1
preamble (cairo_test_context_t *ctx)
40
{
41
    int x,y;
42
1
    int width = 10;
43
1
    int height = 10;
44
    cairo_surface_t *surf;
45
    cairo_t *cr;
46
1
    int false_positive_count = 0;
47
    cairo_status_t status;
48
    cairo_test_status_t ret;
49

            
50
1
    surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
51
1
    cr = cairo_create (surf);
52
1
    cairo_surface_destroy (surf);
53

            
54
    /* Empty horizontal trapezoid. */
55
1
    cairo_move_to (cr, 0, height/3);
56
1
    cairo_line_to (cr, width, height/3);
57
1
    cairo_close_path (cr);
58

            
59
    /* Empty non-horizontal trapezoid #1. */
60
1
    cairo_move_to (cr, 0, 0);
61
1
    cairo_line_to (cr, width, height/2);
62
1
    cairo_close_path (cr);
63

            
64
    /* Empty non-horizontal trapezoid #2 intersecting #1. */
65
1
    cairo_move_to (cr, 0, height/2);
66
1
    cairo_line_to (cr, width, 0);
67
1
    cairo_close_path (cr);
68

            
69
1
    status = cairo_status (cr);
70

            
71
    /* Point sample the tessellated path. */
72
11
    for (y = 0; y < height; y++) {
73
110
	for (x = 0; x < width; x++) {
74
100
	    if (cairo_in_fill (cr, x, y)) {
75
18
		false_positive_count++;
76
	    }
77
	}
78
    }
79
1
    cairo_destroy (cr);
80

            
81
    /* Check that everything went well. */
82
1
    ret = CAIRO_TEST_SUCCESS;
83
1
    if (CAIRO_STATUS_SUCCESS != status) {
84
	cairo_test_log (ctx, "Failed to create a test surface and path: %s\n",
85
			cairo_status_to_string (status));
86
	ret = CAIRO_TEST_XFAILURE;
87
    }
88

            
89
1
    if (0 != false_positive_count) {
90
1
	cairo_test_log (ctx, "Point sampling found %d false positives "
91
			"from cairo_in_fill()\n",
92
			false_positive_count);
93
1
	ret = CAIRO_TEST_XFAILURE;
94
    }
95

            
96
1
    return ret;
97
}
98

            
99
/*
100
 * XFAIL: The cairo_in_fill () function can sometimes produce false positives
101
 * when the tessellator produces empty trapezoids and the query point lands
102
 * exactly on a trapezoid edge.
103
 */
104
1
CAIRO_TEST (in_fill_empty_trapezoid,
105
	    "Test that the tessellator isn't producing obviously empty trapezoids",
106
	    "in, trap", /* keywords */
107
	    NULL, /* requirements */
108
	    0, 0,
109
	    preamble, NULL)