- added 'Resized()' to TVector2 and fixed its const state for all vectors.

This commit is contained in:
Christoph Oelckers 2022-09-27 15:30:26 +02:00
parent a4ec938526
commit 2fe5655394

View file

@ -271,6 +271,19 @@ struct TVector2
return *this;
}
TVector2 Resized(double len) const
{
double vlen = Length();
if (vlen != 0.)
{
double scale = len / vlen;
return{ vec_t(X * scale), vec_t(Y * scale) };
}
else
{
return *this;
}
}
// Dot product
vec_t operator | (const TVector2 &other) const
@ -644,7 +657,7 @@ struct TVector3
return *this;
}
TVector3 Resized(double len)
TVector3 Resized(double len) const
{
double vlen = Length();
if (vlen != 0.)
@ -955,7 +968,7 @@ struct TVector4
return *this;
}
TVector4 Resized(double len)
TVector4 Resized(double len) const
{
double vlen = Length();
if (vlen != 0.)