X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fmath%2Fvector.h;h=31b171d691a03cdbd6d48028e475700724befbb7;hb=495f8b77cb935fe8eff81bec755efca8e34e8a99;hp=b9334544553616df928ad306da55ea65839fe4ff;hpb=9c511ea692d3a2339597211f08f18ea74fad35ec;p=supertux.git diff --git a/lib/math/vector.h b/lib/math/vector.h index b93345445..31b171d69 100644 --- a/lib/math/vector.h +++ b/lib/math/vector.h @@ -1,7 +1,7 @@ // $Id$ // // SuperTux - A Jump'n Run -// Copyright (C) 2004 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -20,77 +20,103 @@ #ifndef SUPERTUX_VECTOR_H #define SUPERTUX_VECTOR_H -class Vector -{ -public: - Vector(float nx, float ny) - : x(nx), y(ny) - { } - Vector(const Vector& other) - : x(other.x), y(other.y) - { } - Vector() - : x(0), y(0) - { } - - bool operator ==(const Vector& other) const +namespace SuperTux { - return x == other.x && y == other.y; - } - const Vector& operator=(const Vector& other) - { - x = other.x; - y = other.y; - return *this; - } - - Vector operator+(const Vector& other) const - { - return Vector(x + other.x, y + other.y); - } - - Vector operator-(const Vector& other) const - { - return Vector(x - other.x, y - other.y); - } - - Vector operator*(float s) const - { - return Vector(x * s, y * s); - } - - Vector operator/(float s) const - { - return Vector(x / s, y / s); - } - - Vector operator-() const - { - return Vector(-x, -y); - } - - const Vector& operator +=(const Vector& other) - { - x += other.x; - y += other.y; - return *this; - } - - // scalar product of 2 vectors - float operator*(const Vector& other) const - { - return x*other.x + y*other.y; - } - - float norm() const; - Vector unit() const; - - // ... add the other operators as needed, I'm too lazy now ... - - float x, y; // leave this public, get/set methods just give me headaches - // for such simple stuff :) -}; + /// 2D Vector. + /** Simple two dimensional vector. */ + class Vector + { + public: + Vector(float nx, float ny) + : x(nx), y(ny) + { } + Vector(const Vector& other) + : x(other.x), y(other.y) + { } + Vector() + : x(0), y(0) + { } + + bool operator ==(const Vector& other) const + { + return x == other.x && y == other.y; + } + + bool operator !=(const Vector& other) const + { + return !(x == other.x && y == other.y); + } + + const Vector& operator=(const Vector& other) + { + x = other.x; + y = other.y; + return *this; + } + + Vector operator+(const Vector& other) const + { + return Vector(x + other.x, y + other.y); + } + + Vector operator-(const Vector& other) const + { + return Vector(x - other.x, y - other.y); + } + + Vector operator*(float s) const + { + return Vector(x * s, y * s); + } + + Vector operator/(float s) const + { + return Vector(x / s, y / s); + } + + Vector operator-() const + { + return Vector(-x, -y); + } + + const Vector& operator +=(const Vector& other) + { + x += other.x; + y += other.y; + return *this; + } + + const Vector& operator *=(float val) + { + x *= val; + y *= val; + return *this; + } + + const Vector& operator /=(float val) + { + x /= val; + y /= val; + return *this; + } + + /// Scalar product of 2 vectors + float operator*(const Vector& other) const + { + return x*other.x + y*other.y; + } + + float norm() const; + Vector unit() const; + + // ... add the other operators as needed, I'm too lazy now ... + + float x, y; // leave this public, get/set methods just give me headaches + // for such simple stuff :) + }; + +} //namespace SuperTux #endif /*SUPERTUX_VECTOR_H*/