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 b6e5e41304d1b748fa5c7ec57e8fd3489f38edc2
parent a5b18367bb7164b3eae5be70ae6bf992e61aeadc
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  9 Oct 2020 15:35:06 +0200

Fix the s3d_closest_point tests

Diffstat:
Msrc/test_s3d_closest_point.c | 33++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/src/test_s3d_closest_point.c b/src/test_s3d_closest_point.c @@ -80,11 +80,12 @@ closest_point_triangle float ab[3], ac[3], bc[3]; float ap[3], bp[3], cp[3]; float d1, d2, d3, d4, d5, d6, d; + float lab, lac, lbc; CHK(p && a && b && c && pt); - f3_normalize(ab, f3_sub(ab, b, a)); - f3_normalize(ac, f3_sub(ac, c, a)); - f3_normalize(bc, f3_sub(bc, c, b)); + lab = f3_normalize(ab, f3_sub(ab, b, a)); + lac = f3_normalize(ac, f3_sub(ac, c, a)); + lbc = f3_normalize(bc, f3_sub(bc, c, b)); /* Compute the triangle normal */ f3_cross(N, ac, ab); @@ -108,22 +109,22 @@ closest_point_triangle if(d5 <= 0 && d6 <= 0) return f3_set(pt, c); /* Check if the nearest point is on the 1st triangle edge */ - f3_normalize(Nbc, f3_cross(Nab, ab, N)); + f3_normalize(Nab, f3_cross(Nab, ab, N)); if(f3_dot(Nab, ap) <= 0) { - return f3_add(pt, a, f3_mulf(pt, ab, d1)); + return f3_add(pt, a, f3_mulf(pt, ab, MMIN(d1, lab))); } /* Check if the nearest point is on the 2nd triangle edge */ f3_normalize(Nbc, f3_cross(Nbc, bc, N)); if(f3_dot(Nbc, bp) <= 0) { - return f3_add(pt, b, f3_mulf(pt, bc, d3)); + return f3_add(pt, b, f3_mulf(pt, bc, MMIN(d3, lbc))); } /* Check if the nearest point is on the 3rd triangle edge */ f3_normalize(Nca, f3_cross(Nca, ac, N)); f3_minus(Nca, Nca); if(f3_dot(Nca, cp) <= 0) { - return f3_add(pt, c, f3_mulf(pt, ac,-d5)); + return f3_add(pt, c, f3_mulf(pt, ac,-MMIN(d5, lac))); } /* The nearest point is in the triangle */ @@ -746,6 +747,24 @@ test_cbox(struct s3d_device* dev) mid[1] = (low[1] + upp[1]) * 0.5f; mid[2] = (low[2] + upp[2]) * 0.5f; + /* Filter nothing */ + filter_data.geom_to_filter[0] = S3D_INVALID_ID; + filter_data.geom_to_filter[1] = S3D_INVALID_ID; + filter_data.geom_to_filter[2] = S3D_INVALID_ID; + + /* Check a specific position that exhibits a precision issues of the + * closest_point_triangle test routine */ + { + union { float f; uint32_t ui; } ucast; + pos[0] = (ucast.ui = 0xc386cc9a, ucast.f); + pos[1] = (ucast.ui = 0x43e635b8, ucast.f); + pos[2] = (ucast.ui = 0x4319ab78, ucast.f); + f3_set(filter_data.query_pos, pos); + CHK(s3d_scene_view_closest_point + (scnview, pos, (float)INF, &filter_data, &hit) == RES_OK); + check_closest_point_cbox(pos, geom_id, &hit); + } + /* Check closest point query on Cornell box */ FOR_EACH(i, 0, 10000) { /* Randomly generate a point in a bounding box that is 2 times the size of