/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: src/sgx/core/math/vector2.cpp

*/

#include "sgx/core/math/math.hpp"

sgxVector2 sgxVector2::Null(0,0);
sgxVector2 sgxVector2::Origin(0,0);
sgxVector2 sgxVector2::UnitX(1,0);
sgxVector2 sgxVector2::UnitY(0,1);
sgxVector2 sgxVector2::UnitMinusX(-1,0);
sgxVector2 sgxVector2::UnitMinusY(0,-1);

void
sgxVector2::rotate(const sgxVector2 &centre, const tREAL32 theta)
{
	if (theta) {
		tREAL32 length = getDistance(centre);
		tREAL32 dx = x - centre.x;
		tREAL32 dy = y - centre.y;
		
		tREAL32 angle = sgxAtan2(dx, dy) - SGX_PI2;

		angle += theta;

		x = sgxCos(angle) * length + centre.x;
		y = -sgxSin(angle) * length + centre.y;
	}
}

