From 3969f2c687aa94721e02d50c2f9e1b4d62a546f7 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 27 Sep 2012 09:56:36 +0100 Subject: [PATCH] test: Add clip-disjoint-quad MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Exercises a bug in the polygon intersection code demonstrated by Søren Sandmann. Signed-off-by: Chris Wilson --- test/Makefile.sources | 1 + test/clip-disjoint-quad.c | 83 ++++++++++++++++++++++ test/reference/clip-disjoint-quad.ref.png | Bin 0 -> 1542 bytes 3 files changed, 84 insertions(+) create mode 100644 test/clip-disjoint-quad.c create mode 100644 test/reference/clip-disjoint-quad.ref.png diff --git a/test/Makefile.sources b/test/Makefile.sources index ca509bac7..fdf262c36 100644 --- a/test/Makefile.sources +++ b/test/Makefile.sources @@ -46,6 +46,7 @@ test_sources = \ clip-complex-shape.c \ clip-disjoint.c \ clip-disjoint-hatching.c \ + clip-disjoint-quad.c \ clip-device-offset.c \ clip-double-free.c \ clip-draw-unbounded.c \ diff --git a/test/clip-disjoint-quad.c b/test/clip-disjoint-quad.c new file mode 100644 index 000000000..fe20381d7 --- /dev/null +++ b/test/clip-disjoint-quad.c @@ -0,0 +1,83 @@ +/* + * Copyright © 2012 Red Hat, Inc. + * Copyright © 2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Author: Soren Sandmann + * Chris Wilson + */ + +#include "cairo-test.h" + +#define WIDTH 100 +#define HEIGHT 200 + +static void +draw_quad (cairo_t *cr, + double x1, double y1, + double x2, double y2, + double x3, double y3, + double x4, double y4) +{ + cairo_move_to (cr, x1, y1); + cairo_line_to (cr, x2, y2); + cairo_line_to (cr, x3, y3); + cairo_line_to (cr, x4, y4); + cairo_close_path (cr); + + cairo_set_source_rgb (cr, 0, 0.6, 0); + cairo_fill (cr); +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + int position[5] = {0, HEIGHT/2-10, HEIGHT/2-5, HEIGHT/2, HEIGHT-10 }; + int i; + + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_paint (cr); + + for (i = 0; i < 5; i++) { + cairo_reset_clip (cr); + cairo_set_source_rgb (cr, 1, 1, 1); + cairo_rectangle (cr, 0, 0, WIDTH/2, HEIGHT/2); + cairo_rectangle (cr, WIDTH/2, position[i], WIDTH/2, 10); + cairo_fill_preserve (cr); + cairo_clip (cr); + + cairo_set_source_rgb (cr, 1, 0, 1); + draw_quad (cr, 50, 50, 75, 75, 50, 150, 25, 75); + cairo_fill (cr); + + cairo_translate(cr, WIDTH, 0); + } + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (clip_disjoint_quad, + "Tests a simple fill through two disjoint clips.", + "clip, fill", /* keywords */ + NULL, /* requirements */ + 5*WIDTH, HEIGHT, + NULL, draw) diff --git a/test/reference/clip-disjoint-quad.ref.png b/test/reference/clip-disjoint-quad.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..de5ceb77b60054a8c8664cbb7660fbf7949d2847 GIT binary patch literal 1542 zcmeAS@N?(olHy`uVBq!ia0y~yVEh7PpWt8uk`t?2_5&%lByV>YhW{YAVDIwD3=FKh zJzX3_D(1Ysd$3T%ouTz%Y!{11<6;Y;ZjXbB3ayS@7NW&d`urLNuCeRsMTgkBeE0dj z`u*-~$-hy1XWg56`+!t?eihtN-TK_ov?EOCGANJ)qRibI68#m)FNb za%slY%Ua7r^Ztgd?)m*|>9vKSexOj&jnXxI7d<7a1!Qv6)3VIce>>g>WwAmu-(GR` z!yPCF|V|^Qp6ZA>oj^R;{l(a^*^>1>zTemP@8_%8 zk_U0)>U`6pJNA43n|!#q3lc!<_FX+uxWB&M9!;dWy!`vSya&u;peXQL9aFpdpuKKz z{Uu2ch{bn77XS53R{+JqmQ$tMrEK1PRiE1kcgUao6=m~Fj$MLiFI@fc@x9thl2Df& zU3;v*`nzYk4n();_F1386}$bd4nrNa_3D&DeY=-D(15=d7JO{)k0r+7#1!>3D*EiN z`7@&Yt&Ab@v~JVYHHG=MFV8H1#M7y;e0AG*{gcmq{{Gyv|NfKm=-SG^`+t}G|8k1o zuJbv_JE^N9%im4EH2Iv$@-4T%B#mwvK z3&t|{v+l1yw=cZT1|s-7^>+2)V3|8vuYZf22L{Q`O<~t>zcqV*asGb$`X8SUXWM=1 zzc}6K(4w_*PhbAay#HHdZP7mV;?%Xz?(O_Ox8#}SrmOGb#n%??j{iULRMc77@7{Mk z(^nmi%Kba*3@{(m@IRXs3#2EnQN;aNUjMz_dQ|V%Bx=r^{rp}l=`ghTi+43 zv+w*P3E#E%;?`f^ygpG{cI`a<^Vhu(tACQ(|Ks+a<9Ckh{@U~FXxM!Fy1E}f44!)Z zOT8H8J*)0H-*2r7-)9CrKNlOFHhOp9b)_#Gu#}`b(3^hx qX^}0k%=}ii`|i1YE#iBKDL~~9