diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-02-06 13:47:46 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-02-06 13:49:12 +0300 |
commit | 6202bc82b858d8f6876c6c20ec62dd0a16209087 (patch) | |
tree | 8a3e0bf4ef94fb91c6190c743d00a17aa77eb7dc /source/blender/editors/mesh/editmesh_select.c | |
parent | f7613cf41ceb4d31d8a869e27cef4781a83e09db (diff) |
Fix T60935: More numerically stable distance to ray computation
The old function was numerically very unstable for 2 reasons:
computing the square and then subtracting the results.
In the example in T60935 all precision was lost and it returned the distance 0
for all points.
I also removed the `depth` parameter since it wasn't used and computing
it would have made the code more complicated.
Reviewers: brecht, campbellbarton
Differential Revision: https://developer.blender.org/D4308
Diffstat (limited to 'source/blender/editors/mesh/editmesh_select.c')
-rw-r--r-- | source/blender/editors/mesh/editmesh_select.c | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index d09f3ba6f64..fd9e635f5e3 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -1153,16 +1153,13 @@ bool EDBM_unified_findnearest_from_raycast( if ((BM_elem_flag_test(e, BM_ELEM_HIDDEN) == false) && (BM_edge_is_boundary(e))) { - float depth; - if (use_vert) { for (uint j = 0; j < 2; j++) { BMVert *v = *((&e->v1) + j); float point[3]; mul_v3_m4v3(point, obedit->obmat, coords ? coords[BM_elem_index_get(v)] : v->co); - const float dist_sq_test = dist_squared_to_ray_v3( - ray_origin, ray_direction, - point, &depth); + const float dist_sq_test = dist_squared_to_ray_v3_normalized( + ray_origin, ray_direction, point); if (dist_sq_test < dist_sq_best) { dist_sq_best = dist_sq_test; best.base_index = base_index; @@ -1186,9 +1183,8 @@ bool EDBM_unified_findnearest_from_raycast( mid_v3_v3v3(point, e->v1->co, e->v2->co); } mul_m4_v3(obedit->obmat, point); - const float dist_sq_test = dist_squared_to_ray_v3( - ray_origin, ray_direction, - point, &depth); + const float dist_sq_test = dist_squared_to_ray_v3_normalized( + ray_origin, ray_direction, point); if (dist_sq_test < dist_sq_best) { dist_sq_best = dist_sq_test; best.base_index = base_index; @@ -1208,10 +1204,8 @@ bool EDBM_unified_findnearest_from_raycast( if (BM_elem_flag_test(v, BM_ELEM_HIDDEN) == false) { float point[3]; mul_v3_m4v3(point, obedit->obmat, v->co); - float depth; - const float dist_sq_test = dist_squared_to_ray_v3( - ray_origin, ray_direction, - v->co, &depth); + const float dist_sq_test = dist_squared_to_ray_v3_normalized( + ray_origin, ray_direction, v->co); if (dist_sq_test < dist_sq_best) { dist_sq_best = dist_sq_test; best.base_index = base_index; @@ -1233,10 +1227,8 @@ bool EDBM_unified_findnearest_from_raycast( mid_v3_v3v3(point, e->v1->co, e->v2->co); } mul_m4_v3(obedit->obmat, point); - float depth; - const float dist_sq_test = dist_squared_to_ray_v3( - ray_origin, ray_direction, - point, &depth); + const float dist_sq_test = dist_squared_to_ray_v3_normalized( + ray_origin, ray_direction, point); if (dist_sq_test < dist_sq_best) { dist_sq_best = dist_sq_test; best.base_index = base_index; @@ -1260,10 +1252,8 @@ bool EDBM_unified_findnearest_from_raycast( BM_face_calc_center_median(f, point); } mul_m4_v3(obedit->obmat, point); - float depth; - const float dist_sq_test = dist_squared_to_ray_v3( - ray_origin, ray_direction, - point, &depth); + const float dist_sq_test = dist_squared_to_ray_v3_normalized( + ray_origin, ray_direction, point); if (dist_sq_test < dist_sq_best) { dist_sq_best = dist_sq_test; best.base_index = base_index; |