Add Int3 operators + funcs.

This commit is contained in:
Jean-Baptiste Perrier
2021-04-08 18:53:39 +02:00
parent 54786a001a
commit 4b22503ea2

View File

@@ -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:
/// <summary>
/// Gets a value indicting whether this vector is zero.
/// </summary>
/// <returns> True if the vector is zero, otherwise false.</returns>
bool IsZero() const
{
return X == 0 && Y == 0 && Z == 0;
}
/// <summary>
/// Gets a value indicting whether any vector component is zero.
/// </summary>
/// <returns> True if a component is zero, otherwise false.</returns>
bool IsAnyZero() const
{
return X == 0 || Y == 0 || Z == 0;
}
/// <summary>
/// Gets a value indicting whether this vector is one.
/// </summary>
/// <returns> True if the vector is one, otherwise false.</returns>
bool IsOne() const
{
return X == 1 && Y == 1 && Z == 1;
}
/// <summary>
/// Calculates a vector with values being opposite to values of that vector
/// </summary>
/// <returns>Negative vector</returns>
Int3 GetNegative() const
{
return Int3(-X, -Y, -Z);
}
/// <summary>
/// Returns average arithmetic of all the components
/// </summary>
/// <returns>Average arithmetic of all the components</returns>
float AverageArithmetic() const
{
return (X + Y + Z) / 3.0f;
}
/// <summary>
/// Gets sum of all vector components values
/// </summary>
/// <returns>Sum of X, Y, Z and W</returns>
int32 SumValues() const
{
return X + Y + Z;
}
/// <summary>
/// Returns minimum value of all the components
/// </summary>
/// <returns>Minimum value</returns>
int32 MinValue() const
{
return Math::Min(X, Y, Z);
}
/// <summary>
/// Returns maximum value of all the components
/// </summary>
/// <returns>Maximum value</returns>
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