1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2019 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
26 static cairo_path_data_t arc_data
[] = {
27 { .header
= { CPML_MOVE
, 2 }},
30 { .header
= { CPML_ARC
, 3 }},
43 _cpml_sanity_info(gint i
)
47 cpml_arc_info(NULL
, NULL
, NULL
, NULL
, NULL
);
50 g_test_trap_assert_failed();
56 _cpml_sanity_to_cairo(gint i
)
60 cr
= adg_test_cairo_context();
64 cpml_arc_to_cairo(NULL
, cr
);
67 cpml_arc_to_cairo(&arc
, NULL
);
70 g_test_trap_assert_failed();
78 _cpml_sanity_to_curves(int i
)
84 cpml_arc_to_curves(NULL
, &segment
, 1);
87 cpml_arc_to_curves(&arc
, NULL
, 1);
90 /* XXX: this generates a division by 0 but on Travis, for some reason,
91 * that is not enough to crash the process:
92 * https://travis-ci.org/ntd/adg/builds/189592982
96 cpml_arc_to_curves(&arc
, &segment
, 0);
99 g_test_trap_assert_failed();
105 _cpml_method_info(void)
108 double r
, start
, end
;
110 /* Passing NULL to the output arguments is valid */
111 g_assert_true(cpml_arc_info(&arc
, NULL
, NULL
, NULL
, NULL
));
113 g_assert_true(cpml_arc_info(&arc
, ¢er
, &r
, &start
, &end
));
115 adg_assert_isapprox(center
.x
, 0);
116 adg_assert_isapprox(center
.y
, 0);
117 adg_assert_isapprox(r
, 3);
118 adg_assert_isapprox(start
, M_PI_2
);
119 adg_assert_isapprox(end
, -M_PI_2
);
123 _cpml_method_to_curves(void)
125 cairo_path_data_t data
[4*2];
126 CpmlSegment segment
= { NULL
, data
, 0 };
128 /* Approximate with a single curve */
129 cpml_arc_to_curves(&arc
, &segment
, 1);
131 g_assert_cmpint(data
[0].header
.type
, ==, CPML_CURVE
);
132 adg_assert_isapprox(data
[1].point
.x
, 4);
133 adg_assert_isapprox(data
[1].point
.y
, 3);
134 adg_assert_isapprox(data
[2].point
.x
, 4);
135 adg_assert_isapprox(data
[2].point
.y
, -3);
136 adg_assert_isapprox(data
[3].point
.x
, 0);
137 adg_assert_isapprox(data
[3].point
.y
, -3);
139 /* Approximate with two curves */
140 cpml_arc_to_curves(&arc
, &segment
, 2);
142 g_assert_cmpint(data
[0].header
.type
, ==, CPML_CURVE
);
143 adg_assert_isapprox(data
[1].point
.x
, 1.65685425);
144 adg_assert_isapprox(data
[1].point
.y
, 3);
145 adg_assert_isapprox(data
[2].point
.x
, 3);
146 adg_assert_isapprox(data
[2].point
.y
, 1.65685425);
147 adg_assert_isapprox(data
[3].point
.x
, 3);
148 adg_assert_isapprox(data
[3].point
.y
, 0);
150 g_assert_cmpint(data
[4].header
.type
, ==, CPML_CURVE
);
151 adg_assert_isapprox(data
[5].point
.x
, 3);
152 adg_assert_isapprox(data
[5].point
.y
, -1.65685425);
153 adg_assert_isapprox(data
[6].point
.x
, 1.65685425);
154 adg_assert_isapprox(data
[6].point
.y
, -3);
155 adg_assert_isapprox(data
[7].point
.x
, 0);
156 adg_assert_isapprox(data
[7].point
.y
, -3);
162 main(int argc
, char *argv
[])
164 adg_test_init(&argc
, &argv
);
166 adg_test_add_traps("/cpml/arc/sanity/info", _cpml_sanity_info
, 1);
167 adg_test_add_traps("/cpml/arc/sanity/to-cairo", _cpml_sanity_to_cairo
, 2);
168 adg_test_add_traps("/cpml/arc/sanity/to-curves", _cpml_sanity_to_curves
, 2);
170 g_test_add_func("/cpml/arc/method/info", _cpml_method_info
);
171 g_test_add_func("/cpml/arc/method/to-curves", _cpml_method_to_curves
);