Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

CP2D.h

Go to the documentation of this file.
00001 /* 00002 * CP2D.h 00003 * $Id: CP2D.h,v 1.4 2003/06/24 14:50:02 anxo Exp $ 00004 * 00005 * Copyright (C) 1999, 2000 Michael Meissner 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * As a special exception to the GPL, the QGLViewer authors (Markus 00022 * Janich, Michael Meissner, Richard Guenther, Alexander Buck and Thomas 00023 * Woerner) give permission to link this program with Qt (non-)commercial 00024 * edition, and distribute the resulting executable, without including 00025 * the source code for the Qt (non-)commercial edition in the source 00026 * distribution. 00027 * 00028 */ 00029 00030 // Description : Class CP2D 00031 // Purpose : Provides funcionality 00032 00033 00034 #ifndef __CP2D_H 00035 #define __CP2D_H 00036 00037 00038 // System 00040 #include <math.h> 00041 #ifdef _MSC_VER 00042 #if _MSC_VER >= 1300 00043 #include <iostream> 00044 #endif 00045 #else 00046 #include <iostream.h> 00047 #endif 00048 00049 // Own 00051 #include "CV2D.h" 00052 #include "CP3D.h" 00053 00054 00055 // forward declarations 00057 class CP3D; 00058 00059 00060 00061 00066 class CP2D 00067 { 00068 public: 00069 static double epsilon; 00070 00073 CP2D() { m_ard[0] = 0.0; 00074 m_ard[1] = 0.0; }; 00075 00078 CP2D(double rdX, double rdY) { m_ard[0] = rdX; 00079 m_ard[1] = rdY; } 00080 00083 CP2D(const CP2D& Point) { m_ard[0] = Point[0]; 00084 m_ard[1] = Point[1]; } 00085 00086 00088 // OVERLOADED OPERATORS // 00090 00093 operator CP3D() const; 00094 00096 const CP2D& operator=(const CP2D&); 00097 00102 int operator==(const CP2D&) const; 00103 00107 int operator!=(const CP2D&) const; 00108 00110 CP2D& operator+=(const CV2D&); 00111 00113 CP2D& operator-=(const CV2D&); 00114 00116 CP2D& operator*=(const CV2D&); 00117 00119 CP2D& operator*=(double); 00120 00122 CP2D& operator/=(double); 00123 00125 CP2D operator+(const CV2D&) const; 00126 00128 CP2D operator+(const CP2D&) const; // eigentlich nur fuer affine Punkte 00129 00131 CP2D operator-(const CV2D&) const; 00132 00134 CV2D operator-(const CP2D&) const ; 00135 00137 CP2D operator*(const CV2D&) const; // scaling 00138 00140 CP2D operator*(double) const; 00141 00143 CP2D operator/(const CV2D&) const; 00144 00146 CP2D operator/(double) const; 00147 00151 double& operator [] (int i) { return m_ard[i]; }; 00152 00154 double operator[](int i) const { return m_ard[i]; }; 00155 00156 00158 // METHODS // 00160 00162 double getMinComponent(void) const { return m_ard[getMinComponentCoord()]; }; 00163 00165 double getAbsMinComponent(void) const { return m_ard[getAbsMinComponentCoord()]; }; 00166 00168 double getMaxComponent(void) const { return m_ard[getMaxComponentCoord()]; }; 00169 00171 double getAbsMaxComponent(void) const { return m_ard[getAbsMaxComponentCoord()]; }; 00172 00174 int getMinComponentCoord(void) const; 00175 00177 int getAbsMinComponentCoord(void) const; 00178 00180 int getMaxComponentCoord(void) const; 00181 00183 int getAbsMaxComponentCoord(void) const; 00184 00188 CV2D getCV2D() const; 00189 00191 double getX(void) const { return m_ard[0]; }; 00192 00194 double getY(void) const { return m_ard[1]; }; 00195 00197 void setX(double rdX) { m_ard[0] = rdX; return; }; 00198 00200 void setY(double rdY) { m_ard[1] = rdY; return; }; 00201 00204 void setCoord(double rdX, double rdY) { m_ard[0] = rdX; 00205 m_ard[1] = rdY; 00206 return; }; 00207 00209 // FRIENDS // 00211 00213 friend CP2D AffinComb(const CP2D&, double, const CP2D&); 00214 00216 friend CP2D AffinComb2(double r, const CP2D& R, 00217 double s, const CP2D& S) { 00218 return CP2D(r*R[0] + s*S[0], 00219 r*R[1] + s*S[1]); }; 00220 00222 friend double dist(const CP2D&, const CP2D&); 00223 00225 friend double quaddist(const CP2D&, const CP2D&); 00226 00228 friend CP2D Min(const CP2D&, const CP2D&); 00229 00231 friend CP2D Max(const CP2D&, const CP2D&); 00232 00234 friend CP2D operator*(double, const CP2D&); 00235 00237 friend CP2D MidPoint(const CP2D&, const CP2D&); 00238 00239 00240 // output to stderr 00242 00243 void print() const; 00244 00246 friend inline ostream& operator<<(ostream&, const CP2D&); 00247 00249 friend inline istream& operator>>(istream&, CP2D&); 00250 00251 00252 protected: 00253 double m_ard[2]; 00254 }; 00255 00256 00257 00258 // Function : operator= 00259 // Parameters : const CP2D& p1 00260 // Purpose : assign another point to this point 00261 // Comments : 00262 inline const CP2D& CP2D::operator=(const CP2D& p1) 00263 /*******************************************************************/ 00264 { 00265 m_ard[0] = p1.m_ard[0]; 00266 m_ard[1] = p1.m_ard[1]; 00267 return *this; 00268 } 00269 00270 00271 00272 // Function : getCV2D 00273 // Parameters : 00274 // Purpose : Convert CP2D to CV2D 00275 // Comments : 00276 inline CV2D CP2D::getCV2D() const 00277 /*******************************************************************/ 00278 { 00279 return CV2D(m_ard[0], m_ard[1]); 00280 } 00281 00282 00283 00284 // Function : operator<< 00285 // Parameters : ostream& s, const CP2D& pnt 00286 // Purpose : 00287 // Comments : 00288 inline ostream& operator<<(ostream& s, const CP2D& pnt) 00289 /*******************************************************************/ 00290 { 00291 return s << "(" << pnt.m_ard[0] << "," << pnt.m_ard[1] << ")"; 00292 } 00293 00294 00295 00296 // Function : operator>> 00297 // Parameters : istream& s, CP2D& pnt 00298 // Purpose : 00299 // Comments : 00300 inline istream& operator>>(istream& s, CP2D& pnt) 00301 /*******************************************************************/ 00302 { 00303 char c; 00304 return s >> c >> pnt.m_ard[0] >> c >> pnt.m_ard[1] >> c; 00305 } 00306 00307 #endif

Generated on Fri Aug 13 17:43:12 2004 for QGLViewer by doxygen 1.3.7