1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2015 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_test_sanity_pair_at_time(gint i
)
47 /* Check that invalid arguments crashes the process */
50 cpml_curve_put_pair_at_time(NULL
, 0, &pair
);
53 cpml_curve_put_pair_at_time(&curve
, 0, NULL
);
56 g_test_trap_assert_failed();
62 _cpml_test_sanity_vector_at_time(gint i
)
66 /* Check that invalid arguments crashes the process */
69 cpml_curve_put_vector_at_time(NULL
, 0, &vector
);
72 cpml_curve_put_vector_at_time(&curve
, 0, NULL
);
75 g_test_trap_assert_failed();
81 _cpml_test_sanity_offset_at_time(gint i
)
85 /* Check that invalid arguments crashes the process */
88 cpml_curve_put_offset_at_time(NULL
, 0, 0, &pair
);
91 cpml_curve_put_offset_at_time(&curve
, 0, 0, NULL
);
94 g_test_trap_assert_failed();
100 _cpml_test_offset_algorithm(void)
102 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_GEOMETRICAL
), ==, CPML_CURVE_OFFSET_ALGORITHM_HANDCRAFT
);
103 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_NONE
), ==, CPML_CURVE_OFFSET_ALGORITHM_GEOMETRICAL
);
104 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_BAIOCA
), ==, CPML_CURVE_OFFSET_ALGORITHM_GEOMETRICAL
);
105 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_DEFAULT
), ==, CPML_CURVE_OFFSET_ALGORITHM_BAIOCA
);
106 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_GEOMETRICAL
), ==, CPML_CURVE_OFFSET_ALGORITHM_HANDCRAFT
);
107 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_HANDCRAFT
), ==, CPML_CURVE_OFFSET_ALGORITHM_GEOMETRICAL
);
108 g_assert_cmpint(cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_NONE
), ==, CPML_CURVE_OFFSET_ALGORITHM_HANDCRAFT
);
112 _cpml_test_pair_at_time(void)
116 cpml_curve_put_pair_at_time(&curve
, 0, &pair
);
117 g_assert_cmpfloat(pair
.x
, ==, 1);
118 g_assert_cmpfloat(pair
.y
, ==, 1);
120 cpml_curve_put_pair_at_time(&curve
, 0.5, &pair
);
121 g_assert_cmpfloat(pair
.x
, ==, 2);
122 g_assert_cmpfloat(pair
.y
, ==, 3);
124 cpml_curve_put_pair_at_time(&curve
, 1, &pair
);
125 g_assert_cmpfloat(pair
.x
, ==, 3);
126 g_assert_cmpfloat(pair
.y
, ==, 5);
128 /* t is not bound to domain 0..1 */
129 cpml_curve_put_pair_at_time(&curve
, -1, &pair
);
130 g_assert_cmpfloat(pair
.x
, ==, 11);
131 g_assert_cmpfloat(pair
.y
, ==, -15);
133 cpml_curve_put_pair_at_time(&curve
, 2, &pair
);
134 g_assert_cmpfloat(pair
.x
, ==, -7);
135 g_assert_cmpfloat(pair
.y
, ==, 21);
139 _cpml_test_vector_at_time(void)
143 cpml_curve_put_vector_at_time(&curve
, 0, &vector
);
144 g_assert_cmpfloat(vector
.x
, ==, 0);
145 g_assert_cmpfloat(vector
.y
, ==, 6);
147 cpml_curve_put_vector_at_time(&curve
, 0.5, &vector
);
148 g_assert_cmpfloat(vector
.x
, ==, 3);
149 g_assert_cmpfloat(vector
.y
, ==, 3);
151 cpml_curve_put_vector_at_time(&curve
, 1, &vector
);
152 g_assert_cmpfloat(vector
.x
, ==, 0);
153 g_assert_cmpfloat(vector
.y
, ==, 6);
155 /* t is not bound to domain 0..1 */
156 cpml_curve_put_vector_at_time(&curve
, -1, &vector
);
157 g_assert_cmpfloat(vector
.x
, ==, -24);
158 g_assert_cmpfloat(vector
.y
, ==, 30);
160 cpml_curve_put_vector_at_time(&curve
, 2, &vector
);
161 g_assert_cmpfloat(vector
.x
, ==, -24);
162 g_assert_cmpfloat(vector
.y
, ==, 30);
166 _cpml_test_offset_at_time(void)
170 /* TODO: test some other points other than 0 and 1, also
171 * outside the 0..1 domainother offset algorithms */
173 cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_HANDCRAFT
);
175 cpml_curve_put_offset_at_time(&curve
, 0, 1, &pair
);
176 g_assert_cmpfloat(pair
.x
, ==, 0);
177 g_assert_cmpfloat(pair
.y
, ==, 1);
179 cpml_curve_put_offset_at_time(&curve
, 1, 1, &pair
);
180 g_assert_cmpfloat(pair
.x
, ==, 2);
181 g_assert_cmpfloat(pair
.y
, ==, 5);
183 cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_GEOMETRICAL
);
185 cpml_curve_put_offset_at_time(&curve
, 0, 1, &pair
);
186 g_assert_cmpfloat(pair
.x
, ==, 0);
187 g_assert_cmpfloat(pair
.y
, ==, 1);
189 cpml_curve_put_offset_at_time(&curve
, 1, 1, &pair
);
190 g_assert_cmpfloat(pair
.x
, ==, 2);
191 g_assert_cmpfloat(pair
.y
, ==, 5);
193 cpml_curve_offset_algorithm(CPML_CURVE_OFFSET_ALGORITHM_BAIOCA
);
195 cpml_curve_put_offset_at_time(&curve
, 0, 1, &pair
);
196 g_assert_cmpfloat(pair
.x
, ==, 0);
197 g_assert_cmpfloat(pair
.y
, ==, 1);
199 cpml_curve_put_offset_at_time(&curve
, 1, 1, &pair
);
200 g_assert_cmpfloat(pair
.x
, ==, 2);
201 g_assert_cmpfloat(pair
.y
, ==, 5);
206 main(int argc
, char *argv
[])
208 adg_test_init(&argc
, &argv
);
210 adg_test_add_traps("/cpml/curve/sanity/pair-at-time", _cpml_test_sanity_pair_at_time
, 2);
211 adg_test_add_traps("/cpml/curve/sanity/vector-at-time", _cpml_test_sanity_vector_at_time
, 2);
212 adg_test_add_traps("/cpml/curve/sanity/offset-at-time", _cpml_test_sanity_offset_at_time
, 2);
214 g_test_add_func("/cpml/curve/method/offset-algorithm", _cpml_test_offset_algorithm
);
215 g_test_add_func("/cpml/curve/method/pair-at-time", _cpml_test_pair_at_time
);
216 g_test_add_func("/cpml/curve/method/vector-at-time", _cpml_test_vector_at_time
);
217 g_test_add_func("/cpml/curve/method/offset-at-time", _cpml_test_offset_at_time
);