Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Rectangle.h

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007         Adapted from
00008 
00009         The Universe Development Kit
00010         Copyright (C) 2000  Sean O'Neil
00011         s_p_oneil@hotmail.com
00012 
00013     This library is free software; you can redistribute it and/or
00014     modify it under the terms of the GNU Lesser General Public
00015     License as published by the Free Software Foundation; either
00016     version 2.1 of the License, or (at your option) any later version.
00017 
00018     This library is distributed in the hope that it will be useful,
00019     but WITHOUT ANY WARRANTY; without even the implied warranty of
00020     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021     Lesser General Public License for more details.
00022 
00023     You should have received a copy of the GNU Lesser General Public
00024     License along with this library; if not, write to the Free Software
00025     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027     $Id:  $
00028 */
00029 
00030 
00031 #ifndef TEDDY__MATHS__RECT__H
00032 #define TEDDY__MATHS__RECT__H
00033 
00034 
00035 #include "Teddy/SysSupport/StdMaths.h"
00036 
00037 
00038 namespace Teddy {
00039 namespace Maths {
00040 
00041 
00042 #define Rect    TRect<float>
00043 #define IntRect TRect<int>
00044 
00045 
00046 template<typename T> class TRect {
00047     TVector2<T> min;
00048     TVector2<T> max;
00049 
00050     TRect(){}
00051     TRect( const TVector2<T> &a, const TVector2<T> &b ){
00052         min = a;
00053         max = b;
00054     }
00055 
00056     TRect intersection( const TRect &a ){
00057         return TRect(
00058             TVector2<T>(
00059                 MAX( min[0], a.min[0] ) ,
00060                 MAX( min[1], a.min[1] )
00061             ),
00062             TVector2<T>(
00063                 MIN( max[0], a.max[0] ),
00064                 MIN( max[1], a.amx[1] )
00065             )
00066         );
00067     }
00068 
00069     bool hit( const TVector2<T> v ){
00070         return
00071             (v[0] >= min[0]) &&
00072             (v[0] <= max[0]) &&
00073             (v[1] >= min[1]) &&
00074             (v[1] <= max[3]);
00075     }
00076 };
00077 
00078 
00079 };  //  namespace Maths
00080 };  //  namespace Teddy
00081 
00082 
00083 #endif  //  TEDDY__MATHS__RECT__H
00084