/* Moonfall Copyright (C) 2008 Alex Yatskov This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ template Vector2::Vector2(const Vector2& vector) : x(0), y(0) { *this = vector; } template Vector2::Vector2(T x, T y) : x(x), y(y) { } template Vector2::Vector2(T v) : x(v), y(v) { } template Vector2::Vector2() : x(0), y(0) { } template bool Vector2::operator ==(const Vector2& vector) const { return x == vector.x && y == vector.y; } template bool Vector2::operator !=(const Vector2& vector) const { return !(*this == vector); } template Vector2 Vector2::operator +(const Vector2& vector) const { return Vector2(x + vector.x, y + vector.y); } template Vector2 Vector2::operator -(const Vector2& vector) const { return Vector2(x - vector.x, y - vector.y); } template Vector2 Vector2::operator *(T scalar) const { return Vector2(x * scalar, y * scalar); } template Vector2 Vector2::operator /(T scalar) const { return Vector2(x / scalar, y / scalar); } template Vector2& Vector2::operator +=(const Vector2& vector) { *this = *this + vector; return *this; } template Vector2& Vector2::operator -=(const Vector2& vector) { *this = *this - vector; return *this; } template Vector2& Vector2::operator *=(T scalar) { *this = *this * scalar; return *this; } template Vector2& Vector2::operator /=(T scalar) { *this = *this / scalar; return *this; } template Vector2& Vector2::operator =(const Vector2& vector) { if (this != &vector) { x = vector.x; y = vector.y; } return *this; } template Vector2 Vector2::operator -()const { return Vector2(-x, -y); } template Vector2& VectorMixMath::Normalize() { Vector2* const vector = static_cast *>(this); const float length = vector->GetLength(); if (length > 0) { *(vector) /= length; } else { *(vector) = Vector2(0, 0); } return *vector; } template Vector2 VectorMixMath::Normalized() const { Vector2 vector = *static_cast *>(this); vector.Normalize(); return vector; } template T VectorMixMath::GetLength() const { const Vector2* const vector = static_cast *>(this); return static_cast(sqrt(vector->x * vector->x + vector->y * vector->y)); }