Changeset fdc8e40 in mainline
- Timestamp:
- 2019-12-13T22:30:30Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3434233
- Parents:
- 4d9c807
- Location:
- uspace/lib/gfx
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfx/include/gfx/coord.h
r4d9c807 rfdc8e40 45 45 gfx_coord_t *); 46 46 extern void gfx_rect_translate(gfx_coord2_t *, gfx_rect_t *, gfx_rect_t *); 47 extern void gfx_rect_rtranslate(gfx_coord2_t *, gfx_rect_t *, gfx_rect_t *); 47 48 extern void gfx_rect_envelope(gfx_rect_t *, gfx_rect_t *, gfx_rect_t *); 49 extern void gfx_rect_clip(gfx_rect_t *, gfx_rect_t *, gfx_rect_t *); 48 50 extern void gfx_rect_points_sort(gfx_rect_t *, gfx_rect_t *); 49 51 extern bool gfx_rect_is_empty(gfx_rect_t *); -
uspace/lib/gfx/src/coord.c
r4d9c807 rfdc8e40 87 87 /** Move (translate) rectangle. 88 88 * 89 * @param trans Translation 89 * @param trans Translation offset 90 90 * @param src Source rectangle 91 91 * @param dest Destination rectangle … … 93 93 void gfx_rect_translate(gfx_coord2_t *trans, gfx_rect_t *src, gfx_rect_t *dest) 94 94 { 95 gfx_coord2_add(trans, &src->p0, &dest->p0); 96 gfx_coord2_add(trans, &src->p1, &dest->p1); 95 gfx_coord2_add(&src->p0, trans, &dest->p0); 96 gfx_coord2_add(&src->p1, trans, &dest->p1); 97 } 98 99 /** Reverse move (translate) rectangle. 100 * 101 * @param trans Translation offset 102 * @param src Source rectangle 103 * @param dest Destination rectangle 104 */ 105 void gfx_rect_rtranslate(gfx_coord2_t *trans, gfx_rect_t *src, gfx_rect_t *dest) 106 { 107 gfx_coord2_subtract(&src->p0, trans, &dest->p0); 108 gfx_coord2_subtract(&src->p1, trans, &dest->p1); 97 109 } 98 110 … … 100 112 * 101 113 * Envelope is the minimal rectangle covering all pixels of both rectangles. 114 * 115 * @param a First rectangle 116 * @param b Second rectangle 117 * @param dest Place to store enveloping rectangle 102 118 */ 103 119 void gfx_rect_envelope(gfx_rect_t *a, gfx_rect_t *b, gfx_rect_t *dest) … … 124 140 dest->p1.x = max(sa.p1.x, sb.p1.x); 125 141 dest->p1.y = max(sa.p1.y, sb.p1.y); 142 } 143 144 /** Compute intersection of two rectangles. 145 * 146 * If the two rectangles do not intersect, the result will be an empty 147 * rectangle (check with gfx_rect_is_empty()). 148 * 149 * @param rect Source rectangle 150 * @param clip Clipping rectangle 151 * @param dest Place to store clipped rectangle 152 */ 153 void gfx_rect_clip(gfx_rect_t *rect, gfx_rect_t *clip, gfx_rect_t *dest) 154 { 155 gfx_rect_t srect, sclip; 156 157 gfx_rect_points_sort(rect, &srect); 158 gfx_rect_points_sort(clip, &sclip); 159 160 dest->p0.x = min(max(srect.p0.x, sclip.p0.x), sclip.p1.x); 161 dest->p0.y = min(max(srect.p0.y, sclip.p0.y), sclip.p1.y); 162 dest->p1.x = max(sclip.p0.x, min(srect.p1.x, sclip.p1.x)); 163 dest->p1.y = max(sclip.p0.y, min(srect.p1.y, sclip.p1.y)); 126 164 } 127 165 -
uspace/lib/gfx/test/coord.c
r4d9c807 rfdc8e40 34 34 PCUT_TEST_SUITE(coord); 35 35 36 extern void gfx_coord2_add(gfx_coord2_t *, gfx_coord2_t *, gfx_coord2_t *);37 extern void gfx_coord2_subtract(gfx_coord2_t *, gfx_coord2_t *, gfx_coord2_t *);38 extern void gfx_rect_translate(gfx_coord2_t *, gfx_rect_t *, gfx_rect_t *);39 40 36 /** gfx_coord2_add should add two coordinate vectors */ 41 37 PCUT_TEST(coord2_add) … … 51 47 gfx_coord2_add(&a, &b, &d); 52 48 53 PCUT_ASSERT_ EQUALS(a.x + b.x, d.x);54 PCUT_ASSERT_ EQUALS(a.y + b.y, d.y);49 PCUT_ASSERT_INT_EQUALS(a.x + b.x, d.x); 50 PCUT_ASSERT_INT_EQUALS(a.y + b.y, d.y); 55 51 } 56 52 … … 68 64 gfx_coord2_subtract(&a, &b, &d); 69 65 70 PCUT_ASSERT_ EQUALS(a.x - b.x, d.x);71 PCUT_ASSERT_ EQUALS(a.y - b.y, d.y);66 PCUT_ASSERT_INT_EQUALS(a.x - b.x, d.x); 67 PCUT_ASSERT_INT_EQUALS(a.y - b.y, d.y); 72 68 } 73 69 … … 89 85 gfx_rect_translate(&offs, &srect, &drect); 90 86 91 PCUT_ASSERT_EQUALS(offs.x + srect.p0.x, drect.p0.x); 92 PCUT_ASSERT_EQUALS(offs.y + srect.p0.y, drect.p0.y); 93 PCUT_ASSERT_EQUALS(offs.x + srect.p1.x, drect.p1.x); 94 PCUT_ASSERT_EQUALS(offs.y + srect.p1.y, drect.p1.y); 87 PCUT_ASSERT_INT_EQUALS(offs.x + srect.p0.x, drect.p0.x); 88 PCUT_ASSERT_INT_EQUALS(offs.y + srect.p0.y, drect.p0.y); 89 PCUT_ASSERT_INT_EQUALS(offs.x + srect.p1.x, drect.p1.x); 90 PCUT_ASSERT_INT_EQUALS(offs.y + srect.p1.y, drect.p1.y); 91 } 92 93 /** gfx_rect_rtranslate should reverse-translate rectangle */ 94 PCUT_TEST(rect_rtranslate) 95 { 96 gfx_coord2_t offs; 97 gfx_rect_t srect; 98 gfx_rect_t drect; 99 100 offs.x = 5; 101 offs.y = 6; 102 103 srect.p0.x = 10; 104 srect.p0.y = 11; 105 srect.p1.x = 20; 106 srect.p1.y = 22; 107 108 gfx_rect_rtranslate(&offs, &srect, &drect); 109 110 PCUT_ASSERT_INT_EQUALS(srect.p0.x - offs.x, drect.p0.x); 111 PCUT_ASSERT_INT_EQUALS(srect.p0.y - offs.y, drect.p0.y); 112 PCUT_ASSERT_INT_EQUALS(srect.p1.x - offs.x, drect.p1.x); 113 PCUT_ASSERT_INT_EQUALS(srect.p1.y - offs.y, drect.p1.y); 95 114 } 96 115 … … 101 120 102 121 gfx_span_points_sort(1, 2, &a, &b); 103 PCUT_ASSERT_ EQUALS(1, a);104 PCUT_ASSERT_ EQUALS(2, b);122 PCUT_ASSERT_INT_EQUALS(1, a); 123 PCUT_ASSERT_INT_EQUALS(2, b); 105 124 } 106 125 … … 111 130 112 131 gfx_span_points_sort(1, 1, &a, &b); 113 PCUT_ASSERT_ EQUALS(1, a);114 PCUT_ASSERT_ EQUALS(1, b);132 PCUT_ASSERT_INT_EQUALS(1, a); 133 PCUT_ASSERT_INT_EQUALS(1, b); 115 134 } 116 135 … … 121 140 122 141 gfx_span_points_sort(1, 0, &a, &b); 123 PCUT_ASSERT_ EQUALS(1, a);124 PCUT_ASSERT_ EQUALS(2, b);142 PCUT_ASSERT_INT_EQUALS(1, a); 143 PCUT_ASSERT_INT_EQUALS(2, b); 125 144 } 126 145 … … 143 162 144 163 gfx_rect_envelope(&a, &b, &e); 145 PCUT_ASSERT_ EQUALS(1, e.p0.x);146 PCUT_ASSERT_ EQUALS(2, e.p0.y);147 PCUT_ASSERT_ EQUALS(3, e.p1.x);148 PCUT_ASSERT_ EQUALS(4, e.p1.y);164 PCUT_ASSERT_INT_EQUALS(1, e.p0.x); 165 PCUT_ASSERT_INT_EQUALS(2, e.p0.y); 166 PCUT_ASSERT_INT_EQUALS(3, e.p1.x); 167 PCUT_ASSERT_INT_EQUALS(4, e.p1.y); 149 168 } 150 169 … … 167 186 168 187 gfx_rect_envelope(&a, &b, &e); 169 PCUT_ASSERT_ EQUALS(1, e.p0.x);170 PCUT_ASSERT_ EQUALS(2, e.p0.y);171 PCUT_ASSERT_ EQUALS(3, e.p1.x);172 PCUT_ASSERT_ EQUALS(4, e.p1.y);188 PCUT_ASSERT_INT_EQUALS(1, e.p0.x); 189 PCUT_ASSERT_INT_EQUALS(2, e.p0.y); 190 PCUT_ASSERT_INT_EQUALS(3, e.p1.x); 191 PCUT_ASSERT_INT_EQUALS(4, e.p1.y); 173 192 } 174 193 … … 191 210 192 211 gfx_rect_envelope(&a, &b, &e); 193 PCUT_ASSERT_ EQUALS(1, e.p0.x);194 PCUT_ASSERT_ EQUALS(2, e.p0.y);195 PCUT_ASSERT_ EQUALS(7, e.p1.x);196 PCUT_ASSERT_ EQUALS(8, e.p1.y);212 PCUT_ASSERT_INT_EQUALS(1, e.p0.x); 213 PCUT_ASSERT_INT_EQUALS(2, e.p0.y); 214 PCUT_ASSERT_INT_EQUALS(7, e.p1.x); 215 PCUT_ASSERT_INT_EQUALS(8, e.p1.y); 197 216 } 198 217 … … 215 234 216 235 gfx_rect_envelope(&a, &b, &e); 217 PCUT_ASSERT_ EQUALS(1, e.p0.x);218 PCUT_ASSERT_ EQUALS(2, e.p0.y);219 PCUT_ASSERT_ EQUALS(7, e.p1.x);220 PCUT_ASSERT_ EQUALS(8, e.p1.y);236 PCUT_ASSERT_INT_EQUALS(1, e.p0.x); 237 PCUT_ASSERT_INT_EQUALS(2, e.p0.y); 238 PCUT_ASSERT_INT_EQUALS(7, e.p1.x); 239 PCUT_ASSERT_INT_EQUALS(8, e.p1.y); 221 240 } 222 241 … … 239 258 240 259 gfx_rect_envelope(&a, &b, &e); 241 PCUT_ASSERT_ EQUALS(1, e.p0.x);242 PCUT_ASSERT_ EQUALS(2, e.p0.y);243 PCUT_ASSERT_ EQUALS(7, e.p1.x);244 PCUT_ASSERT_ EQUALS(8, e.p1.y);260 PCUT_ASSERT_INT_EQUALS(1, e.p0.x); 261 PCUT_ASSERT_INT_EQUALS(2, e.p0.y); 262 PCUT_ASSERT_INT_EQUALS(7, e.p1.x); 263 PCUT_ASSERT_INT_EQUALS(8, e.p1.y); 245 264 } 246 265 … … 263 282 264 283 gfx_rect_envelope(&a, &b, &e); 265 PCUT_ASSERT_ EQUALS(1, e.p0.x);266 PCUT_ASSERT_ EQUALS(2, e.p0.y);267 PCUT_ASSERT_ EQUALS(7, e.p1.x);268 PCUT_ASSERT_ EQUALS(8, e.p1.y);284 PCUT_ASSERT_INT_EQUALS(1, e.p0.x); 285 PCUT_ASSERT_INT_EQUALS(2, e.p0.y); 286 PCUT_ASSERT_INT_EQUALS(7, e.p1.x); 287 PCUT_ASSERT_INT_EQUALS(8, e.p1.y); 269 288 } 270 289 … … 287 306 288 307 gfx_rect_envelope(&a, &b, &e); 289 PCUT_ASSERT_EQUALS(1, e.p0.x); 290 PCUT_ASSERT_EQUALS(1, e.p0.y); 291 PCUT_ASSERT_EQUALS(4, e.p1.x); 292 PCUT_ASSERT_EQUALS(4, e.p1.y); 308 PCUT_ASSERT_INT_EQUALS(1, e.p0.x); 309 PCUT_ASSERT_INT_EQUALS(1, e.p0.y); 310 PCUT_ASSERT_INT_EQUALS(4, e.p1.x); 311 PCUT_ASSERT_INT_EQUALS(4, e.p1.y); 312 } 313 314 /** Clip rectangle with rect completely inside the clipping rectangle */ 315 PCUT_TEST(rect_clip_rect_inside) 316 { 317 gfx_rect_t rect; 318 gfx_rect_t clip; 319 gfx_rect_t dest; 320 321 rect.p0.x = 3; 322 rect.p0.y = 4; 323 rect.p1.x = 5; 324 rect.p1.y = 6; 325 326 clip.p0.x = 1; 327 clip.p0.y = 2; 328 clip.p1.x = 7; 329 clip.p1.y = 8; 330 331 gfx_rect_clip(&rect, &clip, &dest); 332 PCUT_ASSERT_INT_EQUALS(3, dest.p0.x); 333 PCUT_ASSERT_INT_EQUALS(4, dest.p0.y); 334 PCUT_ASSERT_INT_EQUALS(5, dest.p1.x); 335 PCUT_ASSERT_INT_EQUALS(6, dest.p1.y); 336 } 337 338 /** Clip rectangle with rect covering the clipping rectangle */ 339 PCUT_TEST(rect_clip_rect_covering) 340 { 341 gfx_rect_t rect; 342 gfx_rect_t clip; 343 gfx_rect_t dest; 344 345 rect.p0.x = 1; 346 rect.p0.y = 2; 347 rect.p1.x = 7; 348 rect.p1.y = 8; 349 350 clip.p0.x = 3; 351 clip.p0.y = 4; 352 clip.p1.x = 5; 353 clip.p1.y = 6; 354 355 gfx_rect_clip(&rect, &clip, &dest); 356 PCUT_ASSERT_INT_EQUALS(3, dest.p0.x); 357 PCUT_ASSERT_INT_EQUALS(4, dest.p0.y); 358 PCUT_ASSERT_INT_EQUALS(5, dest.p1.x); 359 PCUT_ASSERT_INT_EQUALS(6, dest.p1.y); 360 } 361 362 /** Clip rectangle with rect outside, having lower coordinates */ 363 PCUT_TEST(rect_clip_rect_out_ll) 364 { 365 gfx_rect_t rect; 366 gfx_rect_t clip; 367 gfx_rect_t dest; 368 369 rect.p0.x = 1; 370 rect.p0.y = 2; 371 rect.p1.x = 3; 372 rect.p1.y = 4; 373 374 clip.p0.x = 5; 375 clip.p0.y = 6; 376 clip.p1.x = 7; 377 clip.p1.y = 8; 378 379 gfx_rect_clip(&rect, &clip, &dest); 380 PCUT_ASSERT_INT_EQUALS(5, dest.p0.x); 381 PCUT_ASSERT_INT_EQUALS(6, dest.p0.y); 382 PCUT_ASSERT_INT_EQUALS(5, dest.p1.x); 383 PCUT_ASSERT_INT_EQUALS(6, dest.p1.y); 384 } 385 386 /** Clip rectangle with rect outside, having higher coordinates */ 387 PCUT_TEST(rect_clip_rect_out_hh) 388 { 389 gfx_rect_t rect; 390 gfx_rect_t clip; 391 gfx_rect_t dest; 392 393 rect.p0.x = 5; 394 rect.p0.y = 6; 395 rect.p1.x = 7; 396 rect.p1.y = 8; 397 398 clip.p0.x = 1; 399 clip.p0.y = 2; 400 clip.p1.x = 3; 401 clip.p1.y = 4; 402 403 gfx_rect_clip(&rect, &clip, &dest); 404 PCUT_ASSERT_INT_EQUALS(3, dest.p0.x); 405 PCUT_ASSERT_INT_EQUALS(4, dest.p0.y); 406 PCUT_ASSERT_INT_EQUALS(3, dest.p1.x); 407 PCUT_ASSERT_INT_EQUALS(4, dest.p1.y); 408 } 409 410 /** Clip rectangle with rect partially outside, having lower coordinates */ 411 PCUT_TEST(rect_clip_rect_ll) 412 { 413 gfx_rect_t rect; 414 gfx_rect_t clip; 415 gfx_rect_t dest; 416 417 rect.p0.x = 1; 418 rect.p0.y = 2; 419 rect.p1.x = 5; 420 rect.p1.y = 6; 421 422 clip.p0.x = 3; 423 clip.p0.y = 4; 424 clip.p1.x = 7; 425 clip.p1.y = 8; 426 427 gfx_rect_clip(&rect, &clip, &dest); 428 PCUT_ASSERT_INT_EQUALS(3, dest.p0.x); 429 PCUT_ASSERT_INT_EQUALS(4, dest.p0.y); 430 PCUT_ASSERT_INT_EQUALS(5, dest.p1.x); 431 PCUT_ASSERT_INT_EQUALS(6, dest.p1.y); 432 } 433 434 /** Clip rectangle with rect partially outside, having higher coordinates */ 435 PCUT_TEST(rect_clip_rect_hh) 436 { 437 gfx_rect_t rect; 438 gfx_rect_t clip; 439 gfx_rect_t dest; 440 441 rect.p0.x = 3; 442 rect.p0.y = 4; 443 rect.p1.x = 7; 444 rect.p1.y = 8; 445 446 clip.p0.x = 1; 447 clip.p0.y = 2; 448 clip.p1.x = 5; 449 clip.p1.y = 6; 450 451 gfx_rect_clip(&rect, &clip, &dest); 452 PCUT_ASSERT_INT_EQUALS(3, dest.p0.x); 453 PCUT_ASSERT_INT_EQUALS(4, dest.p0.y); 454 PCUT_ASSERT_INT_EQUALS(5, dest.p1.x); 455 PCUT_ASSERT_INT_EQUALS(6, dest.p1.y); 293 456 } 294 457 … … 299 462 300 463 gfx_span_points_sort(1, 2, &s0, &s1); 301 PCUT_ASSERT_ EQUALS(1, s0);302 PCUT_ASSERT_ EQUALS(2, s1);464 PCUT_ASSERT_INT_EQUALS(1, s0); 465 PCUT_ASSERT_INT_EQUALS(2, s1); 303 466 } 304 467 … … 309 472 310 473 gfx_span_points_sort(2, 1, &s0, &s1); 311 PCUT_ASSERT_ EQUALS(2, s0);312 PCUT_ASSERT_ EQUALS(3, s1);474 PCUT_ASSERT_INT_EQUALS(2, s0); 475 PCUT_ASSERT_INT_EQUALS(3, s1); 313 476 } 314 477
Note:
See TracChangeset
for help on using the changeset viewer.