Skip to content

Add collision detection algorithms#14501

Open
as567-code wants to merge 3 commits intoTheAlgorithms:masterfrom
as567-code:add-collision-detection
Open

Add collision detection algorithms#14501
as567-code wants to merge 3 commits intoTheAlgorithms:masterfrom
as567-code:add-collision-detection

Conversation

@as567-code
Copy link
Copy Markdown

Describe your change:

Added 2D collision detection algorithms to the physics/ directory including:

  • AABB collision - Axis-Aligned Bounding Box intersection test
  • Circle-circle collision - Distance-based circle overlap detection
  • Circle-AABB collision - Hybrid circle/rectangle intersection
  • Point-in-rectangle - Point containment test for rectangles
  • Point-in-circle - Point containment test for circles
  • Batch collision detection - Detect all pairwise collisions among mixed objects

All functions include type hints, input validation, and comprehensive doctests (37 tests total, all passing).

Fixes #12569

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.

Implements AABB, circle, circle-AABB, point-in-rectangle, and
point-in-circle collision detection with comprehensive doctests.

Fixes TheAlgorithms#12569
@algorithms-keeper algorithms-keeper bot added the require descriptive names This PR needs descriptive function and/or variable names label Apr 4, 2026
Copy link
Copy Markdown

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.



def is_circle_aabb_collision(
cx: float, cy: float, r: float,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please provide descriptive name for the parameter: r


def is_point_in_circle(
px: float, py: float,
cx: float, cy: float, r: float,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please provide descriptive name for the parameter: r

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Apr 4, 2026
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Apr 4, 2026
Address review feedback from algorithms-keeper: use descriptive
parameter name 'radius' instead of 'r' in is_circle_aabb_collision
and is_point_in_circle functions.
@algorithms-keeper algorithms-keeper bot removed the require descriptive names This PR needs descriptive function and/or variable names label Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a collision detection algorithm

1 participant