Blender  V2.59
MT_Tuple2.h
Go to the documentation of this file.
00001 /*
00002  * $Id: MT_Tuple2.h 35158 2011-02-25 11:49:19Z jesterking $
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * The Original Code is: all of this file.
00023  *
00024  * Contributor(s): none yet.
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00034 /*
00035 
00036  * Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
00037  *
00038  * Permission to use, copy, modify, distribute and sell this software
00039  * and its documentation for any purpose is hereby granted without fee,
00040  * provided that the above copyright notice appear in all copies and
00041  * that both that copyright notice and this permission notice appear
00042  * in supporting documentation.  Gino van den Bergen makes no
00043  * representations about the suitability of this software for any
00044  * purpose.  It is provided "as is" without express or implied warranty.
00045  *
00046  */
00047 
00048 #ifndef MT_Tuple2_H
00049 #define MT_Tuple2_H
00050 
00051 #include "MT_Stream.h"
00052 #include "MT_Scalar.h"
00053 
00054 class MT_Tuple2 {
00055 public:
00056     MT_Tuple2() {}
00057     MT_Tuple2(const float *vv) { setValue(vv); }
00058     MT_Tuple2(const double *vv) { setValue(vv); }
00059     MT_Tuple2(MT_Scalar xx, MT_Scalar yy) { setValue(xx, yy); }
00060     
00061     MT_Scalar&       operator[](int i)       { return m_co[i]; }
00062     const MT_Scalar& operator[](int i) const { return m_co[i]; }
00063     
00064     MT_Scalar&       x()       { return m_co[0]; } 
00065     const MT_Scalar& x() const { return m_co[0]; } 
00066 
00067     MT_Scalar&       y()       { return m_co[1]; }
00068     const MT_Scalar& y() const { return m_co[1]; } 
00069 
00070         MT_Scalar&       u()       { return m_co[0]; } 
00071     const MT_Scalar& u() const { return m_co[0]; } 
00072 
00073     MT_Scalar&       v()       { return m_co[1]; }
00074     const MT_Scalar& v() const { return m_co[1]; } 
00075 
00076     MT_Scalar       *getValue()       { return m_co; }
00077     const MT_Scalar *getValue() const { return m_co; }
00078 
00079     void getValue(float *vv) const { 
00080         vv[0] = (float) m_co[0]; vv[1] = (float) m_co[1];
00081     }
00082     
00083     void getValue(double *vv) const { 
00084         vv[0] = m_co[0]; vv[1] = m_co[1];
00085     }
00086     
00087     void setValue(const float *vv) {
00088         m_co[0] = vv[0]; m_co[1] = vv[1];
00089     }
00090     
00091     void setValue(const double *vv) {
00092         m_co[0] = vv[0]; m_co[1] = vv[1];
00093     }
00094     
00095     void setValue(MT_Scalar xx, MT_Scalar yy) {
00096         m_co[0] = xx; m_co[1] = yy; 
00097     }
00098     
00099 protected:
00100     MT_Scalar m_co[2];                            
00101 };
00102 
00103 inline bool operator==(const MT_Tuple2& t1, const MT_Tuple2& t2) {
00104     return t1[0] == t2[0] && t1[1] == t2[1];
00105 }
00106 
00107 inline MT_OStream& operator<<(MT_OStream& os, const MT_Tuple2& t) {
00108     return os << t[0] << ' ' << t[1];
00109 }
00110 
00111 #endif
00112