_Tuple3.cc

Go to the documentation of this file.
00001 
00002 #include <vecmath/_Tuple3.h>
00003 
00004 template <class Type>
00005 void _Tuple3<Type>::clamp(Type min, Type max, const _Tuple3<Type>& t)
00006 {
00007     DEBUGTUPLE3(std::cout << "_Tuple3 clamp( " << min << ", " << max
00008                 << ", " << t << " )");
00009     if (t.x < min)
00010         x = min;
00011     else if (t.x > max)
00012         x = max;
00013     else
00014         x = t.x;
00015 
00016     if (t.y < min)
00017         y = min;
00018     else if (t.y > max)
00019         y = max;
00020     else
00021         y = t.y;
00022 
00023     if (t.z < min)
00024         z = min;
00025     else if (t.z > max)
00026         z = max;
00027     else
00028         z = t.z;
00029 
00030     DEBUGTUPLE3(std::cout << " = " << *this << std::endl);
00031 }
00032 
00033 template <class Type>
00034 void _Tuple3<Type>::clampMax(Type max, const _Tuple3<Type>& t)
00035 {
00036     DEBUGTUPLE3(cout << "_Tuple3 clampMax( " << max << ", " << t << " ) ");
00037     x = (t.x > max) ? max : t.x;
00038     y = (t.y > max) ? max : t.y;
00039     z = (t.z > max) ? max : t.z;
00040     DEBUGTUPLE3(std::cout << " = " << *this << std::endl);
00041 }
00042 
00043 template <class Type>
00044 void _Tuple3<Type>::clampMin(Type min, const _Tuple3<Type>& t)
00045 {
00046     DEBUGTUPLE3(std::cout << "_Tuple3 clampMin( " << min << ", " << t << " ) ");
00047     x = (t.x < min) ? min : t.x;
00048     y = (t.y < min) ? min : t.y;
00049     z = (t.z < min) ? min : t.z;
00050     DEBUGTUPLE3(std::cout << " = " << *this << std::endl);
00051 }
00052 
00053 template <class Type>
00054 void _Tuple3<Type>::interpolate(_Tuple3<Type> &t1, const _Tuple3<Type> &t2, double alpha)
00055 {
00056     x = Type((1.0 - alpha) * t1.x + alpha * t2.x);
00057     y = Type((1.0 - alpha) * t1.y + alpha * t2.y);
00058     z = Type((1.0 - alpha) * t1.z + alpha * t2.z);
00059 }
00060 
00061 #if 0   
00062 String& _Tuple3<byte>::toString(String &s)
00063 {
00064     char a[200];
00065     sprintf(a, "x: %d   y: %d   z: %d", x, y, z);
00066     //s += a;
00067     return s;
00068 }
00069 
00070 String& _Tuple3<double>::toString(String &s)
00071 {
00072     char a[200];
00073     sprintf(a, "x: %f   y: %f   z: %f", x, y, z);
00074     //s += a;
00075     return s;
00076 }
00077 
00078 String& _Tuple3<float>::toString(String &s)
00079 {
00080     char a[200];
00081     sprintf(a, "x: %f   y: %f   z: %f", x, y, z);
00082     //s += a;
00083     return s;
00084 }
00085 
00086 String& _Tuple3<int>::toString(String &s)
00087 {
00088     char a[200];
00089     sprintf(a, "x: %d   y: %d   z: %d", x, y, z);
00090     //s += a;
00091     return s;
00092 }
00093 #endif
00094 
00095 
00096 //  template <class Type> inline
00097 //  _Tuple3<Type>& operator +(const _Tuple3<Type> &u, const _Tuple3<Type> &v) {
00098 //      cout << "_Tuple3 operator + _Tuple3  & _Tuple3" << endl;
00099 //      //return _Tuple3(u.x + v.x, u.y + v.y, u.z + v.z);
00100 //      set(u.x + v.x, u.y + v.y, u.z + v.z);
00101 //      return *this;
00102 //  }
00103 
00104 // works - but might have problems
00105 
00106 //  template <class Type> inline _Tuple3<Type>&
00107 //  _Tuple3<Type>::operator += (const _Tuple3<Type>& v) {
00108 //      cout << "_Tuple3 operator += _Tuple3" << endl;
00109 //      x += v.x; y += v.y; z += v.z;
00110 //      return *this;
00111 //  }
00112 
00113 template <class Type> std::ostream& operator <<(std::ostream& os, const _Tuple3<Type>& t)
00114 {
00115     return os << "(" << t.x << ", " << t.y << ", " << t.z << ")";
00116 }
00117 
00118 template <class Type> std::ostream& operator <<(std::ostream& os, const _Tuple3<Type>* t)
00119 {
00120     return os << *t;
00121 }
00122 
00123 template class _Tuple3<byte>;
00124 template class _Tuple3<double>;
00125 template class _Tuple3<float>;
00126 template class _Tuple3<int>;
00127 
00128 template std::ostream& operator <<(std::ostream&, const _Tuple3<byte>&);
00129 template std::ostream& operator <<(std::ostream&, const _Tuple3<byte>*);
00130 template std::ostream& operator <<(std::ostream&, const _Tuple3<double>&);
00131 template std::ostream& operator <<(std::ostream&, const _Tuple3<double>*);
00132 template std::ostream& operator <<(std::ostream&, const _Tuple3<float>&);
00133 template std::ostream& operator <<(std::ostream&, const _Tuple3<float>*);
00134 template std::ostream& operator <<(std::ostream&, const _Tuple3<int>&);
00135 template std::ostream& operator <<(std::ostream&, const _Tuple3<int>*);
00136 

Generated on Thu Sep 29 13:39:45 2005 for vecmath by  doxygen 1.4.4