Add bitmap collision detection unit tests#158
Add bitmap collision detection unit tests#158222448082Ashen wants to merge 2 commits intothoth-tech:mainfrom
Conversation
Extend unit_test_bitmap.cpp with comprehensive collision tests. Adds test cases for point, rectangle, and circle collisions as well as bitmap-to-bitmap collisions, creating small bitmaps with specific opaque/transparent pixels, calling setup_collision_mask, and verifying collision functions (bitmap_point_collision, bitmap_rectangle_collision, bitmap_circle_collision, bitmap_collision) across offsets and edge cases.
kyriesk
left a comment
There was a problem hiding this comment.
Positive Aspects
The unit tests for bitmap functionality are thorough, covering creation, freeing, and a wide range of collision scenarios (point, rectangle, circle, and bitmap-to-bitmap). This level of coverage is excellent for ensuring the reliability of the graphics subsystem.
Areas for Improvement
Failing Collision Tests
Several collision-related tests are currently failing:
- Bitmap-to-bitmap collision:
The test expects no collision when bounding boxes overlap but opaque pixels do not. However, bitmap_collision(bmp2, 0, 0, bmp3, 0, 0) returns true instead of false. - Point collision:
The test expects no collision for transparent pixels, but bitmap_point_collision returns true for points that should be transparent. - Rectangle and circle collisions:
The test expects no collision when only transparent regions overlap, but the collision function returns true.
The test expects a collision for a small circle overlapping an opaque pixel, but the function returns false.
Suggested Action:
Please review the implementation of the collision detection functions (bitmap_collision, bitmap_point_collision, bitmap_rectangle_collision, bitmap_circle_collision). It appears that the current logic may not be correctly distinguishing between opaque and transparent pixels, or may be using bounding box checks instead of pixel-perfect checks. Pay special attention to how alpha values are handled and ensure that only opaque pixels are considered for collisions.
Test Data:
The tests rely on specific pixel values and transparency. Ensure that the bitmap creation and pixel drawing functions are correctly setting alpha values, and that the collision mask setup is working as intended.
Extend unit_test_bitmap.cpp with comprehensive collision tests. Adds test cases for point, rectangle, and circle collisions as well as bitmap-to-bitmap collisions, creating small bitmaps with specific opaque/transparent pixels, calling setup_collision_mask, and verifying collision functions (bitmap_point_collision, bitmap_rectangle_collision, bitmap_circle_collision, bitmap_collision) across offsets and edge cases.
Description
Please include a summary of the change and which issue is fixed. Please also include relevant
motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
Type of change
Please delete options that are not relevant.
expected)
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can
reproduce. Please also list any relevant details for your test configuration
Testing Checklist
Checklist