Added scaling to SphericalOf<T>

This commit is contained in:
Pascal Serrarens 2024-08-28 09:18:50 +02:00
parent dedaa31740
commit b460bec696
2 changed files with 39 additions and 0 deletions

View File

@ -192,6 +192,18 @@ SphericalOf<T> SphericalOf<T>::operator+=(const SphericalOf<T>& v) {
return *this;
}
template <typename T>
SphericalOf<T> SphericalOf<T>::operator*=(float f) {
this->distance *= f;
return *this;
}
template <typename T>
SphericalOf<T> SphericalOf<T>::operator/=(float f) {
this->distance /= f;
return *this;
}
template class SphericalOf<float>;
template class SphericalOf<signed short>;

View File

@ -65,6 +65,33 @@ class SphericalOf {
/// @return The result of the addition
SphericalOf<T> operator+(const SphericalOf<T>& v) const;
SphericalOf<T> operator+=(const SphericalOf<T>& 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<T> operator*(const SphericalOf<T>& v, float f) {
return SphericalOf<T>(v.distance * f, v.horizontal, v.vertical);
}
friend SphericalOf<T> operator*(float f, const SphericalOf<T>& v) {
return SphericalOf<T>(v.distance * f, v.horizontal,
v.vertical); // not correct, should be f * v.distance
}
SphericalOf<T> 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<T> operator/(const SphericalOf<T>& v, float f) {
return SphericalOf<T>(v.distance / f, v.horizontal, v.vertical);
}
friend SphericalOf<T> operator/(float f, const SphericalOf<T>& v) {
return SphericalOf<T>(v.distance / f, v.horizontal,
v.vertical); // not correct, should be f / v.distance
}
SphericalOf<T> operator/=(float f);
};
using SphericalSingle = SphericalOf<float>;