star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

commit 043dc3be804f2240d9d3a804ec02181730d00ea5
parent b4e2464b1d662278b7ac939699986c4626375d79
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 20 Apr 2020 09:53:53 +0200

Handle a precision issue in closest_point_triangle

Ensure that the returned barycentric coordinates are positive.

Diffstat:
Msrc/s3d_scene_view_closest_point.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/s3d_scene_view_closest_point.c b/src/s3d_scene_view_closest_point.c @@ -144,9 +144,13 @@ closest_point_triangle /* Save the uv barycentric coordinates */ uv[0] = 1.f - v - w; uv[1] = v; - ASSERT(eq_epsf(uv[0] + uv[1] + w, 1.f, 1.e-4f)); + if(uv[0] < 0.f) { /* Handle precision issues */ + if(uv[1] > w) uv[1] += uv[0]; + uv[0] = 0; + } + /* Use the barycentric coordinates to compute the world space position of the * closest point onto the triangle */ closest_pt[0] = a[0] + v*ab[0] + w*ac[0];