Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

point.hpp

Go to the documentation of this file.
00001 //************************************************************************************//
00002 // Module       : point.hpp
00003 // Date         : 8/20/03 (DLR)
00004 // Copyright    : 2003-2006 Copyright University Corporation for Atmospheric
00005 //                Research
00006 // Description  : Encapsulates the access methods and data associated with
00007 //                defining a geometric point
00008 // Derived From : none.
00009 // Modifications:
00010 //************************************************************************************//
00011 #if !defined(POINT_HPP)
00012 #define POINT_HPP
00013 
00014 #include "gtypes.h"
00015 #include <stdlib.h>
00016 #include <math.h>
00017 #include <iostream.h>
00018 #include <iomanip>
00019 
00020 class Point
00021 {
00022 private:
00023   GINT         gdim_;
00024   GDOUBLE      eps_;
00025   GDOUBLE      *px_[3];
00026 public:
00027                   Point(); 
00028                   Point(GDOUBLE eps); 
00029                  ~Point();
00030   friend ostream& operator<<(ostream &, Point &);
00031 
00032   GDOUBLE      x1;
00033   GDOUBLE      x2;
00034   GDOUBLE      x3;
00035 
00036   inline GBOOL    operator==(Point &p) // Add 'fuzziness' to equality check
00037   { GINT  i, n; GBOOL b; GDOUBLE del;    
00038     // p.x_i = g * 2^n = g * 10^m, where m=n log_10(2):
00039     for ( i=0,b=TRUE;i<gdim_;i++) { frexp(p[i],&n); del=eps_*pow(10.0,0.301029995663981*n); // scale bracket to point
00040       b = b && ( p[i] >= *px_[i] - del && p[i] <= *px_[i] + del ); }             // do check for equality
00041     return b; }
00042 
00043   inline GBOOL    operator!=(Point &p) 
00044   { return !this->operator==(p); }
00045 
00046   inline void  operator=(Point &p)
00047   { eps_ = p.eps_; x1 = p.x1; x2 = p.x2; x3 = p.x3; }
00048 
00049   inline void  operator=(GDOUBLE f)
00050   { x1 = f;  x2 = f;  x3 = f; }
00051 
00052   inline GDOUBLE &operator()(GINT  i)
00053   { if ( i<0 || i>=3 ) { cout << "Point::(): access error; bad index:" << i << endl; exit(1); }
00054     return *px_[i]; }
00055 
00056   inline GDOUBLE &operator[](GINT  i)
00057   { if ( i<0 || i>=3 ) { cout << "Point::[]: access error; bad index:" << i << endl; exit(1); }
00058     return *px_[i]; }
00059 
00060   inline void Bracket(GDOUBLE e)
00061   { eps_ = e; }
00062 
00063   inline GDOUBLE GetBracket()
00064   { return eps_ ; }
00065 
00066   inline GDOUBLE GetDim()
00067   { return gdim_ ; }
00068 
00069   inline void Truncate()
00070   { GINT  i, n; GDOUBLE del, is;
00071     // p.x_i = g * 2^n = g * 10^m, where m=n log_10(2):
00072     for ( i=0;i<gdim_;i++ ) { frexp(*px_[i],&n); del=eps_*pow(10.0,0.30103*n); // scale bracket to point
00073       is = *px_[i]>0?1.0:-1.0; *px_[i] = *px_[i]!=0.0 ? is*(fabs(*px_[i])-del): 0.0;} }
00074 
00075 
00076 };
00077 
00078 #endif

Generated on Wed Dec 21 16:00:48 2005 for Geophysics & Astrophysics Spectral Element Adaptive Refinement (GASpAR) 2D Code by  doxygen 1.4.4