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 (csVector2 const& v) 00054 { x = v.x; y = v.y; } 00055 00057 inline void Set (float const* v) { x = v[0]; y = v[1]; } 00058 00060 inline void Set (float v) { x = y = v; } 00061 00063 inline void Get (float* v) { v[0] = x; v[1] = y; } 00064 00066 static float Norm (csVector2 const& v); 00067 00069 float Norm () const; 00070 00072 float SquaredNorm () const 00073 { return x * x + y * y; } 00074 00076 void Rotate (float angle); 00077 00079 csVector2& operator+= (const csVector2& v) 00080 { x += v.x; y += v.y; return *this; } 00081 00083 csVector2& operator-= (const csVector2& v) 00084 { x -= v.x; y -= v.y; return *this; } 00085 00087 csVector2& operator*= (float f) { x *= f; y *= f; return *this; } 00088 00090 csVector2& operator/= (float f) { f = 1.0f / f; x *= f; y *= f; return *this; } 00091 00093 inline csVector2 operator+ () const { return *this; } 00094 00096 inline csVector2 operator- () const { return csVector2(-x,-y); } 00097 00099 friend CS_CSGEOM_EXPORT csVector2 operator+ (const csVector2& v1, 00100 const csVector2& v2); 00102 friend CS_CSGEOM_EXPORT csVector2 operator- (const csVector2& v1, 00103 const csVector2& v2); 00105 friend CS_CSGEOM_EXPORT float operator* (const csVector2& v1, 00106 const csVector2& v2); 00108 friend CS_CSGEOM_EXPORT csVector2 operator* (const csVector2& v, float f); 00110 friend CS_CSGEOM_EXPORT csVector2 operator* (float f, const csVector2& v); 00112 friend CS_CSGEOM_EXPORT csVector2 operator/ (const csVector2& v, float f); 00114 friend CS_CSGEOM_EXPORT bool operator== (const csVector2& v1, 00115 const csVector2& v2); 00117 friend CS_CSGEOM_EXPORT bool operator!= (const csVector2& v1, 00118 const csVector2& v2); 00119 00121 inline friend bool operator< (const csVector2& v, float f) 00122 { return ABS(v.x)<f && ABS(v.y)<f; } 00123 00125 inline friend bool operator> (float f, const csVector2& v) 00126 { return ABS(v.x)<f && ABS(v.y)<f; } 00127 }; 00128 00131 #endif // __CS_VECTOR2_H__
Generated for Crystal Space by doxygen 1.2.18
