point.h

Go to the documentation of this file.
00001 /*
00002  *  The Mana World Server
00003  *  Copyright 2004 The Mana World Development Team
00004  *
00005  *  This file is part of The Mana World.
00006  *
00007  *  The Mana World  is free software; you can redistribute  it and/or modify it
00008  *  under the terms of the GNU General  Public License as published by the Free
00009  *  Software Foundation; either version 2 of the License, or any later version.
00010  *
00011  *  The Mana  World is  distributed in  the hope  that it  will be  useful, but
00012  *  WITHOUT ANY WARRANTY; without even  the implied warranty of MERCHANTABILITY
00013  *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00014  *  more details.
00015  *
00016  *  You should  have received a  copy of the  GNU General Public  License along
00017  *  with The Mana  World; if not, write to the  Free Software Foundation, Inc.,
00018  *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019  *
00020  *  $Id: point.h 3229 2007-03-23 00:38:23Z b_lindeijer $
00021  */
00022 
00023 #ifndef _TMWSERV_POINT_H_
00024 #define _TMWSERV_POINT_H_
00025 
00026 #include <algorithm>
00027 
00031 class Point
00032 {
00033     public:
00034         Point():
00035             x(0), y(0)
00036         {}
00037 
00038         Point(unsigned short X, unsigned short Y):
00039             x(X), y(Y)
00040         {}
00041 
00042         unsigned short x; 
00043         unsigned short y; 
00048         bool inRangeOf(Point const &p, int radius) const
00049         {
00050             return std::abs(x - p.x) <= radius &&
00051                    std::abs(y - p.y) <= radius;
00052         }
00053 
00054         bool operator== (const Point &other) const
00055         {
00056             return (x == other.x && y == other.y);
00057         }
00058 
00059         bool operator!= (const Point &other) const
00060         {
00061             return (x != other.x || y != other.y);
00062         }
00063 };
00064 
00069 class Rectangle
00070 {
00071     public:
00072         unsigned short x; 
00073         unsigned short y; 
00074         unsigned short w; 
00075         unsigned short h; 
00077         bool contains(Point const &p) const
00078         {
00079             return (unsigned short)(p.x - x) < w &&
00080                    (unsigned short)(p.y - y) < h;
00081         }
00082 };
00083 
00084 #endif // _TMWSERV_POINT_H_

Generated on Fri Mar 30 15:39:16 2007 for TMW Server by  doxygen 1.3.9.1