Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2021-06-14 12:06:35 +0300
committerBastien Montagne <bastien@blender.org>2021-06-14 13:32:38 +0300
commitb21db5e6988566dc3344b3293eb7e33234ec2597 (patch)
tree0bc664e2dfb2dce5b94062367ba54bc14eacb9bf /source/blender/blenlib/intern/math_vector.c
parent5add6f2ed93773e1231e3d52dc9fd963b3bfb9e7 (diff)
BLI_math: Fix several division-by-zero cases.
Those were caused by various tools used on degenerate geometry, see T79775. Note that fixes are as low-level as possible, to ensure they cover as much as possible of unreported issues too. We still probably have many more of those hidden in BLI_math though.
Diffstat (limited to 'source/blender/blenlib/intern/math_vector.c')
-rw-r--r--source/blender/blenlib/intern/math_vector.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index fb7b96fde78..05c5f672baa 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -657,6 +657,11 @@ void angle_poly_v3(float *angles, const float *verts[3], int len)
*/
void project_v2_v2v2(float out[2], const float p[2], const float v_proj[2])
{
+ if (UNLIKELY(is_zero_v2(v_proj))) {
+ zero_v2(out);
+ return;
+ }
+
const float mul = dot_v2v2(p, v_proj) / dot_v2v2(v_proj, v_proj);
out[0] = mul * v_proj[0];
@@ -668,6 +673,11 @@ void project_v2_v2v2(float out[2], const float p[2], const float v_proj[2])
*/
void project_v3_v3v3(float out[3], const float p[3], const float v_proj[3])
{
+ if (UNLIKELY(is_zero_v3(v_proj))) {
+ zero_v3(out);
+ return;
+ }
+
const float mul = dot_v3v3(p, v_proj) / dot_v3v3(v_proj, v_proj);
out[0] = mul * v_proj[0];
@@ -677,6 +687,11 @@ void project_v3_v3v3(float out[3], const float p[3], const float v_proj[3])
void project_v3_v3v3_db(double out[3], const double p[3], const double v_proj[3])
{
+ if (UNLIKELY(is_zero_v3_db(v_proj))) {
+ zero_v3_db(out);
+ return;
+ }
+
const double mul = dot_v3v3_db(p, v_proj) / dot_v3v3_db(v_proj, v_proj);
out[0] = mul * v_proj[0];