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