diff --git a/Spherical.cpp b/Spherical.cpp index 744b654..69e2d9f 100644 --- a/Spherical.cpp +++ b/Spherical.cpp @@ -192,6 +192,18 @@ SphericalOf SphericalOf::operator+=(const SphericalOf& v) { return *this; } +template +SphericalOf SphericalOf::operator*=(float f) { + this->distance *= f; + return *this; +} + +template +SphericalOf SphericalOf::operator/=(float f) { + this->distance /= f; + return *this; +} + template class SphericalOf; template class SphericalOf; diff --git a/Spherical.h b/Spherical.h index 47c14bc..3926b5d 100644 --- a/Spherical.h +++ b/Spherical.h @@ -65,6 +65,33 @@ class SphericalOf { /// @return The result of the addition SphericalOf operator+(const SphericalOf& v) const; SphericalOf operator+=(const SphericalOf& v); + + /// @brief Scale the vector uniformly up + /// @param f The scaling factor + /// @return The scaled vector + /// @remark This operation will scale the distance of the vector. The angle + /// will be unaffected. + friend SphericalOf operator*(const SphericalOf& v, float f) { + return SphericalOf(v.distance * f, v.horizontal, v.vertical); + } + friend SphericalOf operator*(float f, const SphericalOf& v) { + return SphericalOf(v.distance * f, v.horizontal, + v.vertical); // not correct, should be f * v.distance + } + SphericalOf operator*=(float f); + /// @brief Scale the vector uniformly down + /// @param f The scaling factor + /// @return The scaled factor + /// @remark This operation will scale the distance of the vector. The angle + /// will be unaffected. + friend SphericalOf operator/(const SphericalOf& v, float f) { + return SphericalOf(v.distance / f, v.horizontal, v.vertical); + } + friend SphericalOf operator/(float f, const SphericalOf& v) { + return SphericalOf(v.distance / f, v.horizontal, + v.vertical); // not correct, should be f / v.distance + } + SphericalOf operator/=(float f); }; using SphericalSingle = SphericalOf;