From 4b22503ea27e5f19c13804af281dd3f0db5e40f5 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:53:39 +0200 Subject: [PATCH] Add Int3 operators + funcs. --- Source/Engine/Core/Math/Int3.h | 257 +++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) diff --git a/Source/Engine/Core/Math/Int3.h b/Source/Engine/Core/Math/Int3.h index b5f8e0bf3..b215ee4ed 100644 --- a/Source/Engine/Core/Math/Int3.h +++ b/Source/Engine/Core/Math/Int3.h @@ -110,6 +110,263 @@ public: public: + // Arithmetic operators with Int2 + + Int3 operator+(const Int3& b) const + { + return Add(*this, b); + } + + Int3 operator-(const Int3& b) const + { + return Subtract(*this, b); + } + + Int3 operator*(const Int3& b) const + { + return Multiply(*this, b); + } + + Int3 operator/(const Int3& b) const + { + return Divide(*this, b); + } + + Int3 operator-() const + { + return Int3(-X, -Y, -Z); + } + + // op= operators with Int2 + + Int3& operator+=(const Int3& b) + { + *this = Add(*this, b); + return *this; + } + + Int3& operator-=(const Int3& b) + { + *this = Subtract(*this, b); + return *this; + } + + Int3& operator*=(const Int3& b) + { + *this = Multiply(*this, b); + return *this; + } + + Int3& operator/=(const Int3& b) + { + *this = Divide(*this, b); + return *this; + } + + // Arithmetic operators with int32 + + Int3 operator+(int32 b) const + { + return Add(*this, b); + } + + Int3 operator-(int32 b) const + { + return Subtract(*this, b); + } + + Int3 operator*(int32 b) const + { + return Multiply(*this, b); + } + + Int3 operator/(int32 b) const + { + return Divide(*this, b); + } + + // op= operators with int32 + + Int3& operator+=(int32 b) + { + *this = Add(*this, b); + return *this; + } + + Int3& operator-=(int32 b) + { + *this = Subtract(*this, b); + return *this; + } + + Int3& operator*=(int32 b) + { + *this = Multiply(*this, b); + return *this; + } + + Int3& operator/=(int32 b) + { + *this = Divide(*this, b); + return *this; + } + + // Comparison operators + + bool operator==(const Int3& b) const + { + return X == b.X && Y == b.Y; + } + + bool operator!=(const Int3& b) const + { + return X != b.X || Y != b.Y; + } + + bool operator>(const Int3& b) const + { + return X > b.X && Y > b.Y; + } + + bool operator>=(const Int3& b) const + { + return X >= b.X && Y >= b.Y; + } + + bool operator<(const Int3& b) const + { + return X < b.X && Y < b.Y; + } + + bool operator<=(const Int3& b) const + { + return X <= b.X && Y <= b.Y; + } + +public: + + static void Add(const Int3& a, const Int3& b, Int3& result) + { + result.X = a.X + b.X; + result.Y = a.Y + b.Y; + result.Z = a.Z + b.Z; + } + + static Int3 Add(const Int3& a, const Int3& b) + { + Int3 result; + Add(a, b, result); + return result; + } + + static void Subtract(const Int3& a, const Int3& b, Int3& result) + { + result.X = a.X - b.X; + result.Y = a.Y - b.Y; + result.Z = a.Z - b.Z; + } + + static Int3 Subtract(const Int3& a, const Int3& b) + { + Int3 result; + Subtract(a, b, result); + return result; + } + + static Int3 Multiply(const Int3& a, const Int3& b) + { + return Int3(a.X * b.X, a.Y * b.Y, a.Z * b.Z); + } + + static Int3 Multiply(const Int3& a, int32 b) + { + return Int3(a.X * b, a.Y * b, a.Z * b); + } + + static Int3 Divide(const Int3& a, const Int3& b) + { + return Int3(a.X / b.X, a.Y / b.Y, a.Z / b.Z); + } + + static Int3 Divide(const Int3& a, int32 b) + { + return Int3(a.X / b, a.Y / b, a.Z / b); + } + +public: + + /// + /// Gets a value indicting whether this vector is zero. + /// + /// True if the vector is zero, otherwise false. + bool IsZero() const + { + return X == 0 && Y == 0 && Z == 0; + } + + /// + /// Gets a value indicting whether any vector component is zero. + /// + /// True if a component is zero, otherwise false. + bool IsAnyZero() const + { + return X == 0 || Y == 0 || Z == 0; + } + + /// + /// Gets a value indicting whether this vector is one. + /// + /// True if the vector is one, otherwise false. + bool IsOne() const + { + return X == 1 && Y == 1 && Z == 1; + } + + /// + /// Calculates a vector with values being opposite to values of that vector + /// + /// Negative vector + Int3 GetNegative() const + { + return Int3(-X, -Y, -Z); + } + + /// + /// Returns average arithmetic of all the components + /// + /// Average arithmetic of all the components + float AverageArithmetic() const + { + return (X + Y + Z) / 3.0f; + } + + /// + /// Gets sum of all vector components values + /// + /// Sum of X, Y, Z and W + int32 SumValues() const + { + return X + Y + Z; + } + + /// + /// Returns minimum value of all the components + /// + /// Minimum value + int32 MinValue() const + { + return Math::Min(X, Y, Z); + } + + /// + /// Returns maximum value of all the components + /// + /// Maximum value + int32 MaxValue() const + { + return Math::Max(X, Y, Z); + } + // Returns a vector containing the largest components of the specified vectors // @param a The first source vector // @param b The second source vector