00001 #ifndef __VEC2__
00002 #define __VEC2__
00003
00004 #include <QString>
00005 #include <QDomElement>
00006 #include <QDomDocument>
00007
00008
00009 namespace apig {
00010 class Vec3;
00011
00013 class Vec2 {
00014 public:
00015 Vec2(float x, float y);
00016 Vec2(float c = 0);
00017 Vec2(const float *v);
00018 Vec2(const QDomElement &element);
00019
00020
00021
00022
00023 inline operator const float* () const { return v; }
00024 inline operator float* () { return v; }
00025
00026 QString toQString() const;
00027
00028 void initFromDOMElement(const QDomElement &element);
00029 QDomElement domElement(const QString &name, QDomDocument &document) const;
00030
00031
00032
00033 float norm() const;
00034 float norm2() const;
00035 void normalize();
00036 Vec2 normalized() const;
00037
00038 friend float dist(Vec2 v1, Vec2 v2);
00039
00040 friend float dot(const Vec2 &a, const Vec2 &b);
00041 friend Vec3 vec(const Vec2 &a, const Vec2 &b);
00042 friend float vecz(const Vec2 &a, const Vec2 &b);
00043 friend float operator|(const Vec2 &a, const Vec2 &b);
00044 friend Vec3 operator^(const Vec2 &a, const Vec2 &b);
00045
00046 float arg() const;
00047 Vec2 polar() const;
00048
00049
00050
00051
00052 friend Vec2 operator-(const Vec2 &a);
00053
00054
00055 friend Vec2 operator+(const Vec2 &a, const Vec2 &b);
00056 friend Vec2 operator-(const Vec2 &a, const Vec2 &b);
00057 friend Vec2 operator*(const Vec2 &a, const Vec2 &b);
00058 friend Vec2 operator/(const Vec2 &a, const Vec2 &b);
00059
00060
00061 friend Vec2 operator*(float s, const Vec2 &a);
00062 friend Vec2 operator*(const Vec2 &a, float s);
00063 friend Vec2 operator/(float s, const Vec2 &a);
00064 friend Vec2 operator/(const Vec2 &a, float s);
00065
00066
00067 Vec2& operator+=(const Vec2 &a);
00068 Vec2& operator-=(const Vec2 &a);
00069 Vec2& operator*=(const Vec2 &a);
00070 Vec2& operator/=(const Vec2 &a);
00071 Vec2& operator*=(float s);
00072 Vec2& operator/=(float s);
00073
00074
00075
00076 friend bool operator==(const Vec2 &a, const Vec2 &b);
00077 friend bool operator!=(const Vec2 &a, const Vec2 &b);
00078
00079 friend bool operator>=(const Vec2 &a, const Vec2 &b);
00080 friend bool operator<=(const Vec2 &a, const Vec2 &b);
00081 friend bool operator>(const Vec2 &a, const Vec2 &b);
00082 friend bool operator<(const Vec2 &a, const Vec2 &b);
00083 friend bool operator>=(const Vec2 &a, float b);
00084 friend bool operator<=(const Vec2 &a, float b);
00085 friend bool operator>(const Vec2 &a, float b);
00086 friend bool operator<(const Vec2 &a, float b);
00087
00088
00089
00090 friend Vec2 abs(const Vec2 &a);
00091 friend Vec2 sign(const Vec2 &a);
00092 friend Vec2 floor(const Vec2 &a);
00093 friend Vec2 ceil(const Vec2 &a);
00094 friend Vec2 fract(const Vec2 &a);
00095 friend Vec2 min(const Vec2 &a, const Vec2 &b);
00096 friend Vec2 min(const Vec2 &a, float b);
00097 friend Vec2 max(const Vec2 &a, const Vec2 &b);
00098 friend Vec2 max(const Vec2 &a, float b);
00099 friend Vec2 clamp(const Vec2 &a, const Vec2 &min, const Vec2 &max);
00100 friend Vec2 clamp(const Vec2 &a, float min, float max);
00101 friend Vec2 mix(const Vec2 &a, const Vec2 &b, const Vec2 &alpha);
00102 friend Vec2 mix(const Vec2 &a, const Vec2 &b, float alpha);
00103 friend Vec2 step(const Vec2 &e, const Vec2 &a);
00104 friend Vec2 step(float e, const Vec2 &a);
00105 friend float min(const Vec2 &a);
00106 friend float max(const Vec2 &a);
00107
00108
00109
00110 static Vec2 random();
00111 static Vec2 random(float min, float max);
00112 static Vec2 random(Vec2 min, Vec2 max);
00113
00114
00115
00116 void glVertex() const;
00117
00118 public:
00119 union {
00120 struct { float x, y; };
00121 float v[2];
00122 };
00123 };
00124
00125 }
00126
00127 #endif
00128