![]() |
The Agent Tool
1.01
An Agent Based Graphic Sound Synthesis Environment
|
00001 #ifndef __VEC2_HPP__ 00002 #define __VEC2_HPP__ 00003 00004 00005 00021 class Vec2{ 00022 float m_x,m_y; 00023 public: 00025 Vec2.new():m_x(0),m_y(0){} 00027 Vec2.new(float x, float y): 00029 Vec2.new(int x, int y): 00031 float x(); 00032 00034 float x(); 00035 00037 00039 Vec2 operator + (Vec2 r); 00041 00043 Vec2 operator + (float r ); 00045 00047 Vec2 operator + (int r ); 00049 00051 Vec2 operator - (Vec2 r); 00053 00055 Vec2 operator - (float r ); 00057 00059 Vec2 operator - (int r ); 00061 00063 Vec2 operator * (float r ); 00065 00067 Vec2 operator * (int r ); 00069 00071 Vec2 operator / (float r ); 00074 float mag(); 00077 Vec2 norm(); 00080 Vec2 perp(); 00084 float dot(const Vec2& v )const{ 00085 return(m_x*v.m_x+m_y*v.m_y); 00086 } 00087 bool operator == (const Vec2& r)const{ 00088 return m_x == r.m_x && m_y == r.m_y; 00089 } 00090 }; 00091 00092 00093 00094 inline Vec2 operator * (const float& l, const Vec2& r){ 00095 return r*l; 00096 } 00097 00098 inline Vec2 operator + (const float& l, const Vec2& r){ 00099 return r+l; 00100 } 00102 inline float dot (const Vec2& u, const Vec2& v){ 00103 return u.dot(v); 00104 } 00105 00106 inline std::ostream& operator << (std::ostream& s, const Vec2& op){ 00107 s << "<" << op.m_x << "," << op.m_y << ">"; 00108 return s; 00109 } 00110 inline bool test_tol(float a,float b){ 00111 return fabs( a-b )<0.0001; 00112 } 00113 inline bool test_vector_tol(Vec2 a,Vec2 b){ 00114 return test_tol(a.m_x,b.m_x) && test_tol(a.m_y,b.m_y); 00115 } 00116 00117 inline void test_vec2(){ 00118 Vec2 t; 00119 assert(t + 10 == Vec2(10,10)); 00120 Vec2 t2(10,5); 00121 Vec2 t3(1,2); 00122 assert(t3+t2 == Vec2(11,7)); 00123 assert(t2*2 == Vec2(20,10)); 00124 assert(t2/2 == Vec2(5,2.5)); 00125 assert(test_tol( t2.dot(t3),20 )); 00126 assert(test_tol( t2.magnitude() , sqrt(125) )); 00127 assert( test_vector_tol(t2.normalise() , t2/t2.magnitude())); 00128 } 00129 00130 00131 00132 #endif