csgeom/tri.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2003 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library 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 GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_TRIANGLE_H__ 00020 #define __CS_TRIANGLE_H__ 00021 00029 #include "csextern.h" 00030 00031 namespace CS 00032 { 00038 template<typename T> 00039 struct TriangleT 00040 { 00041 #if !defined(__STRICT_ANSI__) && !defined(SWIG) 00042 union 00043 { 00044 struct 00045 { 00046 #endif 00047 00048 00049 T a, b, c; 00051 #if !defined(__STRICT_ANSI__) && !defined(SWIG) 00052 }; 00054 T components[3]; 00055 }; 00056 #endif 00057 00059 TriangleT () {} 00060 00062 TriangleT (const T& _a, const T& _b, const T& _c) : a(_a), b(_b), c(_c) {} 00063 00065 TriangleT (const TriangleT& t) 00066 { 00067 a = t.a; 00068 b = t.b; 00069 c = t.c; 00070 } 00071 00073 TriangleT& operator= (const TriangleT& t) 00074 { 00075 a = t.a; 00076 b = t.b; 00077 c = t.c; 00078 return *this; 00079 } 00080 00082 void Set (const T& _a, const T& _b, const T& _c) 00083 { 00084 a = _a; 00085 b = _b; 00086 c = _c; 00087 } 00088 00090 #if defined( __STRICT_ANSI__) || defined(SWIG) 00091 inline const T& operator[] (size_t n) const { return !n?a:n&1?b:c; } 00092 #else 00093 inline const T& operator[] (size_t n) const { return components[n]; } 00094 #endif 00095 00097 #if defined( __STRICT_ANSI__) || defined(SWIG) 00098 inline T& operator[] (size_t n) { return !n?a:n&1?b:c; } 00099 #else 00100 inline T& operator[] (size_t n) { return components[n]; } 00101 #endif 00102 00103 }; 00104 } 00105 00111 struct csTriangle : public CS::TriangleT<int> 00112 { 00113 csTriangle () {} 00114 00116 csTriangle (int _a, int _b, int _c) : CS::TriangleT<int> (_a, _b, _c) {} 00117 00119 csTriangle (const CS::TriangleT<int>& t) : CS::TriangleT<int> (t) {} 00120 }; 00121 00124 #endif // __CS_TRIANGLE_H__ 00125
Generated for Crystal Space 2.0 by doxygen 1.6.1