1 | /*
|
---|
2 | * Copyright (c) 2019 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include <gfx/coord.h>
|
---|
30 | #include <pcut/pcut.h>
|
---|
31 |
|
---|
32 | PCUT_INIT;
|
---|
33 |
|
---|
34 | PCUT_TEST_SUITE(coord);
|
---|
35 |
|
---|
36 | /** gfx_coord2_add should add two coordinate vectors */
|
---|
37 | PCUT_TEST(coord2_add)
|
---|
38 | {
|
---|
39 | gfx_coord2_t a, b;
|
---|
40 | gfx_coord2_t d;
|
---|
41 |
|
---|
42 | a.x = 10;
|
---|
43 | a.y = 11;
|
---|
44 | b.x = 20;
|
---|
45 | b.y = 22;
|
---|
46 |
|
---|
47 | gfx_coord2_add(&a, &b, &d);
|
---|
48 |
|
---|
49 | PCUT_ASSERT_INT_EQUALS(a.x + b.x, d.x);
|
---|
50 | PCUT_ASSERT_INT_EQUALS(a.y + b.y, d.y);
|
---|
51 | }
|
---|
52 |
|
---|
53 | /** gfx_coord2_subtract should subtract two coordinate vectors */
|
---|
54 | PCUT_TEST(coord2_subtract)
|
---|
55 | {
|
---|
56 | gfx_coord2_t a, b;
|
---|
57 | gfx_coord2_t d;
|
---|
58 |
|
---|
59 | a.x = 10;
|
---|
60 | a.y = 11;
|
---|
61 | b.x = 20;
|
---|
62 | b.y = 22;
|
---|
63 |
|
---|
64 | gfx_coord2_subtract(&a, &b, &d);
|
---|
65 |
|
---|
66 | PCUT_ASSERT_INT_EQUALS(a.x - b.x, d.x);
|
---|
67 | PCUT_ASSERT_INT_EQUALS(a.y - b.y, d.y);
|
---|
68 | }
|
---|
69 |
|
---|
70 | /** gfx_coord2_clip with point to lower-left of clipping rectangle */
|
---|
71 | PCUT_TEST(coord2_clip_ll)
|
---|
72 | {
|
---|
73 | gfx_coord2_t p;
|
---|
74 | gfx_coord2_t cp;
|
---|
75 | gfx_rect_t rect;
|
---|
76 |
|
---|
77 | p.x = 1;
|
---|
78 | p.y = 2;
|
---|
79 |
|
---|
80 | rect.p0.x = 3;
|
---|
81 | rect.p0.y = 4;
|
---|
82 | rect.p1.x = 5;
|
---|
83 | rect.p1.y = 6;
|
---|
84 |
|
---|
85 | gfx_coord2_clip(&p, &rect, &cp);
|
---|
86 |
|
---|
87 | PCUT_ASSERT_INT_EQUALS(3, cp.x);
|
---|
88 | PCUT_ASSERT_INT_EQUALS(4, cp.y);
|
---|
89 | }
|
---|
90 |
|
---|
91 | /** gfx_coord2_clip with point inside the clipping rectangle */
|
---|
92 | PCUT_TEST(coord2_clip_mm)
|
---|
93 | {
|
---|
94 | gfx_coord2_t p;
|
---|
95 | gfx_coord2_t cp;
|
---|
96 | gfx_rect_t rect;
|
---|
97 |
|
---|
98 | p.x = 2;
|
---|
99 | p.y = 3;
|
---|
100 |
|
---|
101 | rect.p0.x = 1;
|
---|
102 | rect.p0.y = 2;
|
---|
103 | rect.p1.x = 3;
|
---|
104 | rect.p1.y = 4;
|
---|
105 |
|
---|
106 | gfx_coord2_clip(&p, &rect, &cp);
|
---|
107 |
|
---|
108 | PCUT_ASSERT_INT_EQUALS(2, cp.x);
|
---|
109 | PCUT_ASSERT_INT_EQUALS(3, cp.y);
|
---|
110 | }
|
---|
111 |
|
---|
112 | /** gfx_coord2_clip with point to upper-right of clipping rectangle */
|
---|
113 | PCUT_TEST(coord2_clip_hh)
|
---|
114 | {
|
---|
115 | gfx_coord2_t p;
|
---|
116 | gfx_coord2_t cp;
|
---|
117 | gfx_rect_t rect;
|
---|
118 |
|
---|
119 | p.x = 5;
|
---|
120 | p.y = 6;
|
---|
121 |
|
---|
122 | rect.p0.x = 1;
|
---|
123 | rect.p0.y = 2;
|
---|
124 | rect.p1.x = 3;
|
---|
125 | rect.p1.y = 4;
|
---|
126 |
|
---|
127 | gfx_coord2_clip(&p, &rect, &cp);
|
---|
128 |
|
---|
129 | PCUT_ASSERT_INT_EQUALS(2, cp.x);
|
---|
130 | PCUT_ASSERT_INT_EQUALS(3, cp.y);
|
---|
131 | }
|
---|
132 |
|
---|
133 | /** gfx_coord2_project projects pixel from one rectangle to another */
|
---|
134 | PCUT_TEST(coord2_project)
|
---|
135 | {
|
---|
136 | gfx_coord2_t a, d;
|
---|
137 | gfx_rect_t srect, drect;
|
---|
138 |
|
---|
139 | srect.p0.x = 10;
|
---|
140 | srect.p0.y = 10;
|
---|
141 | srect.p1.x = 20 + 1;
|
---|
142 | srect.p1.y = 20 + 1;
|
---|
143 |
|
---|
144 | drect.p0.x = 100;
|
---|
145 | drect.p0.y = 100;
|
---|
146 | drect.p1.x = 200 + 1;
|
---|
147 | drect.p1.y = 200 + 1;
|
---|
148 |
|
---|
149 | a.x = 10;
|
---|
150 | a.y = 10;
|
---|
151 | gfx_coord2_project(&a, &srect, &drect, &d);
|
---|
152 | PCUT_ASSERT_INT_EQUALS(100, d.x);
|
---|
153 | PCUT_ASSERT_INT_EQUALS(100, d.y);
|
---|
154 |
|
---|
155 | a.x = 15;
|
---|
156 | a.y = 15;
|
---|
157 | gfx_coord2_project(&a, &srect, &drect, &d);
|
---|
158 | PCUT_ASSERT_INT_EQUALS(150, d.x);
|
---|
159 | PCUT_ASSERT_INT_EQUALS(150, d.y);
|
---|
160 |
|
---|
161 | a.x = 12;
|
---|
162 | a.y = 16;
|
---|
163 | gfx_coord2_project(&a, &srect, &drect, &d);
|
---|
164 | PCUT_ASSERT_INT_EQUALS(120, d.x);
|
---|
165 | PCUT_ASSERT_INT_EQUALS(160, d.y);
|
---|
166 |
|
---|
167 | a.x = 20;
|
---|
168 | a.y = 20;
|
---|
169 | gfx_coord2_project(&a, &srect, &drect, &d);
|
---|
170 | PCUT_ASSERT_INT_EQUALS(200, d.x);
|
---|
171 | PCUT_ASSERT_INT_EQUALS(200, d.y);
|
---|
172 | }
|
---|
173 |
|
---|
174 | /** gfx_rect_translate should translate rectangle */
|
---|
175 | PCUT_TEST(rect_translate)
|
---|
176 | {
|
---|
177 | gfx_coord2_t offs;
|
---|
178 | gfx_rect_t srect;
|
---|
179 | gfx_rect_t drect;
|
---|
180 |
|
---|
181 | offs.x = 5;
|
---|
182 | offs.y = 6;
|
---|
183 |
|
---|
184 | srect.p0.x = 10;
|
---|
185 | srect.p0.y = 11;
|
---|
186 | srect.p1.x = 20;
|
---|
187 | srect.p1.y = 22;
|
---|
188 |
|
---|
189 | gfx_rect_translate(&offs, &srect, &drect);
|
---|
190 |
|
---|
191 | PCUT_ASSERT_INT_EQUALS(offs.x + srect.p0.x, drect.p0.x);
|
---|
192 | PCUT_ASSERT_INT_EQUALS(offs.y + srect.p0.y, drect.p0.y);
|
---|
193 | PCUT_ASSERT_INT_EQUALS(offs.x + srect.p1.x, drect.p1.x);
|
---|
194 | PCUT_ASSERT_INT_EQUALS(offs.y + srect.p1.y, drect.p1.y);
|
---|
195 | }
|
---|
196 |
|
---|
197 | /** gfx_rect_rtranslate should reverse-translate rectangle */
|
---|
198 | PCUT_TEST(rect_rtranslate)
|
---|
199 | {
|
---|
200 | gfx_coord2_t offs;
|
---|
201 | gfx_rect_t srect;
|
---|
202 | gfx_rect_t drect;
|
---|
203 |
|
---|
204 | offs.x = 5;
|
---|
205 | offs.y = 6;
|
---|
206 |
|
---|
207 | srect.p0.x = 10;
|
---|
208 | srect.p0.y = 11;
|
---|
209 | srect.p1.x = 20;
|
---|
210 | srect.p1.y = 22;
|
---|
211 |
|
---|
212 | gfx_rect_rtranslate(&offs, &srect, &drect);
|
---|
213 |
|
---|
214 | PCUT_ASSERT_INT_EQUALS(srect.p0.x - offs.x, drect.p0.x);
|
---|
215 | PCUT_ASSERT_INT_EQUALS(srect.p0.y - offs.y, drect.p0.y);
|
---|
216 | PCUT_ASSERT_INT_EQUALS(srect.p1.x - offs.x, drect.p1.x);
|
---|
217 | PCUT_ASSERT_INT_EQUALS(srect.p1.y - offs.y, drect.p1.y);
|
---|
218 | }
|
---|
219 |
|
---|
220 | /** Sorting span with lower start and higher end point results in the same span. */
|
---|
221 | PCUT_TEST(span_points_sort_asc)
|
---|
222 | {
|
---|
223 | gfx_coord_t a, b;
|
---|
224 |
|
---|
225 | gfx_span_points_sort(1, 2, &a, &b);
|
---|
226 | PCUT_ASSERT_INT_EQUALS(1, a);
|
---|
227 | PCUT_ASSERT_INT_EQUALS(2, b);
|
---|
228 | }
|
---|
229 |
|
---|
230 | /** Sorting span with same start and end point results in the same span. */
|
---|
231 | PCUT_TEST(span_points_sort_equal)
|
---|
232 | {
|
---|
233 | gfx_coord_t a, b;
|
---|
234 |
|
---|
235 | gfx_span_points_sort(1, 1, &a, &b);
|
---|
236 | PCUT_ASSERT_INT_EQUALS(1, a);
|
---|
237 | PCUT_ASSERT_INT_EQUALS(1, b);
|
---|
238 | }
|
---|
239 |
|
---|
240 | /** Sorting span with hight start and lower end point results in transposed span. */
|
---|
241 | PCUT_TEST(span_points_sort_desc)
|
---|
242 | {
|
---|
243 | gfx_coord_t a, b;
|
---|
244 |
|
---|
245 | gfx_span_points_sort(1, 0, &a, &b);
|
---|
246 | PCUT_ASSERT_INT_EQUALS(1, a);
|
---|
247 | PCUT_ASSERT_INT_EQUALS(2, b);
|
---|
248 | }
|
---|
249 |
|
---|
250 | /** Rectangle envelope with first rectangle empty should return the second rectangle. */
|
---|
251 | PCUT_TEST(rect_envelope_a_empty)
|
---|
252 | {
|
---|
253 | gfx_rect_t a;
|
---|
254 | gfx_rect_t b;
|
---|
255 | gfx_rect_t e;
|
---|
256 |
|
---|
257 | a.p0.x = 0;
|
---|
258 | a.p0.y = 0;
|
---|
259 | a.p1.x = 0;
|
---|
260 | a.p1.y = 0;
|
---|
261 |
|
---|
262 | b.p0.x = 1;
|
---|
263 | b.p0.y = 2;
|
---|
264 | b.p1.x = 3;
|
---|
265 | b.p1.y = 4;
|
---|
266 |
|
---|
267 | gfx_rect_envelope(&a, &b, &e);
|
---|
268 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
---|
269 | PCUT_ASSERT_INT_EQUALS(2, e.p0.y);
|
---|
270 | PCUT_ASSERT_INT_EQUALS(3, e.p1.x);
|
---|
271 | PCUT_ASSERT_INT_EQUALS(4, e.p1.y);
|
---|
272 | }
|
---|
273 |
|
---|
274 | /** Rectangle envelope with second rectangle empty should return the first rectangle. */
|
---|
275 | PCUT_TEST(rect_envelope_b_empty)
|
---|
276 | {
|
---|
277 | gfx_rect_t a;
|
---|
278 | gfx_rect_t b;
|
---|
279 | gfx_rect_t e;
|
---|
280 |
|
---|
281 | a.p0.x = 1;
|
---|
282 | a.p0.y = 2;
|
---|
283 | a.p1.x = 3;
|
---|
284 | a.p1.y = 4;
|
---|
285 |
|
---|
286 | b.p0.x = 0;
|
---|
287 | b.p0.y = 0;
|
---|
288 | b.p1.x = 0;
|
---|
289 | b.p1.y = 0;
|
---|
290 |
|
---|
291 | gfx_rect_envelope(&a, &b, &e);
|
---|
292 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
---|
293 | PCUT_ASSERT_INT_EQUALS(2, e.p0.y);
|
---|
294 | PCUT_ASSERT_INT_EQUALS(3, e.p1.x);
|
---|
295 | PCUT_ASSERT_INT_EQUALS(4, e.p1.y);
|
---|
296 | }
|
---|
297 |
|
---|
298 | /** Rectangle envelope, a has both coordinates lower than b */
|
---|
299 | PCUT_TEST(rect_envelope_nonempty_a_lt_b)
|
---|
300 | {
|
---|
301 | gfx_rect_t a;
|
---|
302 | gfx_rect_t b;
|
---|
303 | gfx_rect_t e;
|
---|
304 |
|
---|
305 | a.p0.x = 1;
|
---|
306 | a.p0.y = 2;
|
---|
307 | a.p1.x = 3;
|
---|
308 | a.p1.y = 4;
|
---|
309 |
|
---|
310 | b.p0.x = 5;
|
---|
311 | b.p0.y = 6;
|
---|
312 | b.p1.x = 7;
|
---|
313 | b.p1.y = 8;
|
---|
314 |
|
---|
315 | gfx_rect_envelope(&a, &b, &e);
|
---|
316 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
---|
317 | PCUT_ASSERT_INT_EQUALS(2, e.p0.y);
|
---|
318 | PCUT_ASSERT_INT_EQUALS(7, e.p1.x);
|
---|
319 | PCUT_ASSERT_INT_EQUALS(8, e.p1.y);
|
---|
320 | }
|
---|
321 |
|
---|
322 | /** Rectangle envelope, a has both coordinates higher than b */
|
---|
323 | PCUT_TEST(rect_envelope_nonempty_a_gt_b)
|
---|
324 | {
|
---|
325 | gfx_rect_t a;
|
---|
326 | gfx_rect_t b;
|
---|
327 | gfx_rect_t e;
|
---|
328 |
|
---|
329 | a.p0.x = 5;
|
---|
330 | a.p0.y = 6;
|
---|
331 | a.p1.x = 7;
|
---|
332 | a.p1.y = 8;
|
---|
333 |
|
---|
334 | b.p0.x = 1;
|
---|
335 | b.p0.y = 2;
|
---|
336 | b.p1.x = 3;
|
---|
337 | b.p1.y = 4;
|
---|
338 |
|
---|
339 | gfx_rect_envelope(&a, &b, &e);
|
---|
340 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
---|
341 | PCUT_ASSERT_INT_EQUALS(2, e.p0.y);
|
---|
342 | PCUT_ASSERT_INT_EQUALS(7, e.p1.x);
|
---|
343 | PCUT_ASSERT_INT_EQUALS(8, e.p1.y);
|
---|
344 | }
|
---|
345 |
|
---|
346 | /** Rectangle envelope, a is inside b */
|
---|
347 | PCUT_TEST(rect_envelope_nonempty_a_inside_b)
|
---|
348 | {
|
---|
349 | gfx_rect_t a;
|
---|
350 | gfx_rect_t b;
|
---|
351 | gfx_rect_t e;
|
---|
352 |
|
---|
353 | a.p0.x = 1;
|
---|
354 | a.p0.y = 2;
|
---|
355 | a.p1.x = 7;
|
---|
356 | a.p1.y = 8;
|
---|
357 |
|
---|
358 | b.p0.x = 3;
|
---|
359 | b.p0.y = 4;
|
---|
360 | b.p1.x = 5;
|
---|
361 | b.p1.y = 6;
|
---|
362 |
|
---|
363 | gfx_rect_envelope(&a, &b, &e);
|
---|
364 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
---|
365 | PCUT_ASSERT_INT_EQUALS(2, e.p0.y);
|
---|
366 | PCUT_ASSERT_INT_EQUALS(7, e.p1.x);
|
---|
367 | PCUT_ASSERT_INT_EQUALS(8, e.p1.y);
|
---|
368 | }
|
---|
369 |
|
---|
370 | /** Rectangle envelope, b is inside a*/
|
---|
371 | PCUT_TEST(rect_envelope_nonempty_b_inside_a)
|
---|
372 | {
|
---|
373 | gfx_rect_t a;
|
---|
374 | gfx_rect_t b;
|
---|
375 | gfx_rect_t e;
|
---|
376 |
|
---|
377 | a.p0.x = 3;
|
---|
378 | a.p0.y = 4;
|
---|
379 | a.p1.x = 5;
|
---|
380 | a.p1.y = 6;
|
---|
381 |
|
---|
382 | b.p0.x = 1;
|
---|
383 | b.p0.y = 2;
|
---|
384 | b.p1.x = 7;
|
---|
385 | b.p1.y = 8;
|
---|
386 |
|
---|
387 | gfx_rect_envelope(&a, &b, &e);
|
---|
388 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
---|
389 | PCUT_ASSERT_INT_EQUALS(2, e.p0.y);
|
---|
390 | PCUT_ASSERT_INT_EQUALS(7, e.p1.x);
|
---|
391 | PCUT_ASSERT_INT_EQUALS(8, e.p1.y);
|
---|
392 | }
|
---|
393 |
|
---|
394 | /** Rectangle envelope, a and b cross */
|
---|
395 | PCUT_TEST(rect_envelope_nonempty_a_crosses_b)
|
---|
396 | {
|
---|
397 | gfx_rect_t a;
|
---|
398 | gfx_rect_t b;
|
---|
399 | gfx_rect_t e;
|
---|
400 |
|
---|
401 | a.p0.x = 1;
|
---|
402 | a.p0.y = 2;
|
---|
403 | a.p1.x = 4;
|
---|
404 | a.p1.y = 3;
|
---|
405 |
|
---|
406 | b.p0.x = 2;
|
---|
407 | b.p0.y = 1;
|
---|
408 | b.p1.x = 3;
|
---|
409 | b.p1.y = 4;
|
---|
410 |
|
---|
411 | gfx_rect_envelope(&a, &b, &e);
|
---|
412 | PCUT_ASSERT_INT_EQUALS(1, e.p0.x);
|
---|
413 | PCUT_ASSERT_INT_EQUALS(1, e.p0.y);
|
---|
414 | PCUT_ASSERT_INT_EQUALS(4, e.p1.x);
|
---|
415 | PCUT_ASSERT_INT_EQUALS(4, e.p1.y);
|
---|
416 | }
|
---|
417 |
|
---|
418 | /** Clip rectangle with rect completely inside the clipping rectangle */
|
---|
419 | PCUT_TEST(rect_clip_rect_inside)
|
---|
420 | {
|
---|
421 | gfx_rect_t rect;
|
---|
422 | gfx_rect_t clip;
|
---|
423 | gfx_rect_t dest;
|
---|
424 |
|
---|
425 | rect.p0.x = 3;
|
---|
426 | rect.p0.y = 4;
|
---|
427 | rect.p1.x = 5;
|
---|
428 | rect.p1.y = 6;
|
---|
429 |
|
---|
430 | clip.p0.x = 1;
|
---|
431 | clip.p0.y = 2;
|
---|
432 | clip.p1.x = 7;
|
---|
433 | clip.p1.y = 8;
|
---|
434 |
|
---|
435 | gfx_rect_clip(&rect, &clip, &dest);
|
---|
436 | PCUT_ASSERT_INT_EQUALS(3, dest.p0.x);
|
---|
437 | PCUT_ASSERT_INT_EQUALS(4, dest.p0.y);
|
---|
438 | PCUT_ASSERT_INT_EQUALS(5, dest.p1.x);
|
---|
439 | PCUT_ASSERT_INT_EQUALS(6, dest.p1.y);
|
---|
440 | }
|
---|
441 |
|
---|
442 | /** Clip rectangle with rect covering the clipping rectangle */
|
---|
443 | PCUT_TEST(rect_clip_rect_covering)
|
---|
444 | {
|
---|
445 | gfx_rect_t rect;
|
---|
446 | gfx_rect_t clip;
|
---|
447 | gfx_rect_t dest;
|
---|
448 |
|
---|
449 | rect.p0.x = 1;
|
---|
450 | rect.p0.y = 2;
|
---|
451 | rect.p1.x = 7;
|
---|
452 | rect.p1.y = 8;
|
---|
453 |
|
---|
454 | clip.p0.x = 3;
|
---|
455 | clip.p0.y = 4;
|
---|
456 | clip.p1.x = 5;
|
---|
457 | clip.p1.y = 6;
|
---|
458 |
|
---|
459 | gfx_rect_clip(&rect, &clip, &dest);
|
---|
460 | PCUT_ASSERT_INT_EQUALS(3, dest.p0.x);
|
---|
461 | PCUT_ASSERT_INT_EQUALS(4, dest.p0.y);
|
---|
462 | PCUT_ASSERT_INT_EQUALS(5, dest.p1.x);
|
---|
463 | PCUT_ASSERT_INT_EQUALS(6, dest.p1.y);
|
---|
464 | }
|
---|
465 |
|
---|
466 | /** Clip rectangle with rect outside, having lower coordinates */
|
---|
467 | PCUT_TEST(rect_clip_rect_out_ll)
|
---|
468 | {
|
---|
469 | gfx_rect_t rect;
|
---|
470 | gfx_rect_t clip;
|
---|
471 | gfx_rect_t dest;
|
---|
472 |
|
---|
473 | rect.p0.x = 1;
|
---|
474 | rect.p0.y = 2;
|
---|
475 | rect.p1.x = 3;
|
---|
476 | rect.p1.y = 4;
|
---|
477 |
|
---|
478 | clip.p0.x = 5;
|
---|
479 | clip.p0.y = 6;
|
---|
480 | clip.p1.x = 7;
|
---|
481 | clip.p1.y = 8;
|
---|
482 |
|
---|
483 | gfx_rect_clip(&rect, &clip, &dest);
|
---|
484 | PCUT_ASSERT_INT_EQUALS(5, dest.p0.x);
|
---|
485 | PCUT_ASSERT_INT_EQUALS(6, dest.p0.y);
|
---|
486 | PCUT_ASSERT_INT_EQUALS(5, dest.p1.x);
|
---|
487 | PCUT_ASSERT_INT_EQUALS(6, dest.p1.y);
|
---|
488 | }
|
---|
489 |
|
---|
490 | /** Clip rectangle with rect outside, having higher coordinates */
|
---|
491 | PCUT_TEST(rect_clip_rect_out_hh)
|
---|
492 | {
|
---|
493 | gfx_rect_t rect;
|
---|
494 | gfx_rect_t clip;
|
---|
495 | gfx_rect_t dest;
|
---|
496 |
|
---|
497 | rect.p0.x = 5;
|
---|
498 | rect.p0.y = 6;
|
---|
499 | rect.p1.x = 7;
|
---|
500 | rect.p1.y = 8;
|
---|
501 |
|
---|
502 | clip.p0.x = 1;
|
---|
503 | clip.p0.y = 2;
|
---|
504 | clip.p1.x = 3;
|
---|
505 | clip.p1.y = 4;
|
---|
506 |
|
---|
507 | gfx_rect_clip(&rect, &clip, &dest);
|
---|
508 | PCUT_ASSERT_INT_EQUALS(3, dest.p0.x);
|
---|
509 | PCUT_ASSERT_INT_EQUALS(4, dest.p0.y);
|
---|
510 | PCUT_ASSERT_INT_EQUALS(3, dest.p1.x);
|
---|
511 | PCUT_ASSERT_INT_EQUALS(4, dest.p1.y);
|
---|
512 | }
|
---|
513 |
|
---|
514 | /** Clip rectangle with rect partially outside, having lower coordinates */
|
---|
515 | PCUT_TEST(rect_clip_rect_ll)
|
---|
516 | {
|
---|
517 | gfx_rect_t rect;
|
---|
518 | gfx_rect_t clip;
|
---|
519 | gfx_rect_t dest;
|
---|
520 |
|
---|
521 | rect.p0.x = 1;
|
---|
522 | rect.p0.y = 2;
|
---|
523 | rect.p1.x = 5;
|
---|
524 | rect.p1.y = 6;
|
---|
525 |
|
---|
526 | clip.p0.x = 3;
|
---|
527 | clip.p0.y = 4;
|
---|
528 | clip.p1.x = 7;
|
---|
529 | clip.p1.y = 8;
|
---|
530 |
|
---|
531 | gfx_rect_clip(&rect, &clip, &dest);
|
---|
532 | PCUT_ASSERT_INT_EQUALS(3, dest.p0.x);
|
---|
533 | PCUT_ASSERT_INT_EQUALS(4, dest.p0.y);
|
---|
534 | PCUT_ASSERT_INT_EQUALS(5, dest.p1.x);
|
---|
535 | PCUT_ASSERT_INT_EQUALS(6, dest.p1.y);
|
---|
536 | }
|
---|
537 |
|
---|
538 | /** Clip rectangle with rect partially outside, having higher coordinates */
|
---|
539 | PCUT_TEST(rect_clip_rect_hh)
|
---|
540 | {
|
---|
541 | gfx_rect_t rect;
|
---|
542 | gfx_rect_t clip;
|
---|
543 | gfx_rect_t dest;
|
---|
544 |
|
---|
545 | rect.p0.x = 3;
|
---|
546 | rect.p0.y = 4;
|
---|
547 | rect.p1.x = 7;
|
---|
548 | rect.p1.y = 8;
|
---|
549 |
|
---|
550 | clip.p0.x = 1;
|
---|
551 | clip.p0.y = 2;
|
---|
552 | clip.p1.x = 5;
|
---|
553 | clip.p1.y = 6;
|
---|
554 |
|
---|
555 | gfx_rect_clip(&rect, &clip, &dest);
|
---|
556 | PCUT_ASSERT_INT_EQUALS(3, dest.p0.x);
|
---|
557 | PCUT_ASSERT_INT_EQUALS(4, dest.p0.y);
|
---|
558 | PCUT_ASSERT_INT_EQUALS(5, dest.p1.x);
|
---|
559 | PCUT_ASSERT_INT_EQUALS(6, dest.p1.y);
|
---|
560 | }
|
---|
561 |
|
---|
562 | /** Clip rectangle with no clipping rectangle */
|
---|
563 | PCUT_TEST(rect_clip_rect_noclip)
|
---|
564 | {
|
---|
565 | gfx_rect_t rect;
|
---|
566 | gfx_rect_t dest;
|
---|
567 |
|
---|
568 | rect.p0.x = 1;
|
---|
569 | rect.p0.y = 2;
|
---|
570 | rect.p1.x = 3;
|
---|
571 | rect.p1.y = 4;
|
---|
572 |
|
---|
573 | gfx_rect_clip(&rect, NULL, &dest);
|
---|
574 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, dest.p0.x);
|
---|
575 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, dest.p0.y);
|
---|
576 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, dest.p1.x);
|
---|
577 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, dest.p1.y);
|
---|
578 | }
|
---|
579 |
|
---|
580 | /** Sort span points that are already sorted should produde indentical points */
|
---|
581 | PCUT_TEST(rect_points_sort_sorted)
|
---|
582 | {
|
---|
583 | gfx_coord_t s0, s1;
|
---|
584 |
|
---|
585 | gfx_span_points_sort(1, 2, &s0, &s1);
|
---|
586 | PCUT_ASSERT_INT_EQUALS(1, s0);
|
---|
587 | PCUT_ASSERT_INT_EQUALS(2, s1);
|
---|
588 | }
|
---|
589 |
|
---|
590 | /** Sort span points that are reversed should transpose them */
|
---|
591 | PCUT_TEST(rect_points_sort_reversed)
|
---|
592 | {
|
---|
593 | gfx_coord_t s0, s1;
|
---|
594 |
|
---|
595 | gfx_span_points_sort(2, 1, &s0, &s1);
|
---|
596 | PCUT_ASSERT_INT_EQUALS(2, s0);
|
---|
597 | PCUT_ASSERT_INT_EQUALS(3, s1);
|
---|
598 | }
|
---|
599 |
|
---|
600 | /** Rectangle dimensions for straight rectangle are computed correctly */
|
---|
601 | PCUT_TEST(rect_dims_straight)
|
---|
602 | {
|
---|
603 | gfx_rect_t rect;
|
---|
604 | gfx_coord2_t dims;
|
---|
605 |
|
---|
606 | rect.p0.x = 1;
|
---|
607 | rect.p0.y = 10;
|
---|
608 | rect.p1.x = 100;
|
---|
609 | rect.p1.y = 1000;
|
---|
610 |
|
---|
611 | gfx_rect_dims(&rect, &dims);
|
---|
612 |
|
---|
613 | PCUT_ASSERT_INT_EQUALS(99, dims.x);
|
---|
614 | PCUT_ASSERT_INT_EQUALS(990, dims.y);
|
---|
615 | }
|
---|
616 |
|
---|
617 | /** Rectangle dimensions for reversed rectangle are computed correctly */
|
---|
618 | PCUT_TEST(rect_dims_reversed)
|
---|
619 | {
|
---|
620 | gfx_rect_t rect;
|
---|
621 | gfx_coord2_t dims;
|
---|
622 |
|
---|
623 | rect.p0.x = 1000;
|
---|
624 | rect.p0.y = 100;
|
---|
625 | rect.p1.x = 10;
|
---|
626 | rect.p1.y = 1;
|
---|
627 |
|
---|
628 | gfx_rect_dims(&rect, &dims);
|
---|
629 |
|
---|
630 | PCUT_ASSERT_INT_EQUALS(990, dims.x);
|
---|
631 | PCUT_ASSERT_INT_EQUALS(99, dims.y);
|
---|
632 | }
|
---|
633 |
|
---|
634 | /** gfx_rect_is_empty for straight rectangle with zero columns returns true */
|
---|
635 | PCUT_TEST(rect_is_empty_pos_x)
|
---|
636 | {
|
---|
637 | gfx_rect_t rect;
|
---|
638 |
|
---|
639 | rect.p0.x = 1;
|
---|
640 | rect.p0.y = 2;
|
---|
641 | rect.p1.x = 1;
|
---|
642 | rect.p1.y = 3;
|
---|
643 | PCUT_ASSERT_TRUE(gfx_rect_is_empty(&rect));
|
---|
644 | }
|
---|
645 |
|
---|
646 | /** gfx_rect_is_empty for straight rectangle with zero rows returns true */
|
---|
647 | PCUT_TEST(rect_is_empty_pos_y)
|
---|
648 | {
|
---|
649 | gfx_rect_t rect;
|
---|
650 |
|
---|
651 | rect.p0.x = 1;
|
---|
652 | rect.p0.y = 2;
|
---|
653 | rect.p1.x = 2;
|
---|
654 | rect.p1.y = 2;
|
---|
655 | PCUT_ASSERT_TRUE(gfx_rect_is_empty(&rect));
|
---|
656 | }
|
---|
657 |
|
---|
658 | /** gfx_rect_is_empty for straight non-empty rectangle returns false */
|
---|
659 | PCUT_TEST(rect_is_empty_neg)
|
---|
660 | {
|
---|
661 | gfx_rect_t rect;
|
---|
662 |
|
---|
663 | rect.p0.x = 1;
|
---|
664 | rect.p0.y = 2;
|
---|
665 | rect.p1.x = 2;
|
---|
666 | rect.p1.y = 3;
|
---|
667 | PCUT_ASSERT_FALSE(gfx_rect_is_empty(&rect));
|
---|
668 | }
|
---|
669 |
|
---|
670 | /** gfx_rect_is_empty for reverse non-empty rectangle returns false */
|
---|
671 | PCUT_TEST(rect_is_empty_reverse_neg)
|
---|
672 | {
|
---|
673 | gfx_rect_t rect;
|
---|
674 |
|
---|
675 | rect.p0.x = 1;
|
---|
676 | rect.p0.y = 2;
|
---|
677 | rect.p1.x = 0;
|
---|
678 | rect.p1.y = 1;
|
---|
679 | PCUT_ASSERT_FALSE(gfx_rect_is_empty(&rect));
|
---|
680 | }
|
---|
681 |
|
---|
682 | /** gfx_rect_is_incident for neighboring rectangles returns false */
|
---|
683 | PCUT_TEST(rect_is_incident_neighbor)
|
---|
684 | {
|
---|
685 | gfx_rect_t a;
|
---|
686 | gfx_rect_t b;
|
---|
687 |
|
---|
688 | a.p0.x = 1;
|
---|
689 | a.p0.y = 2;
|
---|
690 | a.p1.x = 3;
|
---|
691 | a.p1.y = 4;
|
---|
692 |
|
---|
693 | b.p0.x = 3;
|
---|
694 | b.p0.y = 2;
|
---|
695 | b.p1.x = 5;
|
---|
696 | b.p1.y = 6;
|
---|
697 |
|
---|
698 | PCUT_ASSERT_FALSE(gfx_rect_is_incident(&a, &b));
|
---|
699 | }
|
---|
700 |
|
---|
701 | /** gfx_rect_is_incident for a inside b returns true */
|
---|
702 | PCUT_TEST(rect_is_incident_a_inside_b)
|
---|
703 | {
|
---|
704 | gfx_rect_t a;
|
---|
705 | gfx_rect_t b;
|
---|
706 |
|
---|
707 | a.p0.x = 2;
|
---|
708 | a.p0.y = 3;
|
---|
709 | a.p1.x = 4;
|
---|
710 | a.p1.y = 5;
|
---|
711 |
|
---|
712 | b.p0.x = 1;
|
---|
713 | b.p0.y = 2;
|
---|
714 | b.p1.x = 5;
|
---|
715 | b.p1.y = 6;
|
---|
716 |
|
---|
717 | PCUT_ASSERT_TRUE(gfx_rect_is_incident(&a, &b));
|
---|
718 | }
|
---|
719 |
|
---|
720 | /** gfx_rect_is_incident for b inside a returns true */
|
---|
721 | PCUT_TEST(rect_is_incident_b_inside_a)
|
---|
722 | {
|
---|
723 | gfx_rect_t a;
|
---|
724 | gfx_rect_t b;
|
---|
725 |
|
---|
726 | a.p0.x = 1;
|
---|
727 | a.p0.y = 2;
|
---|
728 | a.p1.x = 5;
|
---|
729 | a.p1.y = 6;
|
---|
730 |
|
---|
731 | b.p0.x = 2;
|
---|
732 | b.p0.y = 3;
|
---|
733 | b.p1.x = 4;
|
---|
734 | b.p1.y = 5;
|
---|
735 |
|
---|
736 | PCUT_ASSERT_TRUE(gfx_rect_is_incident(&a, &b));
|
---|
737 | }
|
---|
738 |
|
---|
739 | /** gfx_rect_is_incident for a and b sharing corner returns true */
|
---|
740 | PCUT_TEST(rect_is_incident_corner)
|
---|
741 | {
|
---|
742 | gfx_rect_t a;
|
---|
743 | gfx_rect_t b;
|
---|
744 |
|
---|
745 | a.p0.x = 1;
|
---|
746 | a.p0.y = 2;
|
---|
747 | a.p1.x = 3;
|
---|
748 | a.p1.y = 4;
|
---|
749 |
|
---|
750 | b.p0.x = 2;
|
---|
751 | b.p0.y = 3;
|
---|
752 | b.p1.x = 4;
|
---|
753 | b.p1.y = 5;
|
---|
754 |
|
---|
755 | PCUT_ASSERT_TRUE(gfx_rect_is_incident(&a, &b));
|
---|
756 | }
|
---|
757 |
|
---|
758 | /** gfx_rect_is_incident for a == b returns true */
|
---|
759 | PCUT_TEST(rect_is_incident_same)
|
---|
760 | {
|
---|
761 | gfx_rect_t a;
|
---|
762 | gfx_rect_t b;
|
---|
763 |
|
---|
764 | a.p0.x = 1;
|
---|
765 | a.p0.y = 2;
|
---|
766 | a.p1.x = 3;
|
---|
767 | a.p1.y = 4;
|
---|
768 |
|
---|
769 | b.p0.x = 1;
|
---|
770 | b.p0.y = 2;
|
---|
771 | b.p1.x = 3;
|
---|
772 | b.p1.y = 4;
|
---|
773 |
|
---|
774 | PCUT_ASSERT_TRUE(gfx_rect_is_incident(&a, &b));
|
---|
775 | }
|
---|
776 |
|
---|
777 | /** gfx_pix_inside_rect for */
|
---|
778 | PCUT_TEST(pix_inside_rect)
|
---|
779 | {
|
---|
780 | gfx_coord2_t coord;
|
---|
781 | gfx_rect_t rect;
|
---|
782 |
|
---|
783 | rect.p0.x = 1;
|
---|
784 | rect.p0.y = 2;
|
---|
785 | rect.p1.x = 3;
|
---|
786 | rect.p1.y = 4;
|
---|
787 |
|
---|
788 | coord.x = 0;
|
---|
789 | coord.y = 1;
|
---|
790 | PCUT_ASSERT_FALSE(gfx_pix_inside_rect(&coord, &rect));
|
---|
791 |
|
---|
792 | coord.x = 1;
|
---|
793 | coord.y = 1;
|
---|
794 | PCUT_ASSERT_FALSE(gfx_pix_inside_rect(&coord, &rect));
|
---|
795 |
|
---|
796 | coord.x = 0;
|
---|
797 | coord.y = 2;
|
---|
798 | PCUT_ASSERT_FALSE(gfx_pix_inside_rect(&coord, &rect));
|
---|
799 |
|
---|
800 | coord.x = 1;
|
---|
801 | coord.y = 2;
|
---|
802 | PCUT_ASSERT_TRUE(gfx_pix_inside_rect(&coord, &rect));
|
---|
803 |
|
---|
804 | coord.x = 2;
|
---|
805 | coord.y = 3;
|
---|
806 | PCUT_ASSERT_TRUE(gfx_pix_inside_rect(&coord, &rect));
|
---|
807 |
|
---|
808 | coord.x = 3;
|
---|
809 | coord.y = 3;
|
---|
810 | PCUT_ASSERT_FALSE(gfx_pix_inside_rect(&coord, &rect));
|
---|
811 |
|
---|
812 | coord.x = 2;
|
---|
813 | coord.y = 4;
|
---|
814 | PCUT_ASSERT_FALSE(gfx_pix_inside_rect(&coord, &rect));
|
---|
815 |
|
---|
816 | coord.x = 3;
|
---|
817 | coord.y = 4;
|
---|
818 | PCUT_ASSERT_FALSE(gfx_pix_inside_rect(&coord, &rect));
|
---|
819 | }
|
---|
820 |
|
---|
821 | PCUT_EXPORT(coord);
|
---|