00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __CP2D_H
00028 #define __CP2D_H
00029
00030
00031
00033
00034 #include <iostream.h>
00035
00036
00038
00039 #include "CP3D.h"
00040
00041
00042
00044
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
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;
00116
00118 CP2D operator-(const CV2D&) const;
00119
00121 CV2D operator-(const CP2D&) const ;
00122
00124 CP2D operator*(const CV2D&) const;
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
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
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
00229
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
00246
00247
00248
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
00260
00261
00262
00263 inline CV2D CP2D::getCV2D() const
00264
00265 {
00266 return CV2D(m_ard[0], m_ard[1]);
00267 }
00268
00269
00270
00271
00272
00273
00274
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
00284
00285
00286
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