AaronCameron.net
No ads. No Profit. No Master, But Truth.
Not a Member? - Login or Create an Account
Wednesday the 23rd of May 2012 @ 05:52pm
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cRectangle2.h

Go to the documentation of this file.
00001 /************************************************************************
00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library
00003 Copyright (C) 2002  Aaron Cameron
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 
00019 A copy of the GNU Lesser General Public License has been provided with
00020 this library in the file 'COPYING'.
00021 
00022 Contact information for the author of this library has been provided
00023 with this library in the file 'AUTHOR'.
00024 ************************************************************************/
00025 
00026 #ifndef _n2l4_cRectangle2_h
00027 #define _n2l4_cRectangle2_h
00028 
00029 #include "n2l/n2l.h"
00030 #include "cVector2.h"
00031 
00032 #include <math.h>
00033 
00034 namespace n2l
00035 {
00039     template <  class TComponent,
00040                 class TComponentDiff,
00041                 class TMagnitude>
00042     class cRectangle2
00043     {
00044     public:
00045         typedef TComponent      tPosComponent;
00046         typedef TMagnitude      tSizeComponent;
00047         typedef TComponentDiff  tComponentDiff;
00048         typedef TMagnitude      tMagnitude;
00049 
00050         typedef cRectangle2<TComponent,TComponentDiff,TMagnitude> tThisRectangle;
00051 
00052         typedef cVector2<TComponent,TComponentDiff,TMagnitude> tPosVector;
00053         typedef cVector2<TMagnitude,TComponentDiff,TMagnitude> tSizeVector;
00054 
00055         /* ************************************************************ */
00056         cRectangle2() {}
00057 
00058         /* ************************************************************ */
00059         ~cRectangle2() {}
00060 
00061         /* ************************************************************ */
00062         cRectangle2(    const tPosComponent & iPosX,
00063                         const tPosComponent & iPosY,
00064                         const tSizeComponent & iSizeX,
00065                         const tSizeComponent & iSizeY ) :
00066             mPos(iPosX,iPosY),
00067             mSize(iSizeX,iSizeY) {}
00068 
00069 
00070         /* ************************************************************ */
00071         cRectangle2(    const tPosVector & iPos,
00072                         const tSizeVector & iSize ) :
00073             mPos(iPos),
00074             mSize(iSize) {}
00075 
00076 
00077         /* ************************************************************ */
00078         const tPosComponent & x() const { return mPos.x(); }
00079         const tPosComponent & y() const { return mPos.y(); }
00080 
00081         /* ************************************************************ */
00084         const tPosComponent x2() const { return mPos.x()+mSize.x(); }
00085 
00088         const tPosComponent y2() const { return mPos.y()+mSize.y(); }
00089 
00090         /* ************************************************************ */
00091         const tSizeComponent & w() const { return mSize.x(); }
00092         const tSizeComponent & h() const { return mSize.y(); }
00093 
00094 
00095         /* ************************************************************ */
00096         void x( const tPosComponent & iX ) { mPos.x(iX); }
00097         void y( const tPosComponent & iY ) { mPos.y(iY); }
00098 
00099         /* ************************************************************ */
00103         void x2( const tPosComponent & iX2 ) { mSize.x(iX2-mPos.x()+1); }
00104 
00105         /* ************************************************************ */
00109         void y2( const tPosComponent & iY2 ) { mSize.y(iY2-mPos.y()+1); }
00110 
00111 
00112         /* ************************************************************ */
00113         const tString dump() const {
00114             tString str("tRectangle2(");
00115             str += asString(mPos.x());
00116             str += ",";
00117             str += asString(mPos.y());
00118             str += " x ";
00119             str += asString(mSize.x());
00120             str += ",";
00121             str += asString(mSize.y());
00122             str += ")";
00123             return str;
00124         }
00125 
00126     protected:
00127 
00128     private:
00129         tPosVector  mPos;
00130         tSizeVector mSize;
00131 
00132     }; // class
00133 
00134 } // namespace n2l
00135 
00136 
00137 #endif
©2012 Aaron Cameron