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:
authorCampbell Barton <ideasman42@gmail.com>2020-03-04 03:23:00 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-03-04 03:23:00 +0300
commit89b10b8d423a0ee851d9299af279ab93660f15f4 (patch)
tree3bc8e70afc2b7a4b893e3f62945734f94c505173 /source/blender
parenta37dceb139eb64e00af8c1a79c49f31f42479bdd (diff)
BLI_math: inline clamp functions
These are used in some per-pixel operations such as image sampling and color conversion, where replacing existing macro use could add overhead.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenlib/BLI_math_vector.h12
-rw-r--r--source/blender/blenlib/intern/math_vector.c42
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c47
3 files changed, 53 insertions, 48 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index e210bae11d6..b9d2a89784b 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -440,12 +440,12 @@ void dist_ensure_v2_v2fl(float v1[2], const float v2[2], const float dist);
void axis_sort_v3(const float axis_values[3], int r_axis_order[3]);
-void clamp_v2(float vec[2], const float min, const float max);
-void clamp_v3(float vec[3], const float min, const float max);
-void clamp_v4(float vec[4], const float min, const float max);
-void clamp_v2_v2v2(float vec[2], const float min[2], const float max[2]);
-void clamp_v3_v3v3(float vec[3], const float min[3], const float max[3]);
-void clamp_v4_v4v4(float vec[4], const float min[4], const float max[4]);
+MINLINE void clamp_v2(float vec[2], const float min, const float max);
+MINLINE void clamp_v3(float vec[3], const float min, const float max);
+MINLINE void clamp_v4(float vec[4], const float min, const float max);
+MINLINE void clamp_v2_v2v2(float vec[2], const float min[2], const float max[2]);
+MINLINE void clamp_v3_v3v3(float vec[3], const float min[3], const float max[3]);
+MINLINE void clamp_v4_v4v4(float vec[4], const float min[4], const float max[4]);
/***************************** Array Functions *******************************/
/* follow fixed length vector function conventions. */
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index d1b36884038..5919b7e1dd6 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -1051,48 +1051,6 @@ void axis_sort_v3(const float axis_values[3], int r_axis_order[3])
#undef SWAP_AXIS
}
-void clamp_v2(float vec[2], const float min, const float max)
-{
- CLAMP(vec[0], min, max);
- CLAMP(vec[1], min, max);
-}
-
-void clamp_v3(float vec[3], const float min, const float max)
-{
- CLAMP(vec[0], min, max);
- CLAMP(vec[1], min, max);
- CLAMP(vec[2], min, max);
-}
-
-void clamp_v4(float vec[4], const float min, const float max)
-{
- CLAMP(vec[0], min, max);
- CLAMP(vec[1], min, max);
- CLAMP(vec[2], min, max);
- CLAMP(vec[3], min, max);
-}
-
-void clamp_v2_v2v2(float vec[2], const float min[2], const float max[2])
-{
- CLAMP(vec[0], min[0], max[0]);
- CLAMP(vec[1], min[1], max[1]);
-}
-
-void clamp_v3_v3v3(float vec[3], const float min[3], const float max[3])
-{
- CLAMP(vec[0], min[0], max[0]);
- CLAMP(vec[1], min[1], max[1]);
- CLAMP(vec[2], min[2], max[2]);
-}
-
-void clamp_v4_v4v4(float vec[4], const float min[4], const float max[4])
-{
- CLAMP(vec[0], min[0], max[0]);
- CLAMP(vec[1], min[1], max[1]);
- CLAMP(vec[2], min[2], max[2]);
- CLAMP(vec[3], min[3], max[3]);
-}
-
/***************************** Array Functions *******************************/
MINLINE double sqr_db(double f)
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index a304042a605..d2c55233653 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -1291,6 +1291,53 @@ MINLINE bool compare_len_v3v3(const float v1[3], const float v2[3], const float
return (dot_v3v3(d, d) <= (limit * limit));
}
+/** \name Vector Clamping
+ * \{ */
+
+MINLINE void clamp_v2(float vec[2], const float min, const float max)
+{
+ CLAMP(vec[0], min, max);
+ CLAMP(vec[1], min, max);
+}
+
+MINLINE void clamp_v3(float vec[3], const float min, const float max)
+{
+ CLAMP(vec[0], min, max);
+ CLAMP(vec[1], min, max);
+ CLAMP(vec[2], min, max);
+}
+
+MINLINE void clamp_v4(float vec[4], const float min, const float max)
+{
+ CLAMP(vec[0], min, max);
+ CLAMP(vec[1], min, max);
+ CLAMP(vec[2], min, max);
+ CLAMP(vec[3], min, max);
+}
+
+MINLINE void clamp_v2_v2v2(float vec[2], const float min[2], const float max[2])
+{
+ CLAMP(vec[0], min[0], max[0]);
+ CLAMP(vec[1], min[1], max[1]);
+}
+
+MINLINE void clamp_v3_v3v3(float vec[3], const float min[3], const float max[3])
+{
+ CLAMP(vec[0], min[0], max[0]);
+ CLAMP(vec[1], min[1], max[1]);
+ CLAMP(vec[2], min[2], max[2]);
+}
+
+MINLINE void clamp_v4_v4v4(float vec[4], const float min[4], const float max[4])
+{
+ CLAMP(vec[0], min[0], max[0]);
+ CLAMP(vec[1], min[1], max[1]);
+ CLAMP(vec[2], min[2], max[2]);
+ CLAMP(vec[3], min[3], max[3]);
+}
+
+/** \} */
+
/**
* <pre>
* + l1