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.
25 static cairo_path_data_t curve_data
[] = {
26 { .header
= { CPML_MOVE
, 2 }},
29 { .header
= { CPML_CURVE
, 4 }},
35 CpmlPrimitive curve
= {
43 _cpml_sanity_pair_at_time(gint i
)
49 cpml_curve_put_pair_at_time(NULL
, 0, &pair
);
52 cpml_curve_put_pair_at_time(&curve
, 0, NULL
);
55 g_test_trap_assert_failed();
61 _cpml_sanity_vector_at_time(gint i
)
67 cpml_curve_put_vector_at_time(NULL
, 0, &vector
);
70 cpml_curve_put_vector_at_time(&curve
, 0, NULL
);
73 g_test_trap_assert_failed();
79 _cpml_sanity_offset_at_time(gint i
)
85 cpml_curve_put_offset_at_time(NULL
, 0, 0, &pair
);
88 cpml_curve_put_offset_at_time(&curve
, 0, 0, NULL
);
91 g_test_trap_assert_failed();
97 _cpml_method_offset_algorithm(void)
99 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_GEOMETRICAL
), ==, CPML_CURVE_OFFSET_ALGORITHM_HANDCRAFT
);
100 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_NONE
), ==, CPML_CURVE_OFFSET_ALGORITHM_GEOMETRICAL
);
101 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_BAIOCA
), ==, CPML_CURVE_OFFSET_ALGORITHM_GEOMETRICAL
);
102 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_DEFAULT
), ==, CPML_CURVE_OFFSET_ALGORITHM_BAIOCA
);
103 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_GEOMETRICAL
), ==, CPML_CURVE_OFFSET_ALGORITHM_HANDCRAFT
);
104 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_HANDCRAFT
), ==, CPML_CURVE_OFFSET_ALGORITHM_GEOMETRICAL
);
105 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_NONE
), ==, CPML_CURVE_OFFSET_ALGORITHM_HANDCRAFT
);
109 _cpml_method_pair_at_time(void)
113 cpml_curve_put_pair_at_time(&curve
, 0, &pair
);
114 adg_assert_isapprox(pair
.x
, 1);
115 adg_assert_isapprox(pair
.y
, 1);
117 cpml_curve_put_pair_at_time(&curve
, 0.5, &pair
);
118 adg_assert_isapprox(pair
.x
, 2);
119 adg_assert_isapprox(pair
.y
, 3);
121 cpml_curve_put_pair_at_time(&curve
, 1, &pair
);
122 adg_assert_isapprox(pair
.x
, 3);
123 adg_assert_isapprox(pair
.y
, 5);
125 /* t is not bound to domain 0..1 */
126 cpml_curve_put_pair_at_time(&curve
, -1, &pair
);
127 adg_assert_isapprox(pair
.x
, 11);
128 adg_assert_isapprox(pair
.y
, -15);
130 cpml_curve_put_pair_at_time(&curve
, 2, &pair
);
131 adg_assert_isapprox(pair
.x
, -7);
132 adg_assert_isapprox(pair
.y
, 21);
136 _cpml_method_vector_at_time(void)
140 cpml_curve_put_vector_at_time(&curve
, 0, &vector
);
141 adg_assert_isapprox(vector
.x
, 0);
142 adg_assert_isapprox(vector
.y
, 6);
144 cpml_curve_put_vector_at_time(&curve
, 0.5, &vector
);
145 adg_assert_isapprox(vector
.x
, 3);
146 adg_assert_isapprox(vector
.y
, 3);
148 cpml_curve_put_vector_at_time(&curve
, 1, &vector
);
149 adg_assert_isapprox(vector
.x
, 0);
150 adg_assert_isapprox(vector
.y
, 6);
152 /* t is not bound to domain 0..1 */
153 cpml_curve_put_vector_at_time(&curve
, -1, &vector
);
154 adg_assert_isapprox(vector
.x
, -24);
155 adg_assert_isapprox(vector
.y
, 30);
157 cpml_curve_put_vector_at_time(&curve
, 2, &vector
);
158 adg_assert_isapprox(vector
.x
, -24);
159 adg_assert_isapprox(vector
.y
, 30);
163 _cpml_method_offset_at_time(void)
167 cpml_curve_put_offset_at_time(&curve
, 0, 1, &pair
);
168 adg_assert_isapprox(pair
.x
, 0);
169 adg_assert_isapprox(pair
.y
, 1);
171 cpml_curve_put_offset_at_time(&curve
, 1, 1, &pair
);
172 adg_assert_isapprox(pair
.x
, 2);
173 adg_assert_isapprox(pair
.y
, 5);
175 cpml_curve_put_offset_at_time(&curve
, 0, 2, &pair
);
176 adg_assert_isapprox(pair
.x
, -1);
177 adg_assert_isapprox(pair
.y
, 1);
179 cpml_curve_put_offset_at_time(&curve
, 0.5, 0, &pair
);
180 adg_assert_isapprox(pair
.x
, 2);
181 adg_assert_isapprox(pair
.y
, 3);
183 cpml_curve_put_offset_at_time(&curve
, 0.5, G_SQRT2
, &pair
);
184 /* Check only the first 5 digits to avoid rounding errors */
185 g_assert_cmpint((pair
.x
+ 0.00005) * 10000, ==, 10000);
186 g_assert_cmpint((pair
.y
+ 0.00005) * 10000, ==, 40000);
191 main(int argc
, char *argv
[])
193 adg_test_init(&argc
, &argv
);
195 adg_test_add_traps("/cpml/curve/sanity/pair-at-time", _cpml_sanity_pair_at_time
, 2);
196 adg_test_add_traps("/cpml/curve/sanity/vector-at-time", _cpml_sanity_vector_at_time
, 2);
197 adg_test_add_traps("/cpml/curve/sanity/offset-at-time", _cpml_sanity_offset_at_time
, 2);
199 g_test_add_func("/cpml/curve/method/offset-algorithm", _cpml_method_offset_algorithm
);
200 g_test_add_func("/cpml/curve/method/pair-at-time", _cpml_method_pair_at_time
);
201 g_test_add_func("/cpml/curve/method/vector-at-time", _cpml_method_vector_at_time
);
202 g_test_add_func("/cpml/curve/method/offset-at-time", _cpml_method_offset_at_time
);