diff options
Diffstat (limited to 'source/blender/blenlib/BLI_float3.hh')
-rw-r--r-- | source/blender/blenlib/BLI_float3.hh | 129 |
1 files changed, 79 insertions, 50 deletions
diff --git a/source/blender/blenlib/BLI_float3.hh b/source/blender/blenlib/BLI_float3.hh index 7ef4f1b4973..a0979bc75bd 100644 --- a/source/blender/blenlib/BLI_float3.hh +++ b/source/blender/blenlib/BLI_float3.hh @@ -58,56 +58,6 @@ struct float3 { return &x; } - float normalize_and_get_length() - { - return normalize_v3(*this); - } - - float3 normalized() const - { - float3 result; - normalize_v3_v3(result, *this); - return result; - } - - float length() const - { - return len_v3(*this); - } - - float length_squared() const - { - return len_squared_v3(*this); - } - - void reflect(const float3 &normal) - { - *this = this->reflected(normal); - } - - float3 reflected(const float3 &normal) const - { - float3 result; - reflect_v3_v3v3(result, *this, normal); - return result; - } - - static float3 safe_divide(const float3 &a, const float3 &b) - { - float3 result; - result.x = (b.x == 0.0f) ? 0.0f : a.x / b.x; - result.y = (b.y == 0.0f) ? 0.0f : a.y / b.y; - result.z = (b.z == 0.0f) ? 0.0f : a.z / b.z; - return result; - } - - void invert() - { - x = -x; - y = -y; - z = -z; - } - friend float3 operator+(const float3 &a, const float3 &b) { return {a.x + b.x, a.y + b.y, a.z + b.z}; @@ -178,6 +128,85 @@ struct float3 { return stream; } + friend bool operator==(const float3 &a, const float3 &b) + { + return a.x == b.x && a.y == b.y && a.z == b.z; + } + + friend bool operator!=(const float3 &a, const float3 &b) + { + return !(a == b); + } + + float normalize_and_get_length() + { + return normalize_v3(*this); + } + + /** + * Normalizes the vector in place. + */ + void normalize() + { + normalize_v3(*this); + } + + /** + * Returns a normalized vector. The original vector is not changed. + */ + float3 normalized() const + { + float3 result; + normalize_v3_v3(result, *this); + return result; + } + + float length() const + { + return len_v3(*this); + } + + float length_squared() const + { + return len_squared_v3(*this); + } + + void reflect(const float3 &normal) + { + *this = this->reflected(normal); + } + + float3 reflected(const float3 &normal) const + { + float3 result; + reflect_v3_v3v3(result, *this, normal); + return result; + } + + static float3 safe_divide(const float3 &a, const float3 &b) + { + float3 result; + result.x = (b.x == 0.0f) ? 0.0f : a.x / b.x; + result.y = (b.y == 0.0f) ? 0.0f : a.y / b.y; + result.z = (b.z == 0.0f) ? 0.0f : a.z / b.z; + return result; + } + + void invert() + { + x = -x; + y = -y; + z = -z; + } + + uint64_t hash() const + { + uint64_t x1 = *(uint32_t *)&x; + uint64_t x2 = *(uint32_t *)&y; + uint64_t x3 = *(uint32_t *)&z; + return (x1 * 435109) ^ (x2 * 380867) ^ (x3 * 1059217); + } + static float dot(const float3 &a, const float3 &b) { return a.x * b.x + a.y * b.y + a.z * b.z; |