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 00046 template<class T = float, int NMAX = 1> 00047 class TexCoord2 00048 { 00049 public: 00050 typedef Point2<T> PointType; 00051 typedef T ScalarType; 00052 00053 00054 private: 00055 PointType _t[NMAX]; 00056 short _n[NMAX]; 00057 public: 00058 00059 TexCoord2(T u, T v) { if(NMAX>0) _n[0]=0; _t[0][0]=u; _t[0][1]=v; } 00060 TexCoord2() { } 00061 00062 inline const PointType &P() const { return _t[0]; } 00063 inline PointType &P() { return _t[0]; } 00064 00065 inline const PointType &P(const int i) const { assert(i>0 && i<NMAX); return _t[i]; } 00066 inline PointType &P(const int i) { assert(i>0 && i<NMAX); return _t[i]; } 00067 00069 inline T & U() { return _t[0][0]; } 00071 inline T & V() { return _t[0][1]; } 00073 inline const T & U() const { return _t[0][0]; } 00075 inline const T & V() const { return _t[0][1]; } 00076 inline T & U( int i) { assert(i>0 && i<NMAX); return _t[i][0]; } 00077 inline T & V( int i) { assert(i>0 && i<NMAX); return _t[i][1]; } 00078 inline const T & U( int i) const { assert(i>0 && i<NMAX); return _t[i][0]; } 00079 inline const T & V( int i) const { assert(i>0 && i<NMAX); return _t[i][1]; } 00080 00082 inline short & N() { return _n[0]; } 00084 inline short N() const { return _n[0]; } 00085 00086 inline short & N(int i) { assert(i>0 && i<NMAX); return _n[i]; } 00087 inline short N(int i) const { assert(i>0 && i<NMAX); return _n[i]; } 00088 00089 00090 /* <OLD_METHODS> (lowercase ones). DEPRECATED. TO BE REMOVED SOON.*/ 00091 inline T & u() { return _t[0][0]; } 00092 inline T & v() { return _t[0][1]; } 00093 inline const T & u() const { return _t[0][0]; } 00094 inline const T & v() const { return _t[0][1]; } 00095 inline T & u( int i) { return _t[i][0]; } 00096 inline T & v( int i) { return _t[i][1]; } 00097 inline const T & u( int i) const { return _t[i][0]; } 00098 inline const T & v( int i) const { return _t[i][1]; } 00099 00100 inline short & n() { return _n[0]; } 00101 inline short n() const { return _n[0]; } 00102 00103 inline short & n( int i) { return _n[i]; } 00104 inline short n( int i) const { return _n[i]; } 00105 00106 inline Point2<T> & t( int i) { return _t[i]; } 00107 inline Point2<T> t( int i) const { return _t[i]; } 00108 00109 inline Point2<T> & t() { return _t[0]; } 00110 inline Point2<T> t() const { return _t[0]; } 00111 /* </OLD_METHODS> */ 00112 00113 inline bool operator == ( const TexCoord2 & p ) const 00114 { 00115 for(int i=0;i<NMAX;++i) 00116 if(p._t[i] != _t[i] || p._n[i] != _n[i]) return false; 00117 return true; 00118 } 00119 00120 inline bool operator != ( const TexCoord2 & p ) const 00121 { 00122 for(int i=0;i<NMAX;++i) 00123 if(p._t[i] != _t[i] || p._n[i] != _n[i]) return true; 00124 return false; 00125 } 00126 00127 inline bool operator < ( const TexCoord2 & p ) const 00128 { 00129 for(int i=0;i<NMAX;++i) 00130 if(p._t[i] != _t[i]) return p._t[i] < _t[i]; 00131 return false; 00132 } 00133 00134 enum { n_coords=NMAX }; 00135 }; 00136 00140 template<class T = float > 00141 class TexCoord2Simple 00142 { 00143 public: 00144 typedef Point2<T> PointType; 00145 typedef T ScalarType; 00146 00147 private: 00148 Point2<T> _t; 00149 00150 inline short & static_n() const 00151 { 00152 static short _n = 0; 00153 return _n; 00154 } 00155 00156 public: 00157 00158 inline T & U() { return _t[0]; } 00159 inline T & V() { return _t[1]; } 00160 inline const T & U() const { return _t[0]; } 00161 inline const T & V() const { return _t[1]; } 00162 inline T & U(const int i) { (void)i; assert(i==0); return _t[0]; } 00163 inline T & V(const int i) { (void)i; assert(i==0); return _t[1]; } 00164 inline const T & U(const int i) const { (void)i; assert(i==0); return _t[0]; } 00165 inline const T & V(const int i) const { (void)i; assert(i==0); return _t[1]; } 00166 00167 inline Point2<T> & P(const int i) { (void)i; assert(i==0); return _t; } 00168 inline Point2<T> P(const int i) const { (void)i; assert(i==0); return _t; } 00169 00170 inline Point2<T> & P() { return _t; } 00171 inline Point2<T> P() const { return _t; } 00172 00173 inline short & N() { assert(static_n()==0); return static_n(); } 00174 inline short N() const { assert(static_n()==0); return 0; } 00175 00176 inline short & N(const int i) { (void)i; assert(i==0); return static_n(); } 00177 inline short N(const int i) const { (void)i; assert(i==0); return 0; } 00178 00179 00180 /* <OLD_METHODS> (lowercase ones). DEPRECATED. TO BE REMOVED SOON.*/ 00181 inline T & u() { return _t[0]; } 00182 inline T & v() { return _t[1]; } 00183 inline const T & u() const { return _t[0]; } 00184 inline const T & v() const { return _t[1]; } 00185 inline T & u(const int i) { (void)i; assert(i==0); return _t[0]; } 00186 inline T & v(const int i) { (void)i; assert(i==0); return _t[1]; } 00187 inline const T & u(const int i) const { (void)i; assert(i==0); return _t[0]; } 00188 inline const T & v(const int i) const { (void)i; assert(i==0); return _t[1]; } 00189 00190 inline Point2<T> & t(const int i) { (void)i; assert(i==0); return _t; } 00191 inline Point2<T> t(const int i) const { (void)i; assert(i==0); return _t; } 00192 00193 inline Point2<T> & t() { return _t; } 00194 inline Point2<T> t() const { return _t; } 00195 00196 inline short & n() { assert(static_n()==0); return static_n(); } 00197 inline short n() const { assert(static_n()==0); return 0; } 00198 00199 inline short & n(const int i) { (void)i; assert(i==0); return static_n(); } 00200 inline short n(const int i) const { (void)i; assert(i==0); return 0; } 00201 00202 /* </OLD_METHODS> */ 00203 00204 inline bool operator == ( TexCoord2Simple const & p ) const 00205 { 00206 return _t==p._t; 00207 } 00208 00209 enum { n_coords=1}; 00210 00211 }; 00212 typedef TexCoord2<float> TexCoord2f; 00213 typedef TexCoord2<double> TexCoord2d; 00214 00215 00218 } 00219 00220 #endif