Main Page | Class Hierarchy | Class List | File List | Class Members

rectangle.h

00001 //-< CRECTANGLE.H >--------------------------------------------------*--------*
00002 // GigaBASE                  Version 1.0         (c) 1999  GARRET    *     ?  *
00003 // (Post Relational Database Management System)                      *   /\|  *
00004 //                                                                   *  /  \  *
00005 //                          Created:     26-Nov-2001  K.A. Knizhnik  * / [] \ *
00006 //                          Last update: 26-Nov-2001   K.A. Knizhnik  * GARRET *
00007 //-------------------------------------------------------------------*--------*
00008 // Rectangle class
00009 //-------------------------------------------------------------------*--------*
00010 
00011 #ifndef __RECTANGLE_H__
00012 #define __RECTANLGE_H__
00013 
00014 BEGIN_GIGABASE_NAMESPACE
00015 
00016 #ifndef RECTANGLE_DIMENSION
00017 #define RECTANGLE_DIMENSION 2
00018 #endif 
00019 
00020 #ifndef RECTANGLE_COORDINATE_TYPE
00021 #define RECTANGLE_COORDINATE_TYPE int4
00022 #endif
00023 
00024 
00025 typedef RECTANGLE_COORDINATE_TYPE coord_t;
00026 
00030 class GIGABASE_DLL_ENTRY rectangle
00031 {
00032   public:
00033     enum { dim = RECTANGLE_DIMENSION };
00040     coord_t boundary[dim*2];
00041 
00045     friend coord_t GIGABASE_DLL_ENTRY distance(rectangle const& r, rectangle const& q);
00046 
00050     friend coord_t area(rectangle const& r) { 
00051         coord_t area = 1;
00052         for (int i = dim; --i >= 0; area *= r.boundary[i+dim] - r.boundary[i]);
00053         return area;
00054     }
00055 
00059     void operator +=(rectangle const& r) { 
00060         int i = dim; 
00061         while (--i >= 0) { 
00062             boundary[i] = (boundary[i] <= r.boundary[i]) 
00063                 ? boundary[i] : r.boundary[i];
00064             boundary[i+dim] = (boundary[i+dim] >= r.boundary[i+dim]) 
00065                 ? boundary[i+dim] : r.boundary[i+dim];
00066         }
00067     }
00071     rectangle operator + (rectangle const& r) const { 
00072         rectangle res;
00073         int i = dim; 
00074         while (--i >= 0) { 
00075             res.boundary[i] = (boundary[i] <= r.boundary[i]) 
00076                 ? boundary[i] : r.boundary[i];
00077             res.boundary[i+dim] = (boundary[i+dim] >= r.boundary[i+dim]) 
00078                 ? boundary[i+dim] : r.boundary[i+dim];
00079         }
00080         return res;
00081     }
00085     bool operator & (rectangle const& r) const {
00086         int i = dim; 
00087         while (--i >= 0) { 
00088             if (boundary[i] > r.boundary[i+dim] ||
00089                 r.boundary[i] > boundary[i+dim])
00090             {
00091                 return false;
00092             }
00093         }
00094         return true;
00095     }
00100     bool operator <= (rectangle const& r) const { 
00101         int i = dim; 
00102         while (--i >= 0) { 
00103             if (boundary[i] < r.boundary[i] ||
00104                 boundary[i+dim] > r.boundary[i+dim])
00105             {
00106                 return false;
00107             }
00108         }
00109         return true;
00110     }
00115     bool operator >= (rectangle const& r) const { 
00116         int i = dim; 
00117         while (--i >= 0) { 
00118             if (r.boundary[i] < boundary[i] ||
00119                 r.boundary[i+dim] > boundary[i+dim])
00120             {
00121                 return false;
00122             }
00123         }
00124         return true;
00125     }
00126 
00131     bool operator < (rectangle const& r) const { 
00132         return *this <= r && *this != r;
00133     }
00138     bool operator > (rectangle const& r) const { 
00139         return *this >= r && *this != r;
00140     }
00144     bool operator == (rectangle const& r) const { 
00145         int i = dim*2; 
00146         while (--i >= 0) { 
00147             if (boundary[i] != r.boundary[i]) { 
00148                 return false;
00149             }
00150         }
00151         return true;
00152     }
00156     bool operator != (rectangle const& r) const { 
00157         int i = dim*2; 
00158         while (--i >= 0) { 
00159             if (boundary[i] != r.boundary[i]) { 
00160                 return true;
00161             }
00162         }
00163         return false;
00164     }
00165 
00166     typedef bool (rectangle::*comparator)(rectangle const& r) const;
00167 };
00168 
00169 END_GIGABASE_NAMESPACE
00170 
00171 #endif
00172 
00173 

Generated on Thu Feb 12 18:46:27 2004 for GigaBASE by doxygen 1.3.5