Blender V2.61 - r43446

MT_Tuple2.h

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