00001 /* 00002 * CV2D.h 00003 * $Id: CV2D.h,v 1.3 2001/11/15 16:54:52 guenth Exp $ 00004 * 00005 * Copyright (C) 1999, 2000 Markus Janich, Michael Meissner, Rainer Jaeger 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 00031 00032 #ifndef __CV2D_H 00033 #define __CV2D_H 00034 00035 00036 00037 // System 00039 #include <math.h> 00040 #include <iostream.h> 00041 00042 00043 // Own 00045 //#include "CP2D.h" 00046 00047 // Forward declaration 00049 class CV3D; 00050 00051 00052 00058 class CV2D { 00059 public: 00060 static double epsilon; 00061 00064 CV2D(void) { m_ard[0] = 0.0; 00065 m_ard[1] = 0.0; }; 00066 00069 CV2D(double rdX, double rdY) { m_ard[0] = rdX; 00070 m_ard[1] = rdY; }; 00071 00074 CV2D(const CV2D& Vector) { m_ard[0] = Vector.m_ard[0]; 00075 m_ard[1] = Vector.m_ard[1]; }; 00076 00078 ~CV2D(void) {}; 00079 00080 00081 00083 // OVERLOADED OPERATORS // 00085 00089 operator CV3D() const; 00090 00092 const CV2D& operator=(const CV2D&); 00093 00097 bool operator==(const CV2D&) const; 00098 00102 bool operator!=(const CV2D&) const; 00103 00105 CV2D& operator+=(const CV2D&); 00106 00108 CV2D& operator-=(const CV2D&); 00109 00111 CV2D& operator*=(double); 00112 00114 CV2D& operator/=(double); 00115 00117 CV2D operator+(const CV2D&) const; 00118 00120 CV2D operator-(const CV2D&) const; 00121 00123 CV2D operator-(void) const; 00124 00126 double operator*(const CV2D&) const; 00127 00129 CV2D operator*(double) const; 00130 00132 CV2D operator/(double) const; 00133 00137 double& operator[](int i) { return m_ard[i]; }; 00138 00140 double operator[](int i) const { return m_ard[i]; }; 00141 00143 friend CV2D operator*(double, const CV2D&); 00144 00145 00146 00148 // METHODS // 00150 00152 double getMinComponent(void) const { return m_ard[getMinComponentCoord()]; }; 00153 00155 double getAbsMinComponent(void) const { return m_ard[getAbsMinComponentCoord()]; }; 00156 00158 double getMaxComponent(void) const { return m_ard[getMaxComponentCoord()]; }; 00159 00161 double getAbsMaxComponent(void) const { return m_ard[getAbsMaxComponentCoord()]; }; 00162 00164 int getMinComponentCoord(void) const; 00165 00167 int getAbsMinComponentCoord(void) const; 00168 00170 int getMaxComponentCoord(void) const; 00171 00173 int getAbsMaxComponentCoord(void) const; 00174 00176 double getX(void) const { return m_ard[0]; }; 00177 00179 double getY(void) const { return m_ard[1]; }; 00180 00182 void setX(double rdX) { m_ard[0] = rdX; }; 00183 00185 void setY(double rdY) { m_ard[1] = rdY; }; 00186 00189 void setCoord(double rdX, double rdY) { m_ard[0] = rdX; 00190 m_ard[1] = rdY; 00191 return; }; 00192 00194 double getNorm(void) const { return sqrt(m_ard[0]*m_ard[0] + m_ard[1]*m_ard[1]); }; 00195 00197 void normalize(void); 00198 00200 CV2D getNormalized(void) const; 00201 00203 void print(void) const; 00204 00206 friend ostream& operator<<(ostream&, const CV2D&); 00207 00209 friend istream& operator>>(istream&, CV2D&); 00210 00211 00212 protected: 00213 double m_ard[2]; 00214 00215 }; 00216 00217 00218 00219 // Function : operator= 00220 // Parameters : const CP2D& p1 00221 // Purpose : assign another point to this point 00222 // Comments : 00223 inline const CV2D& CV2D::operator=(const CV2D& v) 00224 /*******************************************************************/ 00225 { 00226 m_ard[0] = v[0]; 00227 m_ard[1] = v[1]; 00228 return *this; 00229 } 00230 00231 #endif // _CV2D_H_