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

rect.h

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2002 Xavier Trochu
00003 
00004 This software is provided 'as-is', without any express or implied warranty. In no event
00005 will the authors be held liable for any damages arising from the use of this software.
00006 
00007 Permission is granted to anyone to use this software for any purpose, including commercial
00008 applications, and to alter it and redistribute it freely, subject to the following
00009 restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you
00012    wrote the original software. If you use this software in a product, an acknowledgment
00013    in the product documentation would be appreciated but is not required.
00014 
00015 2. Altered source versions must be plainly marked as such, and must not be misrepresented 
00016    as being the original software.
00017 
00018 3. This notice may not be removed or altered from any source distribution.
00019 */
00020 #ifndef __RECT_H_
00021 #define __RECT_H_
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include "config.h"
00025 #endif
00026 
00027 #include <ostream>
00028 
00033 class point {
00034 private:
00035     int _x; 
00036     int _y; 
00037 public:
00038     point() throw() : _x(0), _y(0) {};
00039     point(const point & p) throw() : _x(p.get_x()), _y(p.get_y()) {};
00040     explicit point(int x, int y) throw() : _x(x), _y(y) {};
00041     point & operator=(const point & p) throw() { _x = p.get_x(); _y = p.get_y(); return *this; };
00042     bool operator==(const point & p) const throw() { return _x == p.get_x() && _y == p.get_y(); };
00043     const int & get_x() const throw() { return _x; };
00044     const int & get_y() const throw() { return _y; };
00045     int & get_x() throw() { return _x; };
00046     int & get_y() throw() { return _y; };
00047     point operator+(const point & p) const throw() { return point(_x+p.get_x(), _y+p.get_y()); };
00048     point operator-(const point & p) const throw() { return point(_x-p.get_x(), _y-p.get_y()); };
00049     point & operator+=(const point & p) throw() { _x += p.get_x(); _y += p.get_y(); return *this; };
00050     point & operator-=(const point & p) throw() { _x -= p.get_x(); _y -= p.get_y(); return *this; };
00051     bool is_origin() const throw() { return *this == point(0, 0); };
00052     void set(int x, int y) throw() { _x = x; _y = y; }
00053 };
00054 
00060 class rect {
00061 private:
00062     point _topleft;     
00063     point _bottomright; 
00064 protected:
00065     void check() throw(std::exception);
00066 public:
00067     rect() throw();
00068     rect(int x, int y) throw(std::exception);
00069     explicit rect(const point & size) throw(std::exception);
00070     rect(int x1, int y1, int x2, int y2) throw(std::exception);
00071     rect(const point & topleft, const point & bottomright) throw(std::exception);
00072     rect(const rect & r) throw();
00073     rect & operator=(const rect & r) throw();
00074     bool operator==(const rect & r) const throw();
00075     point size() const throw() { return (_bottomright - _topleft); };
00076     int width() const throw() { return size().get_x(); }
00077     int height() const throw() { return size().get_y(); }
00078     int left() const throw() { return _topleft.get_x(); }
00079     int right() const throw() { return _bottomright.get_x(); }
00080     int top() const throw() { return _topleft.get_y(); }
00081     int bottom() const throw() { return _bottomright.get_y(); }
00082     const point & topleft() const throw() { return _topleft; }
00083     const point & bottomright() const throw() { return _bottomright; }
00084     
00092     bool is_inside(int x, int y) const throw();
00099     bool is_inside(const point & p) const throw();
00100     bool clip(rect & r) const throw(std::exception);
00101 };
00102 
00103 extern std::ostream & operator<<(std::ostream & o, const rect & r);
00104 extern std::ostream & operator<<(std::ostream & o, const point & p);
00105 
00106 #endif

Generated on Fri Aug 9 22:54:29 2002 for san_player by doxygen1.2.16