Changeset 6301a24f in mainline for uspace/lib/gfx
- Timestamp:
- 2020-06-05T20:20:06Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8aef01c
- Parents:
- d70e7b7b
- Location:
- uspace/lib/gfx
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfx/include/gfx/coord.h
rd70e7b7b r6301a24f 54 54 extern void gfx_rect_dims(gfx_rect_t *, gfx_coord2_t *); 55 55 extern bool gfx_rect_is_empty(gfx_rect_t *); 56 extern bool gfx_rect_is_incident(gfx_rect_t *, gfx_rect_t *); 56 57 extern bool gfx_pix_inside_rect(gfx_coord2_t *, gfx_rect_t *); 57 58 -
uspace/lib/gfx/src/coord.c
rd70e7b7b r6301a24f 37 37 #include <macros.h> 38 38 #include <stdbool.h> 39 #include <stddef.h> 39 40 40 41 /** Add two vectors. … … 192 193 * If the two rectangles do not intersect, the result will be an empty 193 194 * rectangle (check with gfx_rect_is_empty()). The resulting rectangle 194 * is always sorted. 195 * is always sorted. If @a clip is NULL, no clipping is performed. 195 196 * 196 197 * @param rect Source rectangle 197 * @param clip Clipping rectangle 198 * @param clip Clipping rectangle or @c NULL 198 199 * @param dest Place to store clipped rectangle 199 200 */ … … 201 202 { 202 203 gfx_rect_t srect, sclip; 204 205 if (clip == NULL) { 206 *dest = *rect; 207 return; 208 } 203 209 204 210 gfx_rect_points_sort(rect, &srect); … … 235 241 } 236 242 243 /** Determine if two rectangles share any pixels 244 * 245 * @param a First rectangle 246 * @param b Second rectangle 247 * @return @c true iff rectangles share any pixels 248 */ 249 bool gfx_rect_is_incident(gfx_rect_t *a, gfx_rect_t *b) 250 { 251 gfx_rect_t r; 252 253 gfx_rect_clip(a, b, &r); 254 return !gfx_rect_is_empty(&r); 255 } 256 237 257 /** Get rectangle dimensions. 238 258 * -
uspace/lib/gfx/test/coord.c
rd70e7b7b r6301a24f 560 560 } 561 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 562 580 /** Sort span points that are already sorted should produde indentical points */ 563 581 PCUT_TEST(rect_points_sort_sorted) … … 638 656 } 639 657 640 /** gfx_rect_is_empty for st aright non-empty rectangle returns false */658 /** gfx_rect_is_empty for straight non-empty rectangle returns false */ 641 659 PCUT_TEST(rect_is_empty_neg) 642 660 { … … 662 680 } 663 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 664 777 /** gfx_pix_inside_rect for */ 665 778 PCUT_TEST(pix_inside_rect)
Note:
See TracChangeset
for help on using the changeset viewer.