Blender V2.61 - r43446

MT_Vector2.inl

Go to the documentation of this file.
00001 #include "MT_Optimize.h"
00002 
00003 GEN_INLINE MT_Vector2& MT_Vector2::operator+=(const MT_Vector2& vv) {
00004     m_co[0] += vv[0]; m_co[1] += vv[1];
00005     return *this;
00006 }
00007 
00008 GEN_INLINE MT_Vector2& MT_Vector2::operator-=(const MT_Vector2& vv) {
00009     m_co[0] -= vv[0]; m_co[1] -= vv[1];
00010     return *this;
00011 }
00012  
00013 GEN_INLINE MT_Vector2& MT_Vector2::operator*=(MT_Scalar s) {
00014     m_co[0] *= s; m_co[1] *= s;
00015     return *this;
00016 }
00017 
00018 GEN_INLINE MT_Vector2& MT_Vector2::operator/=(MT_Scalar s) {
00019     MT_assert(!MT_fuzzyZero(s));
00020     return *this *= 1.0 / s;
00021 }
00022 
00023 GEN_INLINE MT_Vector2 operator+(const MT_Vector2& v1, const MT_Vector2& v2) {
00024     return MT_Vector2(v1[0] + v2[0], v1[1] + v2[1]);
00025 }
00026 
00027 GEN_INLINE MT_Vector2 operator-(const MT_Vector2& v1, const MT_Vector2& v2) {
00028     return MT_Vector2(v1[0] - v2[0], v1[1] - v2[1]);
00029 }
00030 
00031 GEN_INLINE MT_Vector2 operator-(const MT_Vector2& v) {
00032     return MT_Vector2(-v[0], -v[1]);
00033 }
00034 
00035 GEN_INLINE MT_Vector2 operator*(const MT_Vector2& v, MT_Scalar s) {
00036     return MT_Vector2(v[0] * s, v[1] * s);
00037 }
00038 
00039 GEN_INLINE MT_Vector2 operator*(MT_Scalar s, const MT_Vector2& v) { return v * s; }
00040 
00041 GEN_INLINE MT_Vector2 operator/(const MT_Vector2& v, MT_Scalar s) {
00042     MT_assert(!MT_fuzzyZero(s));
00043     return v * (1.0 / s);
00044 }
00045 
00046 GEN_INLINE MT_Scalar MT_Vector2::dot(const MT_Vector2& vv) const {
00047     return m_co[0] * vv[0] + m_co[1] * vv[1];
00048 }
00049 
00050 GEN_INLINE MT_Scalar MT_Vector2::length2() const { return dot(*this); }
00051 GEN_INLINE MT_Scalar MT_Vector2::length() const { return sqrt(length2()); }
00052 
00053 GEN_INLINE MT_Vector2 MT_Vector2::absolute() const {
00054     return MT_Vector2(MT_abs(m_co[0]), MT_abs(m_co[1]));
00055 }
00056 
00057 GEN_INLINE bool MT_Vector2::fuzzyZero() const { return MT_fuzzyZero2(length2()); }
00058 
00059 GEN_INLINE void MT_Vector2::normalize() { *this /= length(); }
00060 GEN_INLINE MT_Vector2 MT_Vector2::normalized() const { return *this / length(); }
00061 
00062 GEN_INLINE void MT_Vector2::scale(MT_Scalar xx, MT_Scalar yy) {
00063     m_co[0] *= xx; m_co[1] *= yy; 
00064 }
00065 
00066 GEN_INLINE MT_Vector2 MT_Vector2::scaled(MT_Scalar xx, MT_Scalar yy) const {
00067     return MT_Vector2(m_co[0] * xx, m_co[1] * yy);
00068 }
00069 
00070 GEN_INLINE MT_Scalar MT_Vector2::angle(const MT_Vector2& vv) const {
00071     MT_Scalar s = sqrt(length2() * vv.length2());
00072     MT_assert(!MT_fuzzyZero(s));
00073     return acos(dot(vv) / s);
00074 }
00075 
00076 
00077 GEN_INLINE MT_Scalar  MT_dot(const MT_Vector2& v1, const MT_Vector2& v2) { 
00078     return v1.dot(v2);
00079 }
00080 
00081 GEN_INLINE MT_Scalar  MT_length2(const MT_Vector2& v) { return v.length2(); }
00082 GEN_INLINE MT_Scalar  MT_length(const MT_Vector2& v) { return v.length(); }
00083 
00084 GEN_INLINE bool       MT_fuzzyZero(const MT_Vector2& v) { return v.fuzzyZero(); }
00085 GEN_INLINE bool       MT_fuzzyEqual(const MT_Vector2& v1, const MT_Vector2& v2) { 
00086     return MT_fuzzyZero(v1 - v2); 
00087 }
00088 
00089 GEN_INLINE MT_Scalar  MT_angle(const MT_Vector2& v1, const MT_Vector2& v2) { return v1.angle(v2); }