Skip to content

Add bitmap collision detection unit tests#158

Open
222448082Ashen wants to merge 2 commits intothoth-tech:mainfrom
222448082Ashen:unit-test/physics
Open

Add bitmap collision detection unit tests#158
222448082Ashen wants to merge 2 commits intothoth-tech:mainfrom
222448082Ashen:unit-test/physics

Conversation

@222448082Ashen
Copy link
Copy Markdown

@222448082Ashen 222448082Ashen commented Mar 28, 2026

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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as
    expected)
  • Documentation (update or new)

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

  • Tested with sktest
  • Tested with skunit_tests

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have requested a review from ... on the Pull Request

222448082Ashen and others added 2 commits March 28, 2026 14:01
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.
Copy link
Copy Markdown

@kyriesk kyriesk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants