Implement Vector-to-Vector Multiplication + division

This commit is contained in:
2024-01-29 14:43:51 -05:00
parent 47b25c695f
commit e76a0954d3
2 changed files with 10 additions and 4 deletions

View File

@@ -112,16 +112,18 @@ namespace LinearAlgebra {
/// Multiplies this vector by a vector, element-wise /// Multiplies this vector by a vector, element-wise
/// @note Mathematically, the multiplication of two vectors is not defined in linear space structures, /// @note Mathematically, the multiplication of two vectors is not defined in linear space structures,
/// but this function is provided here for syntactical convenience. /// but this function is provided here for syntactical convenience.
Vector2 Mul(const Vector2& v) const Vector2 Mul(const Vector2& v) const;
{
return {this->x*v.x, this->y*v.y};
}
/// Divides this vector by a scalar. /// Divides this vector by a scalar.
Vector2 operator /(float rhs) const; Vector2 operator /(float rhs) const;
Vector2 Div(float scalar) const; Vector2 Div(float scalar) const;
static Vector2 Div(const Vector2& lhs, float rhs); static Vector2 Div(const Vector2& lhs, float rhs);
/// Divides this vector by a vector, element-wise
/// @note Mathematically, the multiplication of two vectors is not defined in linear space structures,
/// but this function is provided here for syntactical convenience
Vector2 Div(const Vector2& v) const;
/// Unary operator + /// Unary operator +
Vector2 operator +() const; // TODO: Implement Vector2 operator +() const; // TODO: Implement
Vector2 operator -() const; Vector2 operator -() const;

View File

@@ -243,5 +243,9 @@ namespace LinearAlgebra {
return std::max(x, y); return std::max(x, y);
} }
Vector2 Vector2::Mul(const Vector2 &v) const {
return {this->x*v.x, this->y*v.y};
}
} }