// $Id: vector2f.cpp 2986 2007-08-17 16:20:09Z grumbel $ // // SuperTux - A Jump'n Run // Copyright (C) 2004 Matthias Braun #include #include #include "math/vector2f.hpp" void Vector2f::normalize() { float mag = magnitude(); x /= mag; y /= mag; } Vector2f Vector2f::unit() const { return *this / magnitude(); } float Vector2f::magnitude() const { return sqrt(x*x + y*y); } std::ostream& operator<<(std::ostream& s, const Vector2f& v) { s << "(" << v.x << ", " << v.y << ")"; return s; } Vector2f Vector2f::rotate(float angle) const { float len = magnitude(); return Vector2f(len * cos(angle), len * sin(angle)); } /* EOF */