Added scalar addition / subtraction
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// will evaluate to true
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
#include <string>
|
||||
|
||||
template <typename Type>
|
||||
V3D<Type>::V3D(const Matrix<1, 3> &other)
|
||||
@@ -60,12 +61,24 @@ void V3D<Type>::operator=(const V3D<Type> &other)
|
||||
this->z = other.z;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
V3D<Type> V3D<Type>::operator+(Type other) const
|
||||
{
|
||||
return V3D<Type>{this->x + other, this->y + other, this->z + other};
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
V3D<Type> V3D<Type>::operator+(const V3D<Type> &other) const
|
||||
{
|
||||
return V3D<Type>{this->x + other.x, this->y + other.y, this->z + other.z};
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
V3D<Type> V3D<Type>::operator-(Type other) const
|
||||
{
|
||||
return V3D<Type>{this->x - other, this->y - other, this->z - other};
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
V3D<Type> V3D<Type>::operator-(const V3D<Type> &other) const
|
||||
{
|
||||
@@ -84,6 +97,13 @@ V3D<Type> V3D<Type>::operator/(Type scalar) const
|
||||
return V3D<Type>{this->x / scalar, this->y / scalar, this->z / scalar};
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
V3D<Type> &V3D<Type>::operator+=(Type other)
|
||||
{
|
||||
*this = *this + other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
V3D<Type> &V3D<Type>::operator+=(const V3D<Type> &other)
|
||||
{
|
||||
@@ -91,6 +111,13 @@ V3D<Type> &V3D<Type>::operator+=(const V3D<Type> &other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
V3D<Type> &V3D<Type>::operator-=(Type other)
|
||||
{
|
||||
*this = *this - other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
V3D<Type> &V3D<Type>::operator-=(const V3D<Type> &other)
|
||||
{
|
||||
|
||||
@@ -18,10 +18,15 @@ public:
|
||||
template <typename OtherType>
|
||||
V3D(const V3D<OtherType> &other);
|
||||
|
||||
template <typename OtherType>
|
||||
operator OtherType() const;
|
||||
|
||||
std::array<Type, 3> ToArray() const;
|
||||
|
||||
V3D<Type> operator+(Type other) const;
|
||||
V3D<Type> operator+(const V3D<Type> &other) const;
|
||||
|
||||
V3D<Type> operator-(Type other) const;
|
||||
V3D<Type> operator-(const V3D<Type> &other) const;
|
||||
|
||||
V3D<Type> operator*(Type scalar) const;
|
||||
@@ -30,8 +35,10 @@ public:
|
||||
|
||||
void operator=(const V3D<Type> &other);
|
||||
|
||||
V3D<Type> &operator+=(Type other);
|
||||
V3D<Type> &operator+=(const V3D<Type> &other);
|
||||
|
||||
V3D<Type> &operator-=(Type other);
|
||||
V3D<Type> &operator-=(const V3D<Type> &other);
|
||||
|
||||
V3D<Type> &operator/=(Type scalar);
|
||||
|
||||
Reference in New Issue
Block a user