From ab2d9f002bb38cfd59fe9adc3787a9429be9fd66 Mon Sep 17 00:00:00 2001 From: Quinn Date: Tue, 4 Feb 2025 14:33:29 -0500 Subject: [PATCH] Added scalar addition / subtraction --- src/Vector3D.cpp | 27 +++++++++++++++++++++++++++ src/Vector3D.hpp | 7 +++++++ 2 files changed, 34 insertions(+) diff --git a/src/Vector3D.cpp b/src/Vector3D.cpp index ed06655..f882518 100644 --- a/src/Vector3D.cpp +++ b/src/Vector3D.cpp @@ -2,6 +2,7 @@ // will evaluate to true #include #include +#include template V3D::V3D(const Matrix<1, 3> &other) @@ -60,12 +61,24 @@ void V3D::operator=(const V3D &other) this->z = other.z; } +template +V3D V3D::operator+(Type other) const +{ + return V3D{this->x + other, this->y + other, this->z + other}; +} + template V3D V3D::operator+(const V3D &other) const { return V3D{this->x + other.x, this->y + other.y, this->z + other.z}; } +template +V3D V3D::operator-(Type other) const +{ + return V3D{this->x - other, this->y - other, this->z - other}; +} + template V3D V3D::operator-(const V3D &other) const { @@ -84,6 +97,13 @@ V3D V3D::operator/(Type scalar) const return V3D{this->x / scalar, this->y / scalar, this->z / scalar}; } +template +V3D &V3D::operator+=(Type other) +{ + *this = *this + other; + return *this; +} + template V3D &V3D::operator+=(const V3D &other) { @@ -91,6 +111,13 @@ V3D &V3D::operator+=(const V3D &other) return *this; } +template +V3D &V3D::operator-=(Type other) +{ + *this = *this - other; + return *this; +} + template V3D &V3D::operator-=(const V3D &other) { diff --git a/src/Vector3D.hpp b/src/Vector3D.hpp index be5f7b4..33477d0 100644 --- a/src/Vector3D.hpp +++ b/src/Vector3D.hpp @@ -18,10 +18,15 @@ public: template V3D(const V3D &other); + template + operator OtherType() const; + std::array ToArray() const; + V3D operator+(Type other) const; V3D operator+(const V3D &other) const; + V3D operator-(Type other) const; V3D operator-(const V3D &other) const; V3D operator*(Type scalar) const; @@ -30,8 +35,10 @@ public: void operator=(const V3D &other); + V3D &operator+=(Type other); V3D &operator+=(const V3D &other); + V3D &operator-=(Type other); V3D &operator-=(const V3D &other); V3D &operator/=(Type scalar);