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

rect.h

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: rect.h,v 1.4 2003/11/14 14:05:54 fruit Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 #ifndef SALT_RECT_H
00023 #define SALT_RECT_H
00024 
00025 #ifdef HAVE_CONFIG_H
00026 #include <config.h>
00027 #endif
00028 
00029 #include "defines.h"
00030 
00031 namespace salt
00032 {
00033 
00035 class Rect
00036 {
00037 public:
00039     f_inline                Rect()                                                                                                  { }
00041     f_inline                Rect(const Rect &inOther)                                                               : mLeft(inOther.Left()), mTop(inOther.Top()), mRight(inOther.Right()), mBottom(inOther.Bottom()) { }
00042 
00044     f_inline                Rect(int inLeft, int inTop, int inRight, int inBottom)  : mLeft(inLeft), mTop(inTop), mRight(inRight), mBottom(inBottom) { }
00045 
00047     f_inline void   Set(int inLeft, int inTop, int inRight, int inBottom)   { mLeft=inLeft; mTop=inTop;                     mRight=inRight;                                                 mBottom=inBottom; }
00048 
00049     // member access
00051     f_inline int    Left() const                    { return mLeft; }
00052 
00054     f_inline int    Right() const                   { return mRight; }
00055 
00057     f_inline int    Top() const                     { return mTop; }
00058 
00060     f_inline int    Bottom() const                  { return mBottom; }
00061 
00063     f_inline int    Width() const                   { return mRight-mLeft; }
00064 
00066     f_inline int    Height() const                  { return mBottom-mTop; }
00067 
00069 
00070     f_inline void   Normalize()                                                                             { if (mRight < mLeft) gSwap(mLeft, mRight); if (mBottom < mTop) gSwap(mTop, mBottom); }
00071 
00073     f_inline void   Widen(int inDelta)                                                              { mLeft-=inDelta; mTop-=inDelta; mRight+=inDelta; mBottom+=inDelta;     }
00074 
00078     f_inline void   Widen(int inDeltaWidth, int inDeltaHeight)              { mRight+=inDeltaWidth; mBottom+=inDeltaHeight; }
00079 
00084     f_inline void   Widen(int inDeltaLeft, int inDeltaTop, int inDeltaRight, int inDeltaBottom)     { mLeft-=inDeltaLeft; mTop-=inDeltaTop; mRight+=inDeltaRight; mBottom+=inDeltaBottom;           }
00085 
00087     f_inline void   Shrink(int inDelta)                                                             { mLeft+=inDelta;       mTop+=inDelta;  mRight-=inDelta; mBottom-=inDelta;      }
00088 
00092     f_inline void   Shrink(int inDeltaWidth, int inDeltaHeight)             { mRight-=inDeltaWidth; mBottom-=inDeltaHeight; }
00093 
00098     f_inline void   Shrink(int inDeltaLeft, int inDeltaTop, int inDeltaRight, int inDeltaBottom) { mLeft+=inDeltaLeft; mTop+=inDeltaTop; mRight-=inDeltaRight; mBottom-=inDeltaBottom;              }
00099 
00101     f_inline void   Offset(int inDeltaX, int inDeltaY)                              { mLeft+=inDeltaX;      mTop+=inDeltaY; mRight+=inDeltaX;       mBottom+=inDeltaY; }
00102 
00104     f_inline bool   Intersects(const Rect &b) const                                 { return !(mLeft > b.mRight || mRight < b.mLeft || mTop > b.mBottom || mBottom < b.mTop); }
00105 
00106     // assignment
00107 
00109     f_inline Rect&          operator=(const Rect &inOther)                                                          { mLeft=inOther.Left(); mTop=inOther.Top();     mRight=inOther.Right(); mBottom=inOther.Bottom(); return *this; }
00110 
00111     // comparison
00112 
00114     f_inline bool           operator==(const Rect &inRHS) const                                                     { return (mLeft==inRHS.Left()) && (mTop==inRHS.Top()) && (mRight==inRHS.Right()) && (mBottom==inRHS.Bottom()); }
00115 
00117     f_inline bool           operator!=(const Rect &inRHS) const                                                     { return (mLeft!=inRHS.Left()) || (mTop!=inRHS.Top()) || (mRight!=inRHS.Right()) || (mBottom!=inRHS.Bottom()); }
00118 
00119 private:
00121     int mLeft;
00122 
00124     int mTop;
00125 
00127     int mRight;
00128 
00130     int mBottom;
00131 };
00132 
00133 } //namespace salt
00134 
00135 #endif //SALT_RECT_H

Generated on Thu Apr 6 15:25:39 2006 for rcssserver3d by  doxygen 1.4.4