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"
41 cairo_test_context_t ctx
;
45 cairo_surface_t
*surf
;
47 int false_positive_count
= 0;
48 cairo_status_t status
;
49 char const * description
=
50 "Test that the tessellator isn't producing obviously empty trapezoids";
51 cairo_test_status_t ret
;
53 cairo_test_init (&ctx
, "in-fill-empty-trapezoid");
54 cairo_test_log (&ctx
, "%s\n", description
);
55 printf ("%s\n", description
);
57 surf
= cairo_image_surface_create (CAIRO_FORMAT_ARGB32
, width
, height
);
58 cr
= cairo_create (surf
);
59 cairo_surface_destroy (surf
);
61 /* Empty horizontal trapezoid. */
62 cairo_move_to (cr
, 0, height
/3);
63 cairo_line_to (cr
, width
, height
/3);
64 cairo_close_path (cr
);
66 /* Empty non-horizontal trapezoid #1. */
67 cairo_move_to (cr
, 0, 0);
68 cairo_line_to (cr
, width
, height
/2);
69 cairo_close_path (cr
);
71 /* Empty non-horizontal trapezoid #2 intersecting #1. */
72 cairo_move_to (cr
, 0, height
/2);
73 cairo_line_to (cr
, width
, 0);
74 cairo_close_path (cr
);
76 status
= cairo_status (cr
);
78 /* Point sample the tessellated path. */
79 for (y
= 0; y
< height
; y
++) {
80 for (x
= 0; x
< width
; x
++) {
81 if (cairo_in_fill (cr
, x
, y
)) {
82 false_positive_count
++;
88 /* Check that everything went well. */
89 ret
= CAIRO_TEST_SUCCESS
;
90 if (CAIRO_STATUS_SUCCESS
!= status
) {
91 cairo_test_log (&ctx
, "Failed to create a test surface and path: %s\n",
92 cairo_status_to_string (status
));
93 ret
= CAIRO_TEST_FAILURE
;
96 if (0 != false_positive_count
) {
97 cairo_test_log (&ctx
, "Point sampling found %d false positives "
98 "from cairo_in_fill()\n",
99 false_positive_count
);
100 ret
= CAIRO_TEST_FAILURE
;
103 cairo_test_fini (&ctx
);