From bb3d06a5dc6cd1eef368a9679a67ff8341860ac1 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 20 Aug 2011 16:00:13 +0100 Subject: [PATCH] test: Add shape-general-concave A discussion that we've been having is the use of contours in filling, and for optimizing for convex contours in particular. A devious mind quickly generates a shape using a convex "contour" whose hull is larger than its area. This is due to the self-intersection of the "contour" which if properly excised causes the contour to be classed as concave. Signed-off-by: Chris Wilson --- test/Makefile.refs | 4 +- test/Makefile.sources | 1 + test/shape-general-convex.c | 88 ++++++++++++++++++++++++++++++ test/shape-general-convex.ref.png | Bin 0 -> 3470 bytes 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 test/shape-general-convex.c create mode 100644 test/shape-general-convex.ref.png diff --git a/test/Makefile.refs b/test/Makefile.refs index e0dd734d6..8bdfa65a5 100644 --- a/test/Makefile.refs +++ b/test/Makefile.refs @@ -1146,6 +1146,7 @@ REFERENCE_IMAGES = \ self-intersecting.xlib.ref.png \ set-source.ref.png \ set-source.rgb24.ref.png \ + shape-general-concave.ref.png \ show-glyphs-advance.image16.ref.png \ show-glyphs-advance.ps.ref.png \ show-glyphs-advance.quartz.ref.png \ @@ -1290,9 +1291,6 @@ REFERENCE_IMAGES = \ svg-surface-source.rgb24.ref.png \ svg-surface-source.svg12.argb32.xfail.png \ svg-surface-source.svg12.rgb24.xfail.png \ - test-fallback16-surface-source.ps.ref.png \ - test-fallback16-surface-source.svg12.argb32.xfail.png \ - test-fallback16-surface-source.svg12.rgb24.xfail.png \ text-antialias-gray.image16.ref.png \ text-antialias-gray.quartz.ref.png \ text-antialias-gray.ref.png \ diff --git a/test/Makefile.sources b/test/Makefile.sources index f236e53e0..b61557fe7 100644 --- a/test/Makefile.sources +++ b/test/Makefile.sources @@ -267,6 +267,7 @@ test_sources = \ show-glyphs-advance.c \ show-glyphs-many.c \ show-text-current-point.c \ + shape-general-convex.c \ skew-extreme.c \ smask.c \ smask-fill.c \ diff --git a/test/shape-general-convex.c b/test/shape-general-convex.c new file mode 100644 index 000000000..b9241bb9f --- /dev/null +++ b/test/shape-general-convex.c @@ -0,0 +1,88 @@ +/* + * Copyright © 2011 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: Chris Wilson + */ + +/* A general convex shape with a twist. */ + +#include "cairo-test.h" + +#define SIZE (100) +#define PAD 4 + +static void +limacon (cairo_t *cr, double a, double b, double radius) +{ + int i; + + cairo_save (cr); + cairo_translate (cr, PAD, 0); + for (i = 0; i < 360; i++) { + double theta = i * M_PI / 180; + double r = b + a * cos (theta); + double x = radius * r * cos (theta); + double y = radius * r * sin (theta); + cairo_line_to (cr, x, y); + } + cairo_close_path (cr); + cairo_restore (cr); +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_set_source_rgb (cr, 1, 1, 1); + cairo_paint (cr); + + cairo_save (cr); + cairo_translate (cr, 2*PAD, PAD); + + cairo_translate (cr, SIZE/2, SIZE/2); + limacon (cr, 1, .5, SIZE/3); /* trivia, this is a trisectrix */ + + cairo_set_source_rgb (cr, 1, 0, 0); + cairo_fill_preserve (cr); + + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_stroke (cr); + + cairo_scale (cr, -1, 1); + + limacon (cr, 1, .5, SIZE/3); /* trivia, this is a trisectrix */ + + cairo_set_source_rgb (cr, 0, 0, 1); + cairo_fill_preserve (cr); + + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_stroke (cr); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (shape_general_convex, + "A general shape that is not as convex as it first appears", + "fill,stroke", /* keywords */ + NULL, /* requirements */ + SIZE+4*PAD, SIZE+4*PAD, + NULL, draw) diff --git a/test/shape-general-convex.ref.png b/test/shape-general-convex.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..55f5c5666dae0329e4cff755961355cb52abf068 GIT binary patch literal 3470 zcmbtXi96KY7yr%-#*(E(_T?2rBwN`MSrSQP&oYA|`-FtbGR#bjM5>pNEosO)_H}HL zr3hJvnc*ed*pn^4@B8}?e$VgT=iYOl=iYms=brPq=X_3_g}E^&yAV470GuY*4R3=o z_}{?_1?S1%(P&VxxZN-|1djjh*-Zs0;7J1$!>iVz8LOF3Eo|lC1j-9PfgCmJC=bwVTklJ{k zi_Jr3>^#%3rKJQuX_PVfXCruhJ+N*!a4o2m6x6(xzTxt7FQg%l~DIG+gv3IM}}UM^aK!clUK7 za;_Na-j{_I78dU9?e+O@JI{Z^%F622trr@n`S~yTPt|HOYTfs@7k8&02Y7ogReB8_ z{vK&x?n_g(v9ak&6fGhW>(DfPAD^OWdnYF+H#fK2|F-W_bwRVUvq!%=&9iKfNTjv3 zTF`u7j-ohZkVpA9d6;O$!OkuuEc{fRYRbvU$;`}b^}%eTjlVBLll1Z9$DEwjM=&Y; zGFl^^Ku}dxhab=w3;NU=io4l^}3PW*s)Ukld2fqSu1s(q0 zNKV@jVpREz+J3Unk&Z`_mj{;0_gV)}l(q>-T)zC|;Mb~@xf~aM_PP2rD>pa%Gr4Gh z9#d>PcB00c_?uYpu0CY-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