Add Int4 operators + funcs.
This commit is contained in:
@@ -121,6 +121,229 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
// Arithmetic operators with Int2
|
||||
|
||||
Int4 operator+(const Int4& b) const
|
||||
{
|
||||
return Add(*this, b);
|
||||
}
|
||||
|
||||
Int4 operator-(const Int4& b) const
|
||||
{
|
||||
return Subtract(*this, b);
|
||||
}
|
||||
|
||||
Int4 operator*(const Int4& b) const
|
||||
{
|
||||
return Multiply(*this, b);
|
||||
}
|
||||
|
||||
Int4 operator/(const Int4& b) const
|
||||
{
|
||||
return Divide(*this, b);
|
||||
}
|
||||
|
||||
Int4 operator-() const
|
||||
{
|
||||
return Int4(-X, -Y, -Z, -W);
|
||||
}
|
||||
|
||||
// op= operators with Int2
|
||||
|
||||
Int4& operator+=(const Int4& b)
|
||||
{
|
||||
*this = Add(*this, b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int4& operator-=(const Int4& b)
|
||||
{
|
||||
*this = Subtract(*this, b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int4& operator*=(const Int4& b)
|
||||
{
|
||||
*this = Multiply(*this, b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int4& operator/=(const Int4& b)
|
||||
{
|
||||
*this = Divide(*this, b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Arithmetic operators with int32
|
||||
|
||||
Int4 operator+(int32 b) const
|
||||
{
|
||||
return Add(*this, b);
|
||||
}
|
||||
|
||||
Int4 operator-(int32 b) const
|
||||
{
|
||||
return Subtract(*this, b);
|
||||
}
|
||||
|
||||
Int4 operator*(int32 b) const
|
||||
{
|
||||
return Multiply(*this, b);
|
||||
}
|
||||
|
||||
Int4 operator/(int32 b) const
|
||||
{
|
||||
return Divide(*this, b);
|
||||
}
|
||||
|
||||
// op= operators with int32
|
||||
|
||||
Int4& operator+=(int32 b)
|
||||
{
|
||||
*this = Add(*this, b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int4& operator-=(int32 b)
|
||||
{
|
||||
*this = Subtract(*this, b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int4& operator*=(int32 b)
|
||||
{
|
||||
*this = Multiply(*this, b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Int4& operator/=(int32 b)
|
||||
{
|
||||
*this = Divide(*this, b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Comparison operators
|
||||
|
||||
bool operator==(const Int4& b) const
|
||||
{
|
||||
return X == b.X && Y == b.Y;
|
||||
}
|
||||
|
||||
bool operator!=(const Int4& b) const
|
||||
{
|
||||
return X != b.X || Y != b.Y;
|
||||
}
|
||||
|
||||
bool operator>(const Int4& b) const
|
||||
{
|
||||
return X > b.X && Y > b.Y;
|
||||
}
|
||||
|
||||
bool operator>=(const Int4& b) const
|
||||
{
|
||||
return X >= b.X && Y >= b.Y;
|
||||
}
|
||||
|
||||
bool operator<(const Int4& b) const
|
||||
{
|
||||
return X < b.X && Y < b.Y;
|
||||
}
|
||||
|
||||
bool operator<=(const Int4& b) const
|
||||
{
|
||||
return X <= b.X && Y <= b.Y;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static void Add(const Int4& a, const Int4& b, Int4& result)
|
||||
{
|
||||
result.X = a.X + b.X;
|
||||
result.Y = a.Y + b.Y;
|
||||
result.Z = a.Z + b.Z;
|
||||
result.W = a.W + b.W;
|
||||
}
|
||||
|
||||
static Int4 Add(const Int4& a, const Int4& b)
|
||||
{
|
||||
Int4 result;
|
||||
Add(a, b, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void Subtract(const Int4& a, const Int4& b, Int4& result)
|
||||
{
|
||||
result.X = a.X - b.X;
|
||||
result.Y = a.Y - b.Y;
|
||||
result.Z = a.Z - b.Z;
|
||||
result.W = a.W - b.W;
|
||||
}
|
||||
|
||||
static Int4 Subtract(const Int4& a, const Int4& b)
|
||||
{
|
||||
Int4 result;
|
||||
Subtract(a, b, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static Int4 Multiply(const Int4& a, const Int4& b)
|
||||
{
|
||||
return Int4(a.X * b.X, a.Y * b.Y, a.Z * b.Z, a.W * b.W);
|
||||
}
|
||||
|
||||
static Int4 Multiply(const Int4& a, int32 b)
|
||||
{
|
||||
return Int4(a.X * b, a.Y * b, a.Z * b, a.W * b);
|
||||
}
|
||||
|
||||
static Int4 Divide(const Int4& a, const Int4& b)
|
||||
{
|
||||
return Int4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W);
|
||||
}
|
||||
|
||||
static Int4 Divide(const Int4& a, int32 b)
|
||||
{
|
||||
return Int4(a.X / b, a.Y / b, a.Z / b, a.Y / 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 && W == 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 || W == 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 && W == 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates a vector with values being opposite to values of that vector
|
||||
/// </summary>
|
||||
/// <returns>Negative vector</returns>
|
||||
Int4 GetNegative() const
|
||||
{
|
||||
return Int4(-X, -Y, -Z, -W);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns average arithmetic of all the components
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user