diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 18 |
2 files changed, 22 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index 3399287dd46..1425e7da1bc 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -367,6 +367,10 @@ MINLINE bool compare_len_v3v3(const float a[3], const float b[3], const float limit) ATTR_WARN_UNUSED_RESULT; +MINLINE bool compare_size_v3v3(const float a[3], + const float b[3], + const float limit) ATTR_WARN_UNUSED_RESULT; + MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2]) ATTR_WARN_UNUSED_RESULT; diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 13a87b9ec6a..d3c975e3249 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -1372,6 +1372,24 @@ MINLINE bool compare_len_v3v3(const float v1[3], const float v2[3], const float return (dot_v3v3(d, d) <= (limit * limit)); } +MINLINE bool compare_size_v3v3(const float v1[3], const float v2[3], const float limit) +{ + for (int i = 0; i < 3; i++) { + if (v2[i] == 0.0f) { + /* Catch division by zero. */ + if (v1[i] != v2[i]) { + return false; + } + } + else { + if (fabsf(v1[i] / v2[i] - 1.0f) > limit) { + return false; + } + } + } + return true; +} + /** \name Vector Clamping * \{ */ |