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 00029 #include "csextern.h" 00030 00034 class CS_CSGEOM_EXPORT csVector2 00035 { 00036 public: 00038 float x; 00040 float y; 00041 00043 csVector2 () {} 00044 00046 csVector2 (float x, float y) { csVector2::x = x; csVector2::y = y; } 00047 00049 inline void Set (float ix, float iy) 00050 { x = ix; y = iy; } 00051 00053 inline void Set (const csVector2& v) 00054 { x = v.x; y = v.y; } 00055 00057 static float Norm (const csVector2& v); 00058 00060 float Norm () const; 00061 00063 float SquaredNorm () const 00064 { return x * x + y * y; } 00065 00067 void Rotate (float angle); 00068 00070 csVector2& operator+= (const csVector2& v) 00071 { x += v.x; y += v.y; return *this; } 00072 00074 csVector2& operator-= (const csVector2& v) 00075 { x -= v.x; y -= v.y; return *this; } 00076 00078 csVector2& operator*= (float f) { x *= f; y *= f; return *this; } 00079 00081 csVector2& operator/= (float f) { f = 1.0f / f; x *= f; y *= f; return *this; } 00082 00084 inline csVector2 operator+ () const { return *this; } 00085 00087 inline csVector2 operator- () const { return csVector2(-x,-y); } 00088 00090 friend CS_CSGEOM_EXPORT csVector2 operator+ (const csVector2& v1, 00091 const csVector2& v2); 00093 friend CS_CSGEOM_EXPORT csVector2 operator- (const csVector2& v1, 00094 const csVector2& v2); 00096 friend CS_CSGEOM_EXPORT float operator* (const csVector2& v1, 00097 const csVector2& v2); 00099 friend CS_CSGEOM_EXPORT csVector2 operator* (const csVector2& v, float f); 00101 friend CS_CSGEOM_EXPORT csVector2 operator* (float f, const csVector2& v); 00103 friend CS_CSGEOM_EXPORT csVector2 operator/ (const csVector2& v, float f); 00105 friend CS_CSGEOM_EXPORT bool operator== (const csVector2& v1, 00106 const csVector2& v2); 00108 friend CS_CSGEOM_EXPORT bool operator!= (const csVector2& v1, 00109 const csVector2& v2); 00110 00112 inline friend bool operator< (const csVector2& v, float f) 00113 { return ABS(v.x)<f && ABS(v.y)<f; } 00114 00116 inline friend bool operator> (float f, const csVector2& v) 00117 { return ABS(v.x)<f && ABS(v.y)<f; } 00118 }; 00119 00122 #endif // __CS_VECTOR2_H__
Generated for Crystal Space by doxygen 1.2.18