csgeom/vector2.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2000 by Jorrit Tyberghein 00003 Largely rewritten by Ivan Avramovic <ivan@avramovic.com> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_VECTOR2_H__ 00021 #define __CS_VECTOR2_H__ 00022 00032 class csVector2 00033 { 00034 public: 00036 float x; 00038 float y; 00039 00041 csVector2 () {} 00042 00044 csVector2 (float x, float y) { csVector2::x = x; csVector2::y = y; } 00045 00047 inline void Set (float ix, float iy) 00048 { x = ix; y = iy; } 00049 00051 inline void Set (const csVector2& v) 00052 { x = v.x; y = v.y; } 00053 00055 static float Norm (const csVector2& v); 00056 00058 float Norm () const; 00059 00061 float SquaredNorm () const 00062 { return x * x + y * y; } 00063 00065 void Rotate (float angle); 00066 00068 csVector2& operator+= (const csVector2& v) 00069 { x += v.x; y += v.y; return *this; } 00070 00072 csVector2& operator-= (const csVector2& v) 00073 { x -= v.x; y -= v.y; return *this; } 00074 00076 csVector2& operator*= (float f) { x *= f; y *= f; return *this; } 00077 00079 csVector2& operator/= (float f) { f = 1.0f / f; x *= f; y *= f; return *this; } 00080 00082 inline csVector2 operator+ () const { return *this; } 00083 00085 inline csVector2 operator- () const { return csVector2(-x,-y); } 00086 00088 friend csVector2 operator+ (const csVector2& v1, const csVector2& v2); 00090 friend csVector2 operator- (const csVector2& v1, const csVector2& v2); 00092 friend float operator* (const csVector2& v1, const csVector2& v2); 00094 friend csVector2 operator* (const csVector2& v, float f); 00096 friend csVector2 operator* (float f, const csVector2& v); 00098 friend csVector2 operator/ (const csVector2& v, float f); 00100 friend bool operator== (const csVector2& v1, const csVector2& v2); 00102 friend bool operator!= (const csVector2& v1, const csVector2& v2); 00103 00105 inline friend bool operator< (const csVector2& v, float f) 00106 { return ABS(v.x)<f && ABS(v.y)<f; } 00107 00109 inline friend bool operator> (float f, const csVector2& v) 00110 { return ABS(v.x)<f && ABS(v.y)<f; } 00111 }; 00112 00115 #endif // __CS_VECTOR2_H__
Generated for Crystal Space by doxygen 1.2.18