00001 /**************************************************************************** 00002 * VCGLib o o * 00003 * Visual and Computer Graphics Library o o * 00004 * _ O _ * 00005 * Copyright(C) 2004 \/)\/ * 00006 * Visual Computing Lab /\/| * 00007 * ISTI - Italian National Research Council | * 00008 * \ * 00009 * All rights reserved. * 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This program is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 00020 * for more details. * 00021 * * 00022 ****************************************************************************/ 00023 00024 #ifndef __VCGLIB_TEXCOORD2__ 00025 #define __VCGLIB_TEXCOORD2__ 00026 00027 #include <vcg/space/point2.h> 00028 00029 namespace vcg { 00032 00039 template<class T = float, int NMAX = 1> 00040 class TexCoord2 00041 { 00042 public: 00043 typedef Point2<T> PointType; 00044 typedef T ScalarType; 00045 00046 00047 private: 00048 PointType _t[NMAX]; 00049 short _n[NMAX]; 00050 public: 00051 00052 TexCoord2(T u, T v) { if(NMAX>0) _n[0]=0; _t[0][0]=u; _t[0][1]=v; }; 00053 TexCoord2() { }; 00054 00055 inline const PointType &P() const { return _t[0]; }; 00056 inline PointType &P() { return _t[0]; }; 00057 00058 inline const PointType &P(const int i) const { assert(i>0 && i<NMAX); return _t[i]; }; 00059 inline PointType &P(const int i) { assert(i>0 && i<NMAX); return _t[i]; }; 00060 00061 inline T & U() { return _t[0][0]; } 00062 inline T & V() { return _t[0][1]; } 00063 inline const T & U() const { return _t[0][0]; } 00064 inline const T & V() const { return _t[0][1]; } 00065 inline T & U(const int i) { assert(i>0 && i<NMAX); return _t[i][0]; } 00066 inline T & V(const int i) { assert(i>0 && i<NMAX); return _t[i][1]; } 00067 inline const T & U(const int i) const { assert(i>0 && i<NMAX); return _t[i][0]; } 00068 inline const T & V(const int i) const { assert(i>0 && i<NMAX); return _t[i][1]; } 00069 00070 inline short & N() { return _n[0]; } 00071 inline short N() const { return _n[0]; } 00072 00073 inline short & N(const int i) { assert(i>0 && i<NMAX); return _n[i]; } 00074 inline short N(const int i) const { assert(i>0 && i<NMAX); return _n[i]; } 00075 00076 00077 /* <OLD_METHODS> (lowercase ones). DEPRECATED. TO BE REMOVED SOON.*/ 00078 inline T & u() { return _t[0][0]; } 00079 inline T & v() { return _t[0][1]; } 00080 inline const T & u() const { return _t[0][0]; } 00081 inline const T & v() const { return _t[0][1]; } 00082 inline T & u(const int i) { return _t[i][0]; } 00083 inline T & v(const int i) { return _t[i][1]; } 00084 inline const T & u(const int i) const { return _t[i][0]; } 00085 inline const T & v(const int i) const { return _t[i][1]; } 00086 00087 inline short & n() { return _n[0]; } 00088 inline short n() const { return _n[0]; } 00089 00090 inline short & n(const int i) { return _n[i]; } 00091 inline short n(const int i) const { return _n[i]; } 00092 00093 inline Point2<T> & t(const int i) { return _t[i]; } 00094 inline Point2<T> t(const int i) const { return _t[i]; } 00095 00096 inline Point2<T> & t() { return _t[0]; } 00097 inline Point2<T> t() const { return _t[0]; } 00098 /* </OLD_METHODS> */ 00099 00100 inline bool operator == ( TexCoord2 const & p ) const 00101 { 00102 for(int i=0;i<NMAX;++i) 00103 if(p._t[i] != _t[i] || p._n[i] != _n[i]) return false; 00104 return true; 00105 } 00106 00107 inline bool operator != ( TexCoord2 const & p ) const 00108 { 00109 for(int i=0;i<NMAX;++i) 00110 if(p._t[i] != _t[i] || p._n[i] != _n[i]) return true; 00111 return false; 00112 } 00113 00114 inline bool operator < ( TexCoord2 const & p ) const 00115 { 00116 for(int i=0;i<NMAX;++i) 00117 if(p._t[i] != _t[i]) return p._t[i] < _t[i]; 00118 return false; 00119 } 00120 00121 enum { n_coords=NMAX }; 00122 }; 00123 00127 template<class T = float > 00128 class TexCoord2Simple 00129 { 00130 public: 00131 typedef Point2<T> PointType; 00132 typedef T ScalarType; 00133 00134 private: 00135 Point2<T> _t; 00136 00137 inline short & static_n() const 00138 { 00139 static short _n = 0; 00140 return _n; 00141 } 00142 00143 public: 00144 00145 inline T & U() { return _t[0]; } 00146 inline T & V() { return _t[1]; } 00147 inline const T & U() const { return _t[0]; } 00148 inline const T & V() const { return _t[1]; } 00149 inline T & U(const int i) { assert(i==0); return _t[0]; } 00150 inline T & V(const int i) { assert(i==0); return _t[1]; } 00151 inline const T & U(const int i) const { assert(i==0); return _t[0]; } 00152 inline const T & V(const int i) const { assert(i==0); return _t[1]; } 00153 00154 inline Point2<T> & P(const int i) { assert(i==0); return _t; } 00155 inline Point2<T> P(const int i) const { assert(i==0); return _t; } 00156 00157 inline Point2<T> & P() { return _t; } 00158 inline Point2<T> P() const { return _t; } 00159 00160 inline short & N() { assert(static_n()==0); return static_n(); } 00161 inline short N() const { assert(static_n()==0); return 0; } 00162 00163 inline short & N(const int i) { assert(i==0); return static_n(); } 00164 inline short N(const int i) const { assert(i==0); return 0; } 00165 00166 00167 /* <OLD_METHODS> (lowercase ones). DEPRECATED. TO BE REMOVED SOON.*/ 00168 inline T & u() { return _t[0]; } 00169 inline T & v() { return _t[1]; } 00170 inline const T & u() const { return _t[0]; } 00171 inline const T & v() const { return _t[1]; } 00172 inline T & u(const int i) { assert(i==0); return _t[0]; } 00173 inline T & v(const int i) { assert(i==0); return _t[1]; } 00174 inline const T & u(const int i) const { assert(i==0); return _t[0]; } 00175 inline const T & v(const int i) const { assert(i==0); return _t[1]; } 00176 00177 inline Point2<T> & t(const int i) { assert(i==0); return _t; } 00178 inline Point2<T> t(const int i) const { assert(i==0); return _t; } 00179 00180 inline Point2<T> & t() { return _t; } 00181 inline Point2<T> t() const { return _t; } 00182 00183 inline short & n() { assert(static_n()==0); return static_n(); } 00184 inline short n() const { assert(static_n()==0); return 0; } 00185 00186 inline short & n(const int i) { assert(i==0); return static_n(); } 00187 inline short n(const int i) const { assert(i==0); return 0; } 00188 00189 /* </OLD_METHODS> */ 00190 00191 inline bool operator == ( TexCoord2Simple const & p ) const 00192 { 00193 return _t==p._t; 00194 } 00195 00196 enum { n_coords=1}; 00197 00198 }; 00199 typedef TexCoord2<float> TexCoord2f; 00200 typedef TexCoord2<double> TexCoord2d; 00201 00202 00205 } 00206 00207 #endif