From 41e650981861c2f18ab0548e18851d1d761066ff Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 13 Aug 2021 15:36:49 +1000 Subject: Mesh: replace saacos with acosf for normal calculation The clamped version of acos isn't needed as degenerate (nan) coordinates result in zeroed vectors which don't need clamping. --- source/blender/blenlib/intern/math_geom.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 8afb6b5a2be..43f2e08cf69 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -5307,7 +5307,10 @@ void accumulate_vertex_normals_tri_v3(float n1[3], for (i = 0; i < nverts; i++) { const float *cur_edge = vdiffs[i]; - const float fac = saacos(-dot_v3v3(cur_edge, prev_edge)); + /* Calculate angle between the two poly edges incident on this vertex. + * NOTE: no need for #saacos here as the input has been sanitized, + * `nan` values in coordinates normalize to zero which works for `acosf`. */ + const float fac = acosf(-dot_v3v3(cur_edge, prev_edge)); /* accumulate */ madd_v3_v3fl(vn[i], f_no, fac); @@ -5386,9 +5389,10 @@ void accumulate_vertex_normals_poly_v3(float **vertnos, for (i = 0; i < nverts; i++) { const float *cur_edge = vdiffs[i]; - /* calculate angle between the two poly edges incident on - * this vertex */ - const float fac = saacos(-dot_v3v3(cur_edge, prev_edge)); + /* Calculate angle between the two poly edges incident on this vertex. + * NOTE: no need for #saacos here as the input has been sanitized, + * `nan` values in coordinates normalize to zero which works for `acosf`. */ + const float fac = acosf(-dot_v3v3(cur_edge, prev_edge)); /* accumulate */ madd_v3_v3fl(vertnos[i], polyno, fac); -- cgit v1.2.3