Repository navigation
test(collision): count the pairs a full table's merge drops - #360
Merged
Merged
Conversation
siracozmen01
commented
Nov 5, 2026
siracozmen01
left a comment
Collaborator
Author
There was a problem hiding this comment.
Review at 2504388: no change needed. I read the code; I did not run it. Checks were still pending when I read them.
Collection drops and merge drops. src/broadphase.c at this head:
pairsDroppedis reset at the top ofm2UpdatePairs(line 112).- The collection counts a drop only once
collectedreachespairCapacity(192 here, lines 176-188). - The merge counts a drop only once
outCountreachespairCapacity(lines 240-247).
What each step does:
- Step 1. All 24 shapes are in the moved list. Each pair is collected once, by its lower slot, so 276 candidates are met. The 84 past 192 are dropped at collection. Nothing is kept from before, so the merge drops nothing.
- Step 2. Nothing moved, so
movedCount == 0and the function returns at line 113 after the reset. That gives 0. - Step 3, the teleport. Only the teleported disc is in the moved list. Its fat box meets the 23 others, which have not moved, so the skip at line 157 does not apply and it collects 23 candidates. 23 is far below 192, so the collection cannot drop. Every drop in this step comes from the merge, so the test does separate the two paths.
The bound. The kept list (lines 200-210) drops every pair that touches a moved shape. If x of the teleported disc's pairs were in the table, the merge sees 192 - x kept pairs plus 23 distinct new ones, and drops exactly 23 - x.
- x can be anything from 0 to 23, so
1 <= drops <= 23holds for any x of 22 or less, and x = 23 cannot occur here. - If the slots follow creation order, the disc is slot 23 and collects nothing of its own in step 1. Its pairs come in as (k, 23), collected by slot k in slot order. The first 192 candidates run out during slot 10's query: slots 0 to 9 give 185, and slot 10 adds 7 of its 13 in tree order. So x is 10 or 11 and the count is 12 or 13.
> 0 && <= 23is a correct bound, not a tight one. It still fails the two mutants you listed: an uncounted merge gives 0, and a merge counted twice gives over 23. Pinning 12 or 13 would pin the tree's query order, so the looser bound is the better choice.
The m2Joint_GetLocalAxisA @return line now states the misuse count, matching the file comment and what #358 tests.
The body has Problem, Change and Verification, and has no column-0 word( or type(scope): line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The pair table's merge overflow in
m2UpdatePairsis reachable from the public API, and no test takes it. It happens when pairs kept from earlier steps plus new candidates run past the table. Its drops are counted inm2Counters.pairsDropped, but only the collection's drop is tested, so a change that lost the merge's pairs silently would pass every suite.m2Joint_GetLocalAxisA's@returnalso leaves out the misuse its refusals count (#359).Change
test/test_broadphase.cgainsTestFullTableMergeIsCounted. The world has no gravity and 24 dynamic discs on one spot with every motion lock set. They want 276 pairs, and a world of 24 shapes keeps 192.include/maul2d/joint.h:m2Joint_GetLocalAxisA's@returnsays that another joint type or a stale id reads zero and counts one misuse, as test(joints): read what a joint's kind does not carry #358 tests.No result changes: the code is as it was.
Verification
test_broadphasepasses.test_broadphase:TestFullPairTableIsCountedtools/check.sh changedpasses, the documentation check included. The changed files compile clean with gcc-14 and clang-20 under the strict flags.test_goldenprints the 13 lines oftest/hashes.txtunchanged in the scalar (linux-clang-20-asan) and AVX2 (linux-clang-20) presets.Closes #359