1
/*
2
 * Author: Christian Rohlfs, 2022
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

            
25
#include "cairo-test.h"
26

            
27
#define WIDTH   100
28
#define HEIGHT  WIDTH
29

            
30
static cairo_test_status_t
31
3
draw_round(cairo_t *cr, int width, int height)
32
{
33
    /* Fail condition:
34
            0  >=  2 * ( 1 - tolerance / (line_width / 2) )^2 - 1,
35
       with the default tolerance of 0.1, `failing_line_width` is in
36
            [0.117157287525381; 0.682842712474619]
37
       range.
38
    */
39

            
40
3
    double failing_line_width = 0.3;
41

            
42
3
    cairo_set_tolerance(cr, 0.1);
43
3
    cairo_scale(cr, width, height);
44

            
45
3
    cairo_set_source_rgb(cr, 1, 1, 1);
46
3
    cairo_paint(cr);
47

            
48
3
    cairo_move_to(cr, 0.2, 0.2);
49
3
    cairo_line_to(cr, 0.8, 0.2);
50
3
    cairo_line_to(cr, 0.8, 0.8);
51
3
    cairo_line_to(cr, 0.2, 0.8);
52
3
    cairo_close_path(cr);
53

            
54
3
    cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
55
3
    cairo_set_source_rgb(cr, 0, 0, 0);
56
3
    cairo_set_line_width(cr, failing_line_width);
57
3
    cairo_stroke(cr);
58

            
59
3
    return CAIRO_TEST_SUCCESS;
60
}
61

            
62
static cairo_test_status_t
63
3
draw_bevel(cairo_t *cr, int width, int height)
64
{
65
    /* Fail condition:
66
            arc_height < tolerance
67
       For 90° join `arc_height` is equal to
68
            line_width / 2 * (1 - sqrt(1/2))
69
       which is 0.1464466094067262 of a `line_width`.
70
    */
71

            
72
3
    double line_width = 0.3;
73
3
    double failing_tolerance = 0.3 * line_width;
74

            
75
3
    cairo_set_tolerance(cr, width * failing_tolerance);
76
3
    cairo_scale(cr, width, height);
77

            
78
3
    cairo_set_source_rgb(cr, 1, 1, 1);
79
3
    cairo_paint(cr);
80

            
81
3
    cairo_move_to(cr, 0.2, 0.2);
82
3
    cairo_line_to(cr, 0.8, 0.2);
83
3
    cairo_line_to(cr, 0.8, 0.8);
84
3
    cairo_line_to(cr, 0.2, 0.8);
85
3
    cairo_close_path(cr);
86

            
87
3
    cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
88
3
    cairo_set_source_rgb(cr, 0, 0, 0);
89
3
    cairo_set_line_width(cr, line_width);
90
3
    cairo_stroke(cr);
91

            
92
3
    return CAIRO_TEST_SUCCESS;
93
}
94

            
95

            
96
1
CAIRO_TEST (round_join_bug_520_round,
97
    "Tests round joins within tolerance",
98
    "stroke, cap, join", /* keywords */
99
    NULL, /* requirements */
100
    WIDTH, HEIGHT,
101
    NULL, draw_round)
102

            
103
1
CAIRO_TEST (round_join_bug_520_bevel,
104
    "Tests round joins omission when `arc_height < tolerance`",
105
    "stroke, cap, join", /* keywords */
106
    NULL, /* requirements */
107
    WIDTH, HEIGHT,
108
    NULL, draw_bevel)
109