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:
Diffstat (limited to 'source/blender/blenlib/BLI_float4.hh')
-rw-r--r--source/blender/blenlib/BLI_float4.hh52
1 files changed, 52 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_float4.hh b/source/blender/blenlib/BLI_float4.hh
index b1feee3121b..5b487f6d029 100644
--- a/source/blender/blenlib/BLI_float4.hh
+++ b/source/blender/blenlib/BLI_float4.hh
@@ -44,6 +44,11 @@ struct float4 {
return &x;
}
+ friend float4 operator+(const float4 &a, const float &b)
+ {
+ return {a.x + b, a.y + b, a.z + b, a.w + b};
+ }
+
operator const float *() const
{
return &x;
@@ -58,11 +63,27 @@ struct float4 {
return *this;
}
+ friend float4 operator-(const float4 &a, const float4 &b)
+ {
+ return {a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w};
+ }
+
+ friend float4 operator-(const float4 &a, const float &b)
+ {
+ return {a.x - b, a.y - b, a.z - b, a.w - b};
+ }
+
friend float4 operator+(const float4 &a, const float4 &b)
{
return {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w};
}
+ friend float4 operator/(const float4 &a, float f)
+ {
+ BLI_assert(f != 0.0f);
+ return a * (1.0f / f);
+ }
+
float4 &operator*=(float factor)
{
x *= factor;
@@ -81,6 +102,37 @@ struct float4 {
{
return b * a;
}
+
+ float length() const
+ {
+ return len_v4(*this);
+ }
+
+ static float distance(const float4 &a, const float4 &b)
+ {
+ return (a - b).length();
+ }
+
+ static float4 safe_divide(const float4 &a, const float b)
+ {
+ return (b != 0.0f) ? a / b : float4(0.0f);
+ }
+
+ static float4 interpolate(const float4 &a, const float4 &b, float t)
+ {
+ return a * (1 - t) + b * t;
+ }
+
+ static float4 floor(const float4 &a)
+ {
+ return float4(floorf(a.x), floorf(a.y), floorf(a.z), floorf(a.w));
+ }
+
+ static float4 normalize(const float4 &a)
+ {
+ const float t = len_v4(a);
+ return (t != 0.0f) ? a / t : float4(0.0f);
+ }
};
} // namespace blender