Compare commits

..

4 Commits

Author SHA1 Message Date
Recep Aslantas 58d8c15a12 Merge pull request #499 from tooold2rock-n-roll/tooold2rock-n-roll/issue_n498_int2float_conversion_warnings
Fixing warning messages.
2026-07-29 18:21:01 +03:00
TooOld2Rock'nRoll bbd81a24d3 Fixing warning messages. 2026-07-29 10:37:03 -03:00
Recep Aslantas b7813d0edb Merge pull request #496 from 94xhn/fix/aabb-sphere-below-min-face-selection
box/aabb2d: fix wrong face selected below AABB min bound in sphere/circle test
2026-07-18 18:32:22 +03:00
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
11 changed files with 40 additions and 40 deletions
+2 -2
View File
@@ -235,8 +235,8 @@ glm_aabb2d_circle(vec2 aabb[2], vec3 c) {
a = (c[0] < aabb[0][0]) + (c[0] > aabb[1][0]);
b = (c[1] < aabb[0][1]) + (c[1] > aabb[1][1]);
dmin = glm_pow2((c[0] - aabb[!(a - 1)][0]) * (a != 0))
+ glm_pow2((c[1] - aabb[!(b - 1)][1]) * (b != 0));
dmin = glm_pow2((c[0] - aabb[c[0] > aabb[1][0]][0]) * (a != 0))
+ glm_pow2((c[1] - aabb[c[1] > aabb[1][1]][1]) * (b != 0));
return dmin <= glm_pow2(c[2]);
}
+3 -3
View File
@@ -243,9 +243,9 @@ glm_aabb_sphere(vec3 box[2], vec4 s) {
b = (s[1] < box[0][1]) + (s[1] > box[1][1]);
c = (s[2] < box[0][2]) + (s[2] > box[1][2]);
dmin = glm_pow2((s[0] - box[!(a - 1)][0]) * (a != 0))
+ glm_pow2((s[1] - box[!(b - 1)][1]) * (b != 0))
+ glm_pow2((s[2] - box[!(c - 1)][2]) * (c != 0));
dmin = glm_pow2((s[0] - box[s[0] > box[1][0]][0]) * (a != 0))
+ glm_pow2((s[1] - box[s[1] > box[1][1]][1]) * (b != 0))
+ glm_pow2((s[2] - box[s[2] > box[1][2]][2]) * (c != 0));
return dmin <= glm_pow2(s[3]);
}
+1 -1
View File
@@ -199,7 +199,7 @@ TEST_IMPL(GLM_PREFIX, mat2_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat2_scale)(m1, scale);
+1 -1
View File
@@ -143,7 +143,7 @@ TEST_IMPL(GLM_PREFIX, mat2x3_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat2x3_scale)(m1, scale);
+1 -1
View File
@@ -146,7 +146,7 @@ TEST_IMPL(GLM_PREFIX, mat2x4_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat2x4_scale)(m1, scale);
+1 -1
View File
@@ -187,7 +187,7 @@ TEST_IMPL(GLM_PREFIX, mat3_scale) {
int i, j, k;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat3_scale)(m1, scale);
+1 -1
View File
@@ -142,7 +142,7 @@ TEST_IMPL(GLM_PREFIX, mat3x2_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat3x2_scale)(m1, scale);
+1 -1
View File
@@ -148,7 +148,7 @@ TEST_IMPL(GLM_PREFIX, mat3x4_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat3x4_scale)(m1, scale);
+2 -2
View File
@@ -295,7 +295,7 @@ TEST_IMPL(GLM_PREFIX, mat4_scale_p) {
int i, j, k;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat4_scale_p)(m1, scale);
@@ -315,7 +315,7 @@ TEST_IMPL(GLM_PREFIX, mat4_scale) {
int i, j, k;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat4_scale)(m1, scale);
+1 -1
View File
@@ -145,7 +145,7 @@ TEST_IMPL(GLM_PREFIX, mat4x2_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat4x2_scale)(m1, scale);
+1 -1
View File
@@ -149,7 +149,7 @@ TEST_IMPL(GLM_PREFIX, mat4x3_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat4x3_scale)(m1, scale);