2 * Copyright © 2006 M Joonas Pihlaja
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 * Author: M Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
29 * 2006-12-05 M Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
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.
36 #include "cairo-test.h"
38 static cairo_test_status_t
39 preamble (cairo_test_context_t *ctx)
44 cairo_surface_t *surf;
46 int false_positive_count = 0;
47 cairo_status_t status;
48 cairo_test_status_t ret;
50 surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
51 cr = cairo_create (surf);
52 cairo_surface_destroy (surf);
54 /* Empty horizontal trapezoid. */
55 cairo_move_to (cr, 0, height/3);
56 cairo_line_to (cr, width, height/3);
57 cairo_close_path (cr);
59 /* Empty non-horizontal trapezoid #1. */
60 cairo_move_to (cr, 0, 0);
61 cairo_line_to (cr, width, height/2);
62 cairo_close_path (cr);
64 /* Empty non-horizontal trapezoid #2 intersecting #1. */
65 cairo_move_to (cr, 0, height/2);
66 cairo_line_to (cr, width, 0);
67 cairo_close_path (cr);
69 status = cairo_status (cr);
71 /* Point sample the tessellated path. */
72 for (y = 0; y < height; y++) {
73 for (x = 0; x < width; x++) {
74 if (cairo_in_fill (cr, x, y)) {
75 false_positive_count++;
81 /* Check that everything went well. */
82 ret = CAIRO_TEST_SUCCESS;
83 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;
89 if (0 != false_positive_count) {
90 cairo_test_log (ctx, "Point sampling found %d false positives "
91 "from cairo_in_fill()\n",
92 false_positive_count);
93 ret = CAIRO_TEST_XFAILURE;
99 CAIRO_TEST (in_fill_empty_trapezoid,
100 "Test that the tessellator isn't producing obviously empty trapezoids",
101 "in, trap", /* keywords */
102 NULL, /* requirements */