matrix: Vector2/Vector4 override ops so specific Vector type is returned

- mirrored from Vector3
This commit is contained in:
Daniel Agar
2024-06-14 10:05:32 -04:00
parent 783cf9aede
commit c0d6b67633
2 changed files with 79 additions and 0 deletions
+39
View File
@@ -56,6 +56,45 @@ public:
return a(0) * b(1, 0) - a(1) * b(0, 0);
}
/**
* Override matrix ops so Vector2 type is returned
*/
Vector2 operator+(Vector2 other) const
{
return Matrix21::operator+(other);
}
Vector2 operator+(Type scalar) const
{
return Matrix21::operator+(scalar);
}
Vector2 operator-(Vector2 other) const
{
return Matrix21::operator-(other);
}
Vector2 operator-(Type scalar) const
{
return Matrix21::operator-(scalar);
}
Vector2 operator-() const
{
return Matrix21::operator-();
}
Vector2 operator*(Type scalar) const
{
return Matrix21::operator*(scalar);
}
Type operator*(Vector2 b) const
{
return Vector<Type, 2>::operator*(b);
}
Type operator%(const Matrix21 &b) const
{
return (*this).cross(b);
+40
View File
@@ -82,6 +82,46 @@ public:
Vector4(const Slice<Type, 1, 4, P, Q> &slice_in) : Vector<Type, 4>(slice_in)
{
}
/**
* Override matrix ops so Vector4 type is returned
*/
Vector4 operator+(Vector4 other) const
{
return Matrix41::operator+(other);
}
Vector4 operator+(Type scalar) const
{
return Matrix41::operator+(scalar);
}
Vector4 operator-(Vector4 other) const
{
return Matrix41::operator-(other);
}
Vector4 operator-(Type scalar) const
{
return Matrix41::operator-(scalar);
}
Vector4 operator-() const
{
return Matrix41::operator-();
}
Vector4 operator*(Type scalar) const
{
return Matrix41::operator*(scalar);
}
Type operator*(Vector4 b) const
{
return Vector<Type, 4>::operator*(b);
}
};
using Vector4f = Vector4<float>;