Changeset 266ec54 in mainline for uspace/lib/gfx
- Timestamp:
- 2020-11-28T23:06:31Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- db3c6795
- Parents:
- 554a5f1
- git-author:
- Jiri Svoboda <jiri@…> (2020-11-27 22:30:28)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-11-28 23:06:31)
- Location:
- uspace/lib/gfx
- Files:
-
- 3 edited
-
include/gfx/coord.h (modified) (1 diff)
-
src/coord.c (modified) (1 diff)
-
test/coord.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfx/include/gfx/coord.h
r554a5f1 r266ec54 52 52 extern void gfx_rect_envelope(gfx_rect_t *, gfx_rect_t *, gfx_rect_t *); 53 53 extern void gfx_rect_clip(gfx_rect_t *, gfx_rect_t *, gfx_rect_t *); 54 extern void gfx_rect_ctr_on_rect(gfx_rect_t *, gfx_rect_t *, gfx_rect_t *); 54 55 extern void gfx_rect_points_sort(gfx_rect_t *, gfx_rect_t *); 55 56 extern void gfx_rect_dims(gfx_rect_t *, gfx_coord2_t *); -
uspace/lib/gfx/src/coord.c
r554a5f1 r266ec54 238 238 } 239 239 240 /** Center rectangle on rectangle. 241 * 242 * Translate rectangle @a a so that its center coincides with the 243 * center of rectangle @a b, saving the result in @a dest. 244 * 245 * @param a Rectnagle to translate 246 * @param b Rectangle on which to center 247 * @param dest Place to store resulting rectangle 248 */ 249 void gfx_rect_ctr_on_rect(gfx_rect_t *a, gfx_rect_t *b, gfx_rect_t *dest) 250 { 251 gfx_coord2_t adim; 252 gfx_coord2_t bdim; 253 254 gfx_rect_dims(a, &adim); 255 gfx_rect_dims(b, &bdim); 256 257 dest->p0.x = b->p0.x + bdim.x / 2 - adim.x / 2; 258 dest->p0.y = b->p0.y + bdim.y / 2 - adim.y / 2; 259 260 dest->p1.x = dest->p0.x + adim.x; 261 dest->p1.y = dest->p0.y + adim.y; 262 } 263 240 264 /** Sort points of a rectangle. 241 265 * -
uspace/lib/gfx/test/coord.c
r554a5f1 r266ec54 597 597 } 598 598 599 /** Center rectangle on rectangle */ 600 PCUT_TEST(rect_ctr_on_rect) 601 { 602 gfx_rect_t a; 603 gfx_rect_t b; 604 gfx_rect_t dest; 605 606 /* Dimensions: 20 x 20 */ 607 b.p0.x = 10; 608 b.p0.y = 20; 609 b.p1.x = 30; 610 b.p1.y = 40; 611 612 /* Dimensions: 20 x 20 */ 613 a.p0.x = 100; 614 a.p0.y = 200; 615 a.p1.x = 120; 616 a.p1.y = 220; 617 618 /* Centering rectangle of same size should give us the same rectangle */ 619 gfx_rect_ctr_on_rect(&a, &b, &dest); 620 PCUT_ASSERT_INT_EQUALS(b.p0.x, dest.p0.x); 621 PCUT_ASSERT_INT_EQUALS(b.p0.y, dest.p0.y); 622 PCUT_ASSERT_INT_EQUALS(b.p1.x, dest.p1.x); 623 PCUT_ASSERT_INT_EQUALS(b.p1.y, dest.p1.y); 624 625 /* Dimensions: 10 x 10 */ 626 a.p0.x = 100; 627 a.p0.y = 200; 628 a.p1.x = 110; 629 a.p1.y = 210; 630 631 gfx_rect_ctr_on_rect(&a, &b, &dest); 632 PCUT_ASSERT_INT_EQUALS(15, dest.p0.x); 633 PCUT_ASSERT_INT_EQUALS(25, dest.p0.y); 634 PCUT_ASSERT_INT_EQUALS(25, dest.p1.x); 635 PCUT_ASSERT_INT_EQUALS(35, dest.p1.y); 636 } 637 599 638 /** Sort span points that are already sorted should produde indentical points */ 600 639 PCUT_TEST(rect_points_sort_sorted)
Note:
See TracChangeset
for help on using the changeset viewer.
