Files
cglm/include/cglm
94xhn 1c260ceb7d box/aabb2d: fix wrong face selected below AABB min bound in sphere/circle test
glm_aabb_sphere() and glm_aabb2d_circle() pick which box face to
measure axis distance to via `!(a - 1)`, where
`a = (s[i] < box[0][i]) + (s[i] > box[1][i])` is 1 for either
out-of-range direction. `!(a - 1)` always resolves to index 1
(the max face) whenever a == 1, so when the query point is below
the box's min bound on an axis, distance is measured to the wrong
(max) face instead of the min face, inflating dmin and producing
false-negative intersection results.

The above-max direction happens to pick the correct face already,
which is why this went unnoticed since the index-selection logic
was introduced in #180 (fix for #179).

Fix: index directly with the "above max" boolean
(s[i] > box[1][i]) instead of the derived !(a - 1) expression --
it's 0 for below-min (selects box[0], correct) and 1 for
above-max (selects box[1], correct), and is already computed as
part of `a`/`b`/`c` so no extra branching is introduced. Same fix
applied to both the 3D (box.h) and 2D (aabb2d.h) variants since
they share the identical pattern.

Verified against a hand-written Ericson/Graphics-Gems reference
point-AABB distance test: 200k randomized box/sphere fuzz cases
show 3418/200000 false negatives before this fix and 0/200000
after, with no change to the already-correct above-max and
fully-enclosed cases.
2026-07-18 18:06:58 +08:00
..
2026-04-18 10:11:03 +03:00
2024-08-27 12:22:42 +03:00
2024-02-08 15:12:30 +07:00
2024-02-08 15:12:30 +07:00
2024-07-14 09:10:19 +07:00
2024-02-08 15:12:30 +07:00
2023-07-08 23:13:20 +03:00
2019-06-03 12:12:50 +03:00
2026-03-22 11:11:46 +02:00
2019-05-07 16:16:00 -05:00
2024-02-08 15:12:30 +07:00
2024-02-08 15:12:30 +07:00
2025-04-17 18:08:50 -04:00
2025-04-05 13:36:12 +03:00
2025-04-04 11:04:44 -04:00
2025-04-05 13:32:47 +03:00
2025-01-22 16:49:27 +00:00
2024-07-14 09:10:19 +07:00
2024-03-29 08:10:56 +03:00
2025-01-15 14:05:08 +00:00
2026-03-22 11:11:46 +02:00
2024-02-08 15:12:30 +07:00
2025-11-15 10:39:14 +01:00
2025-11-15 10:39:14 +01:00
2025-11-15 10:39:14 +01:00
2025-02-13 12:25:10 +03:00