Commit b4acfda1 authored by louiz’'s avatar louiz’

Fix the Vec2::set_length method to avoid division by zero

parent 7ca8541f
......@@ -106,9 +106,11 @@ public:
// Change the vector's length but keep the same direction.
void set_length(Fix16 new_length)
{
Fix16 mult = this->length() / new_length;
this->x /= mult;
this->y /= mult;
if (this->length() == 0)
return;
Fix16 mult = new_length / this->length();
this->x *= mult;
this->y *= mult;
}
// Returns one of the two perpendicular vectors.
Vec2 perpendicular1() const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment