2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef HEADER_SUPERTUX_MATH_VECTOR_HPP
18 #define HEADER_SUPERTUX_MATH_VECTOR_HPP
20 /** Simple two dimensional vector. */
24 Vector(float nx, float ny)
27 Vector(const Vector& other)
28 : x(other.x), y(other.y)
34 bool operator ==(const Vector& other) const
36 return x == other.x && y == other.y;
39 bool operator !=(const Vector& other) const
41 return !(x == other.x && y == other.y);
44 const Vector& operator=(const Vector& other)
51 Vector operator+(const Vector& other) const
53 return Vector(x + other.x, y + other.y);
56 Vector operator-(const Vector& other) const
58 return Vector(x - other.x, y - other.y);
61 Vector operator*(float s) const
63 return Vector(x * s, y * s);
66 Vector operator/(float s) const
68 return Vector(x / s, y / s);
71 Vector operator-() const
73 return Vector(-x, -y);
76 const Vector& operator +=(const Vector& other)
83 const Vector& operator -=(const Vector& other)
90 const Vector& operator *=(float val)
97 const Vector& operator /=(float val)
104 /// Scalar product of 2 vectors
105 float operator*(const Vector& other) const
107 return x*other.x + y*other.y;
113 // ... add the other operators as needed, I'm too lazy now ...
115 float x, y; // leave this public, get/set methods just give me headaches
116 // for such simple stuff :)