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

CP2D.h

Go to the documentation of this file.
00001 /*
00002  * CP2D.h
00003  * $Id: CP2D.h,v 1.2 2001/09/28 11:06:08 mjanich 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  */
00022 
00023 //  Description : Class CP2D
00024 //  Purpose     : Provides  funcionality
00025 
00026 
00027 #ifndef __CP2D_H
00028 #define __CP2D_H
00029 
00030 
00031 // System
00033 #include <math.h>
00034 #include <iostream.h>
00035 
00036 // Own
00038 #include "CV2D.h"
00039 #include "CP3D.h"
00040 
00041 
00042 // forward declarations
00044 class CP3D;
00045 
00046 
00047 
00048 
00053 class CP2D 
00054 {   
00055 public:
00056   static double epsilon;
00057 
00060   CP2D() { m_ard[0] = 0.0;
00061            m_ard[1] = 0.0; };
00062 
00065   CP2D(double rdX, double rdY) { m_ard[0] = rdX;
00066                                  m_ard[1] = rdY; }
00067 
00070   CP2D(const CP2D& Point) { m_ard[0] = Point[0];
00071                             m_ard[1] = Point[1]; }
00072 
00073 
00075   // OVERLOADED OPERATORS //
00077  
00080   operator CP3D() const;
00081 
00083   const CP2D& operator=(const CP2D&);
00084 
00089   int operator==(const CP2D&) const;
00090 
00094   int operator!=(const CP2D&) const;
00095 
00097   CP2D& operator+=(const CV2D&);
00098 
00100   CP2D& operator-=(const CV2D&);
00101   
00103   CP2D& operator*=(const CV2D&);
00104 
00106   CP2D& operator*=(double);
00107 
00109   CP2D& operator/=(double);
00110 
00112   CP2D operator+(const CV2D&) const;
00113 
00115   CP2D operator+(const CP2D&) const;  // eigentlich nur fuer affine Punkte
00116   
00118   CP2D operator-(const CV2D&) const;
00119 
00121   CV2D operator-(const CP2D&) const ;
00122 
00124   CP2D operator*(const CV2D&) const;  // scaling
00125 
00127   CP2D operator*(double) const;
00128 
00130   CP2D operator/(const CV2D&) const;
00131 
00133   CP2D operator/(double) const;
00134 
00138   double& operator [] (int i) { return m_ard[i]; };
00139 
00141   double operator[](int i) const { return m_ard[i]; };
00142 
00143 
00145   // METHODS //
00147   
00149   double getMinComponent(void) const    { return m_ard[getMinComponentCoord()]; };
00150  
00152   double getAbsMinComponent(void) const { return m_ard[getAbsMinComponentCoord()]; };
00153  
00155   double getMaxComponent(void) const    { return m_ard[getMaxComponentCoord()]; };
00156  
00158   double getAbsMaxComponent(void) const { return m_ard[getAbsMaxComponentCoord()]; };
00159  
00161   int getMinComponentCoord(void) const;
00162 
00164   int getAbsMinComponentCoord(void) const;
00165 
00167   int getMaxComponentCoord(void) const;
00168 
00170   int getAbsMaxComponentCoord(void) const;
00171 
00175   CV2D getCV2D() const;
00176 
00178   double getX(void) const  { return m_ard[0]; };
00179 
00181   double getY(void) const  { return m_ard[1]; };
00182 
00184   void setX(double rdX)    { m_ard[0] = rdX; return; };
00185 
00187   void setY(double rdY)    { m_ard[1] = rdY; return; };
00188 
00191   void setCoord(double rdX, double rdY) { m_ard[0] = rdX; 
00192                                           m_ard[1] = rdY; 
00193                                           return; };
00194 
00196   // FRIENDS //
00198   
00200   friend CP2D AffinComb(const CP2D&, double, const CP2D&);
00201 
00203   friend CP2D AffinComb2(double r, const CP2D& R, 
00204                          double s, const CP2D& S) {
00205                                   return CP2D(r*R[0] + s*S[0],
00206                                               r*R[1] + s*S[1]); };
00207 
00209   friend double dist(const CP2D&, const CP2D&);
00210 
00212   friend double quaddist(const CP2D&, const CP2D&);
00213 
00215   friend CP2D Min(const CP2D&, const CP2D&);
00216 
00218   friend CP2D Max(const CP2D&, const CP2D&);
00219 
00221   friend CP2D operator*(double, const CP2D&);
00222 
00224   friend CP2D MidPoint(const CP2D&, const CP2D&);
00225 
00226 
00227   // output to stderr
00229   /** Prints a point to the standard output. */
00230   void print() const;
00231 
00233   friend inline ostream& operator<<(ostream&, const CP2D&);
00234 
00236   friend inline istream& operator>>(istream&, CP2D&);
00237 
00238 
00239 protected:
00240   double m_ard[2];
00241 };
00242 
00243 
00244 
00245 // Function   : operator=
00246 // Parameters : const CP2D& p1
00247 // Purpose    : assign another point to this point
00248 // Comments   : 
00249 inline const CP2D& CP2D::operator=(const CP2D& p1)
00250 /*******************************************************************/
00251 {
00252   m_ard[0] = p1.m_ard[0];
00253   m_ard[1] = p1.m_ard[1];
00254   return *this;
00255 }
00256 
00257 
00258 
00259 // Function   : getCV2D
00260 // Parameters : 
00261 // Purpose    : Convert CP2D to CV2D
00262 // Comments   : 
00263 inline CV2D CP2D::getCV2D() const
00264 /*******************************************************************/
00265 {
00266   return CV2D(m_ard[0], m_ard[1]);
00267 }
00268 
00269 
00270 
00271 // Function   : operator<<
00272 // Parameters : ostream& s, const CP2D& pnt
00273 // Purpose    : 
00274 // Comments   : 
00275 inline ostream& operator<<(ostream& s, const CP2D& pnt)
00276 /*******************************************************************/
00277 {   
00278   return s << "(" << pnt.m_ard[0] << "," << pnt.m_ard[1] << ")"; 
00279 }
00280 
00281 
00282 
00283 // Function   : operator>>
00284 // Parameters : istream& s, CP2D& pnt
00285 // Purpose    : 
00286 // Comments   : 
00287 inline istream& operator>>(istream& s, CP2D& pnt)
00288 /*******************************************************************/
00289 {   
00290   char c;
00291   return s >> c >> pnt.m_ard[0] >> c >> pnt.m_ard[1] >> c;
00292 }
00293 
00294 #endif

Generated at Thu Oct 4 17:17:25 2001 for QGLViewer by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001