Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
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 #include "csutil/csstring.h" 00031 00035 class CS_CSGEOM_EXPORT csVector2 00036 { 00037 public: 00039 float x; 00041 float y; 00042 00044 csVector2 () {} 00045 00047 csVector2 (float x, float y) { csVector2::x = x; csVector2::y = y; } 00048 00050 csString Description() const; 00051 00053 inline void Set (float ix, float iy) 00054 { x = ix; y = iy; } 00055 00057 inline void Set (csVector2 const& v) 00058 { x = v.x; y = v.y; } 00059 00061 inline void Set (float const* v) { x = v[0]; y = v[1]; } 00062 00064 inline void Set (float v) { x = y = v; } 00065 00067 inline void Get (float* v) { v[0] = x; v[1] = y; } 00068 00070 static float Norm (csVector2 const& v); 00071 00073 float Norm () const; 00074 00076 float SquaredNorm () const 00077 { return x * x + y * y; } 00078 00080 void Rotate (float angle); 00081 00086 float IsLeft (const csVector2& p0, const csVector2& p1) 00087 { 00088 return (p1.x - p0.x)*(y - p0.y) - (x - p0.x)*(p1.y - p0.y); 00089 } 00090 00092 csVector2& operator+= (const csVector2& v) 00093 { x += v.x; y += v.y; return *this; } 00094 00096 csVector2& operator-= (const csVector2& v) 00097 { x -= v.x; y -= v.y; return *this; } 00098 00100 csVector2& operator*= (float f) { x *= f; y *= f; return *this; } 00101 00103 csVector2& operator/= (float f) 00104 { 00105 f = 1.0f / f; 00106 x *= f; 00107 y *= f; 00108 return *this; 00109 } 00110 00112 inline csVector2 operator+ () const { return *this; } 00113 00115 inline csVector2 operator- () const { return csVector2(-x,-y); } 00116 00118 friend CS_CSGEOM_EXPORT csVector2 operator+ (const csVector2& v1, 00119 const csVector2& v2); 00121 friend CS_CSGEOM_EXPORT csVector2 operator- (const csVector2& v1, 00122 const csVector2& v2); 00124 friend CS_CSGEOM_EXPORT float operator* (const csVector2& v1, 00125 const csVector2& v2); 00127 friend CS_CSGEOM_EXPORT csVector2 operator* (const csVector2& v, float f); 00129 friend CS_CSGEOM_EXPORT csVector2 operator* (float f, const csVector2& v); 00131 friend CS_CSGEOM_EXPORT csVector2 operator/ (const csVector2& v, float f); 00133 friend CS_CSGEOM_EXPORT bool operator== (const csVector2& v1, 00134 const csVector2& v2); 00136 friend CS_CSGEOM_EXPORT bool operator!= (const csVector2& v1, 00137 const csVector2& v2); 00138 00140 inline friend bool operator< (const csVector2& v, float f) 00141 { return ABS(v.x)<f && ABS(v.y)<f; } 00142 00144 inline friend bool operator> (float f, const csVector2& v) 00145 { return ABS(v.x)<f && ABS(v.y)<f; } 00146 }; 00147 00150 #endif // __CS_VECTOR2_H__
Generated for Crystal Space by doxygen 1.3.9.1