Wm4Vector2.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef WM4VECTOR2_H
00018 #define WM4VECTOR2_H
00019
00020 #include "Wm4FoundationLIB.h"
00021 #include "Wm4Math.h"
00022
00023 namespace Wm4
00024 {
00025 template <class Real>
00026 class Vector2
00027 {
00028 public:
00029
00030 Vector2 ();
00031 Vector2 (Real fX, Real fY);
00032 Vector2 (const Real* afTuple);
00033 Vector2 (const Vector2& rkV);
00034
00035
00036 operator const Real* () const;
00037 operator Real* ();
00038 Real operator[] (int i) const;
00039 Real& operator[] (int i);
00040 Real X () const;
00041 Real& X ();
00042 Real Y () const;
00043 Real& Y ();
00044
00045
00046 Vector2& operator= (const Vector2& rkV);
00047
00048
00049 bool operator== (const Vector2& rkV) const;
00050 bool operator!= (const Vector2& rkV) const;
00051 bool operator< (const Vector2& rkV) const;
00052 bool operator<= (const Vector2& rkV) const;
00053 bool operator> (const Vector2& rkV) const;
00054 bool operator>= (const Vector2& rkV) const;
00055
00056
00057 Vector2 operator+ (const Vector2& rkV) const;
00058 Vector2 operator- (const Vector2& rkV) const;
00059 Vector2 operator* (Real fScalar) const;
00060 Vector2 operator/ (Real fScalar) const;
00061 Vector2 operator- () const;
00062
00063
00064 Vector2& operator+= (const Vector2& rkV);
00065 Vector2& operator-= (const Vector2& rkV);
00066 Vector2& operator*= (Real fScalar);
00067 Vector2& operator/= (Real fScalar);
00068
00069
00070 Real Length () const;
00071 Real SquaredLength () const;
00072 Real Dot (const Vector2& rkV) const;
00073 Real Normalize ();
00074
00075
00076 Vector2 Perp () const;
00077
00078
00079 Vector2 UnitPerp () const;
00080
00081
00082 Real DotPerp (const Vector2& rkV) const;
00083
00084
00085
00086 void GetBarycentrics (const Vector2& rkV0, const Vector2& rkV1,
00087 const Vector2& rkV2, Real afBary[3]) const;
00088
00089
00090
00091
00092 static void Orthonormalize (Vector2& rkU, Vector2& rkV);
00093
00094
00095
00096
00097 static void GenerateOrthonormalBasis (Vector2& rkU, Vector2& rkV);
00098
00099
00100 static void ComputeExtremes (int iVQuantity, const Vector2* akPoint,
00101 Vector2& rkMin, Vector2& rkMax);
00102
00103
00104 WM4_FOUNDATION_ITEM static const Vector2 ZERO;
00105 WM4_FOUNDATION_ITEM static const Vector2 UNIT_X;
00106 WM4_FOUNDATION_ITEM static const Vector2 UNIT_Y;
00107 WM4_FOUNDATION_ITEM static const Vector2 ONE;
00108
00109 private:
00110
00111 int CompareArrays (const Vector2& rkV) const;
00112
00113 Real m_afTuple[2];
00114 };
00115
00116
00117 template <class Real>
00118 Vector2<Real> operator* (Real fScalar, const Vector2<Real>& rkV);
00119
00120
00121 template <class Real>
00122 std::ostream& operator<< (std::ostream& rkOStr, const Vector2<Real>& rkV);
00123
00124 }
00125
00126 #include "Wm4Vector2.inl"
00127
00128 namespace Wm4
00129 {
00130 typedef Vector2<float> Vector2f;
00131 typedef Vector2<double> Vector2d;
00132
00133 }
00134
00135 #endif