Repository navigation
docs(query): say m2Shape_GetClosestPoint returns an inside point as is - #354
Merged
Merged
Conversation
siracozmen01
commented
Nov 5, 2026
siracozmen01
left a comment
Collaborator
Author
There was a problem hiding this comment.
Review at 42c914d: ready. No findings. Read, not run.
The words against ShapeGetClosestPointWorker (src/shape.c:798-825):
- The query point goes to the body frame in float, and
m2ShapeDistancemeasures it against the core. Ifd.distance - target.radius <= 0.0f, it returnspoint, the caller's ownm2Pos2, untouched. So "comes back as it is" is exact, bit for bit, for any body position or rotation, not just in the test's unrotated frame. - "Or within its radius" is the
- target.radiusin that test. A point in a rounded shape's skin, as in your capsule case, takes the same branch and comes back unchanged. It is not moved to the skin's outer surface. - Otherwise it returns
pointA + radius * normal, the surface radius included, rotated back and added to the body position in double. That is the near-miss case.
Two edges, neither a reason to change the words:
- A point exactly on the surface takes the inside branch and returns itself, which is also its nearest surface point.
- Whether a point within float rounding of the surface counts as inside depends on the float conversion of
rel. The two answers differ by at most that rounding. m2Shape_TestPointcounts a point within 0.005 outside as touching, while this query projects it. The header does not tie the two together, so nothing here is contradicted.
Test:
- The box point (0.25, 5.5) is inside a 2 m box centered at (0, 5).
- The capsule point (4, 5.25) is 0.25 m off the core from (3, 5) to (5, 5), within radius 0.5.
- The near miss (1.5, 5.5) projects to (1, 5.5).
As the body says, only the capsule case catches the no-inside-branch mutant, since a point inside a polygon core projects to itself. The capsule case also catches the radius-left-out mutant. Both exact-equality checks hold because the inside branch returns the input unchanged.
The body has Problem, Change and Verification. The change is docs and a test only.
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
m2Shape_GetClosestPoint's header promises the nearest surface point. For a point inside the shape, or within its radius of the core, the call returns the point itself, as Box2D's does. The header says nothing of that, and no test takes the branch (#353).Change
include/maul2d/shape.h:m2Shape_GetClosestPointsays that a point inside the shape, or within its radius, is its own nearest point and comes back as it is.@returnsays the same.test/test_world.cgainsTestClosestPointFromInside, on a 2 m box and a capsule of radius 0.5:No result changes: the code is as it was.
Verification
test_worldpasses.test_world:tools/check.sh changedpasses, the documentation check included. The changed file compiles 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 #353