commit c332bc8a945b01ebf24cf1baf8cf144268b39252
parent 54e83fdd5bde1a510a95003600c5727444da16cd
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 23 May 2025 14:42:33 +0200
Test fix for ray tracing in a binary tree
To avoid numerical problems, commit e4ad9db slightly modifies the
direction of the ray if it is traced along the infinite dimension. But
the test always assumed that this direction was necessarily unchanged,
and therefore equal to that submitted by the user to the nearest bit.
Hence this commit, which uses epsilon equality instead of strict
equality.
Diffstat:
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/test_svx_bintree_trace_ray.c b/src/test_svx_bintree_trace_ray.c
@@ -140,8 +140,17 @@ hit_challenge_pass_through
CHK(hit && ray_org && ray_dir && ray_range && context);
CHK(!SVX_HIT_NONE(hit));
CHK(d3_eq(ray->org, ray_org));
- CHK(d3_eq(ray->dir, ray_dir));
CHK(d2_eq(ray->range, ray_range));
+
+ /* The direction could be adjusted internally when crossing a binary tree.
+ * This avoids numerical inaccuracies in the case of distant intersections,
+ * i.e. when the ray direction is roughly aligned with the third dimension
+ * (i.e. the one that goes to infinity). In this case, the ray direction is
+ * forced to be 0 on this dimension before being renormalized. The ray
+ * therefore never intersects the binary tree. But its direction has changed.
+ * Hence the approximate equality on the direction */
+ CHK(d3_eq_eps(ray->dir, ray_dir, 1.e-6));
+
return 0;
}
@@ -156,9 +165,13 @@ hit_filter
const struct ray* ray = context;
CHK(hit && ray_org && ray_dir && ray_range && context);
CHK(d3_eq(ray->org, ray_org));
- CHK(d3_eq(ray->dir, ray_dir));
CHK(d2_eq(ray->range, ray_range));
CHK(!SVX_HIT_NONE(hit));
+
+ /* The direction could be adjusted internally when crossing a binary tree.
+ * Refer to the hit_challenge_pass_through function */
+ CHK(d3_eq_eps(ray->dir, ray_dir, 1.e-6));
+
return *((char*)hit->voxel.data) == 0;
}