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

CP2D.h

Go to the documentation of this file.
00001 /*
00002  * CP2D.h
00003  * $Id: CP2D.h,v 1.3 2001/11/15 16:54:52 guenth 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 #include <iostream.h>
00042 
00043 // Own
00045 #include "CV2D.h"
00046 #include "CP3D.h"
00047 
00048 
00049 // forward declarations
00051 class CP3D;
00052 
00053 
00054 
00055 
00060 class CP2D 
00061 {   
00062 public:
00063   static double epsilon;
00064 
00067   CP2D() { m_ard[0] = 0.0;
00068            m_ard[1] = 0.0; };
00069 
00072   CP2D(double rdX, double rdY) { m_ard[0] = rdX;
00073                                  m_ard[1] = rdY; }
00074 
00077   CP2D(const CP2D& Point) { m_ard[0] = Point[0];
00078                             m_ard[1] = Point[1]; }
00079 
00080 
00082   // OVERLOADED OPERATORS //
00084  
00087   operator CP3D() const;
00088 
00090   const CP2D& operator=(const CP2D&);
00091 
00096   int operator==(const CP2D&) const;
00097 
00101   int operator!=(const CP2D&) const;
00102 
00104   CP2D& operator+=(const CV2D&);
00105 
00107   CP2D& operator-=(const CV2D&);
00108   
00110   CP2D& operator*=(const CV2D&);
00111 
00113   CP2D& operator*=(double);
00114 
00116   CP2D& operator/=(double);
00117 
00119   CP2D operator+(const CV2D&) const;
00120 
00122   CP2D operator+(const CP2D&) const;  // eigentlich nur fuer affine Punkte
00123   
00125   CP2D operator-(const CV2D&) const;
00126 
00128   CV2D operator-(const CP2D&) const ;
00129 
00131   CP2D operator*(const CV2D&) const;  // scaling
00132 
00134   CP2D operator*(double) const;
00135 
00137   CP2D operator/(const CV2D&) const;
00138 
00140   CP2D operator/(double) const;
00141 
00145   double& operator [] (int i) { return m_ard[i]; };
00146 
00148   double operator[](int i) const { return m_ard[i]; };
00149 
00150 
00152   // METHODS //
00154   
00156   double getMinComponent(void) const    { return m_ard[getMinComponentCoord()]; };
00157  
00159   double getAbsMinComponent(void) const { return m_ard[getAbsMinComponentCoord()]; };
00160  
00162   double getMaxComponent(void) const    { return m_ard[getMaxComponentCoord()]; };
00163  
00165   double getAbsMaxComponent(void) const { return m_ard[getAbsMaxComponentCoord()]; };
00166  
00168   int getMinComponentCoord(void) const;
00169 
00171   int getAbsMinComponentCoord(void) const;
00172 
00174   int getMaxComponentCoord(void) const;
00175 
00177   int getAbsMaxComponentCoord(void) const;
00178 
00182   CV2D getCV2D() const;
00183 
00185   double getX(void) const  { return m_ard[0]; };
00186 
00188   double getY(void) const  { return m_ard[1]; };
00189 
00191   void setX(double rdX)    { m_ard[0] = rdX; return; };
00192 
00194   void setY(double rdY)    { m_ard[1] = rdY; return; };
00195 
00198   void setCoord(double rdX, double rdY) { m_ard[0] = rdX; 
00199                                           m_ard[1] = rdY; 
00200                                           return; };
00201 
00203   // FRIENDS //
00205   
00207   friend CP2D AffinComb(const CP2D&, double, const CP2D&);
00208 
00210   friend CP2D AffinComb2(double r, const CP2D& R, 
00211                          double s, const CP2D& S) {
00212                                   return CP2D(r*R[0] + s*S[0],
00213                                               r*R[1] + s*S[1]); };
00214 
00216   friend double dist(const CP2D&, const CP2D&);
00217 
00219   friend double quaddist(const CP2D&, const CP2D&);
00220 
00222   friend CP2D Min(const CP2D&, const CP2D&);
00223 
00225   friend CP2D Max(const CP2D&, const CP2D&);
00226 
00228   friend CP2D operator*(double, const CP2D&);
00229 
00231   friend CP2D MidPoint(const CP2D&, const CP2D&);
00232 
00233 
00234   // output to stderr
00236   /** Prints a point to the standard output. */
00237   void print() const;
00238 
00240   friend inline ostream& operator<<(ostream&, const CP2D&);
00241 
00243   friend inline istream& operator>>(istream&, CP2D&);
00244 
00245 
00246 protected:
00247   double m_ard[2];
00248 };
00249 
00250 
00251 
00252 // Function   : operator=
00253 // Parameters : const CP2D& p1
00254 // Purpose    : assign another point to this point
00255 // Comments   : 
00256 inline const CP2D& CP2D::operator=(const CP2D& p1)
00257 /*******************************************************************/
00258 {
00259   m_ard[0] = p1.m_ard[0];
00260   m_ard[1] = p1.m_ard[1];
00261   return *this;
00262 }
00263 
00264 
00265 
00266 // Function   : getCV2D
00267 // Parameters : 
00268 // Purpose    : Convert CP2D to CV2D
00269 // Comments   : 
00270 inline CV2D CP2D::getCV2D() const
00271 /*******************************************************************/
00272 {
00273   return CV2D(m_ard[0], m_ard[1]);
00274 }
00275 
00276 
00277 
00278 // Function   : operator<<
00279 // Parameters : ostream& s, const CP2D& pnt
00280 // Purpose    : 
00281 // Comments   : 
00282 inline ostream& operator<<(ostream& s, const CP2D& pnt)
00283 /*******************************************************************/
00284 {   
00285   return s << "(" << pnt.m_ard[0] << "," << pnt.m_ard[1] << ")"; 
00286 }
00287 
00288 
00289 
00290 // Function   : operator>>
00291 // Parameters : istream& s, CP2D& pnt
00292 // Purpose    : 
00293 // Comments   : 
00294 inline istream& operator>>(istream& s, CP2D& pnt)
00295 /*******************************************************************/
00296 {   
00297   char c;
00298   return s >> c >> pnt.m_ard[0] >> c >> pnt.m_ard[1] >> c;
00299 }
00300 
00301 #endif

Generated on Wed Mar 5 18:23:25 2003 for QGLViewer by doxygen1.3-rc3