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

Rect.H

Go to the documentation of this file.
00001 
00015 #ifndef RECT_H
00016 #define RECT_H
00017 
00018 #include <Vector.H> 
00019 
00020 namespace xchen
00021 {
00022   template <class T>
00023   class Rect 
00024   {
00025   public:
00026       Rect(T sx=0, T sy=0, T w=1, T h=1);
00027 
00028       T StartX() const                     { return startx; }
00029       T StartY() const                     { return starty; }
00030       T Width()  const                     { return width;  }
00031       T Height() const                     { return height; }
00032 
00033       T& StartX()                      { return startx; }
00034       T& StartY()                      { return starty; }
00035       T& Width()                       { return width;  }
00036       T& Height()                      { return height; }
00037 
00038       Vector<T,2> LowerLeft() const        { return Vector<T,2>(startx, starty); }
00039       Vector<T,2> UpperRight() const       { return Vector<T,2>(startx+width, starty+height); }
00040       dVector2D Center() const             { return dVector2D(startx + width/2.0, starty+height/2.0); }
00041 
00042 
00043       bool Contain(T x, T y) const         { return x>startx && x<startx+width && y>starty && y<starty+height; }
00044 
00045   private:
00046       T startx, starty;
00047       T width, height;
00048   };
00049 
00050 
00051   template <class T>
00052   inline ostream &operator<<(ostream &os, const Rect<T> &r) {
00053     return
00054       os << "(" << r.StartX() << ", " << r.StartY() << ", " << r.Width() << ", " << r.Height() << ")\n";
00055   }
00056   template <class T>
00057   inline Rect<T> operator * (T a, const Rect<T>& r)
00058   {
00059     return Rect<T> (a * r.StartX(), a * r.StartY(), a * r.Width() , a * r.Height());
00060   }
00061   template <class T>
00062   inline Rect<T> operator * (const Rect<T>& r, T a)
00063   {
00064     return Rect<T> (a * r.StartX(), a * r.StartY(), a * r.Width(), a * r.Height());
00065   }
00066 
00067   typedef Rect<int> iRect;
00068   typedef Rect<double> dRect;
00069 
00070   typedef dRect XiaViewPort;
00071   typedef iRect GLViewPort;
00072   typedef dRect OrthoClip;
00073 
00074 
00075   template <class T>
00076   inline Rect<T> :: Rect<T>(T sx, T sy, T w, T h) : startx(sx), starty(sy), width(w), height(h)
00077   {
00078   }
00079 }
00080 
00081 #endif

Generated on Wed Apr 7 21:40:49 2004 by doxygen1.2.18