1
/*
2
 * Copyright © 2007 Red Hat, Inc.
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: Carl D. Worth <cworth@cworth.org>
25
 */
26

            
27
#include "cairo-test.h"
28

            
29
#define SIZE   20
30
#define PAD    5
31
#define WIDTH  (PAD + 3 * (PAD + SIZE) + PAD)
32
#define HEIGHT (PAD + SIZE + PAD)
33

            
34
/* We're demonstrating here a bug originally reported by Benjamin Otte
35
 * on the cairo mailing list here, (after he ran into this problem
36
 * with various flash animations):
37
 *
38
 *	[cairo] Assertion `i < pen->num_vertices' failed in 1.4.10
39
 *	https://lists.cairographics.org/archives/cairo/2007-August/011282.html
40
 *
41
 * The problem shows up with an extreme transformation matrix that
42
 * collapses the pen to a single line, (which means that
43
 * _cairo_slope_compare cannot handle adjacent vertices in the pen
44
 * since they have parallel slope).
45
 *
46
 * This test case tests degenerate pens in several directions and uses
47
 * round caps to force the stroking code to attempt to walk around the
48
 * pen doing slope comparisons.
49
 */
50

            
51
static cairo_test_status_t
52
3
draw (cairo_t *cr, int width, int height)
53
{
54
3
    cairo_set_source_rgb (cr, 1, 1, 1);
55
3
    cairo_paint (cr);
56

            
57
3
    cairo_set_source_rgb (cr, 0, 0, 0);
58
3
    cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
59

            
60
3
    cairo_translate (cr, PAD, PAD);
61

            
62
    /* First compress the pen to a vertical line. */
63
3
    cairo_rectangle (cr, 0, 0, SIZE, SIZE);
64
3
    cairo_curve_to (cr, SIZE / 2, 0, SIZE, SIZE / 2, SIZE, SIZE);
65
3
    cairo_save (cr);
66
    {
67
3
	cairo_scale (cr, 0.000001, 1.0);
68
3
	cairo_stroke (cr);
69
    }
70
3
    cairo_restore (cr);
71

            
72
3
    cairo_translate (cr, PAD + SIZE, 0);
73

            
74
    /* Then compress the pen to a horizontal line. */
75
3
    cairo_rectangle (cr, 0, 0, SIZE, SIZE);
76
3
    cairo_curve_to (cr, SIZE / 2, 0, SIZE, SIZE / 2, SIZE, SIZE);
77
3
    cairo_save (cr);
78
    {
79
3
	cairo_scale (cr, 1.0, 0.000001);
80
3
	cairo_stroke (cr);
81
    }
82
3
    cairo_restore (cr);
83

            
84
3
    cairo_translate (cr, PAD + SIZE, 0);
85

            
86
    /* Finally a line at an angle. */
87
3
    cairo_rectangle (cr, 0, 0, SIZE, SIZE);
88
3
    cairo_curve_to (cr, SIZE / 2, 0, SIZE, SIZE / 2, SIZE, SIZE);
89
3
    cairo_save (cr);
90
    {
91
3
	cairo_rotate (cr, M_PI / 4.0);
92
3
	cairo_scale (cr, 0.000001, 1.0);
93
3
	cairo_stroke (cr);
94
    }
95
3
    cairo_restore (cr);
96

            
97
3
    return CAIRO_TEST_SUCCESS;
98
}
99

            
100
1
CAIRO_TEST (degenerate_pen,
101
	    "Test round joins with a pen that's transformed to a line",
102
	    "degenerate", /* keywords */
103
	    NULL, /* requirements */
104
	    WIDTH, HEIGHT,
105
	    NULL, draw)