00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef HEADER_SUPERTUX_MATH_VECTOR_HPP
00018 #define HEADER_SUPERTUX_MATH_VECTOR_HPP
00019
00021 class Vector
00022 {
00023 public:
00024 Vector(float nx, float ny)
00025 : x(nx), y(ny)
00026 { }
00027 Vector(const Vector& other)
00028 : x(other.x), y(other.y)
00029 { }
00030 Vector()
00031 : x(0), y(0)
00032 { }
00033
00034 bool operator ==(const Vector& other) const
00035 {
00036 return x == other.x && y == other.y;
00037 }
00038
00039 bool operator !=(const Vector& other) const
00040 {
00041 return !(x == other.x && y == other.y);
00042 }
00043
00044 const Vector& operator=(const Vector& other)
00045 {
00046 x = other.x;
00047 y = other.y;
00048 return *this;
00049 }
00050
00051 Vector operator+(const Vector& other) const
00052 {
00053 return Vector(x + other.x, y + other.y);
00054 }
00055
00056 Vector operator-(const Vector& other) const
00057 {
00058 return Vector(x - other.x, y - other.y);
00059 }
00060
00061 Vector operator*(float s) const
00062 {
00063 return Vector(x * s, y * s);
00064 }
00065
00066 Vector operator/(float s) const
00067 {
00068 return Vector(x / s, y / s);
00069 }
00070
00071 Vector operator-() const
00072 {
00073 return Vector(-x, -y);
00074 }
00075
00076 const Vector& operator +=(const Vector& other)
00077 {
00078 x += other.x;
00079 y += other.y;
00080 return *this;
00081 }
00082
00083 const Vector& operator -=(const Vector& other)
00084 {
00085 x -= other.x;
00086 y -= other.y;
00087 return *this;
00088 }
00089
00090 const Vector& operator *=(float val)
00091 {
00092 x *= val;
00093 y *= val;
00094 return *this;
00095 }
00096
00097 const Vector& operator /=(float val)
00098 {
00099 x /= val;
00100 y /= val;
00101 return *this;
00102 }
00103
00105 float operator*(const Vector& other) const
00106 {
00107 return x*other.x + y*other.y;
00108 }
00109
00110 float norm() const;
00111 Vector unit() const;
00112
00113
00114
00115 float x, y;
00116
00117 };
00118
00119 #endif
00120
00121