00001 /* 00002 CLAW - a C++ Library Absolutely Wonderful 00003 00004 CLAW is a free library without any particular aim but being useful to 00005 anyone. 00006 00007 Copyright (C) 2005-2008 Julien Jorge 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 contact: julien_jorge@yahoo.fr 00024 */ 00030 #ifndef __CLAW_BOX_2D_HPP__ 00031 #define __CLAW_BOX_2D_HPP__ 00032 00033 #include <claw/coordinate_2d.hpp> 00034 00035 namespace claw 00036 { 00037 namespace math 00038 { 00039 template<class T> class rectangle; 00040 00045 template <class T> 00046 class box_2d 00047 { 00048 public: 00050 typedef T value_type; 00051 00054 typedef coordinate_2d<value_type> point_type; 00055 00057 typedef box_2d<value_type> self_type; 00058 00059 public: 00060 box_2d(); 00061 box_2d( const self_type& that ); 00062 box_2d( const rectangle<value_type>& that ); 00063 box_2d( const point_type& p1, const point_type& p2 ); 00064 box_2d( const value_type& x1, const value_type& y1, 00065 const value_type& x2, const value_type& y2 ); 00066 00067 void set( const value_type& x1, const value_type& y1, 00068 const value_type& x2, const value_type& y2 ); 00069 00070 template<typename U> 00071 box_2d<U> cast_value_type_to() const; 00072 00073 value_type area() const; 00074 bool includes( const coordinate_2d<value_type>& p ) const; 00075 bool includes( const self_type& r ) const; 00076 bool intersects( const self_type& r ) const; 00077 self_type intersection( const self_type& r ) const; 00078 00079 value_type top() const; 00080 value_type bottom() const; 00081 value_type left() const; 00082 value_type right() const; 00083 point_type top_left() const; 00084 point_type top_right() const; 00085 point_type bottom_left() const; 00086 point_type bottom_right() const; 00087 00088 void top( const value_type& p ); 00089 void bottom( const value_type& p ); 00090 void left( const value_type& p ); 00091 void right( const value_type& p ); 00092 void top_left( const coordinate_2d<value_type>& p ); 00093 void top_right( const coordinate_2d<value_type>& p ); 00094 void bottom_left( const coordinate_2d<value_type>& p ); 00095 void bottom_right( const coordinate_2d<value_type>& p ); 00096 00097 void shift_x( const value_type& d ); 00098 void shift_y( const value_type& d ); 00099 00100 value_type width() const; 00101 value_type height() const; 00102 00103 coordinate_2d<value_type> size() const; 00104 00105 bool operator==(const self_type& vect) const; 00106 bool operator!=(const self_type& vect) const; 00107 self_type operator+(const point_type& vect) const; 00108 self_type operator-(const point_type& vect) const; 00109 self_type& operator+=(const point_type& vect); 00110 self_type& operator-=(const point_type& vect); 00111 00112 private: 00113 void x_intersection( const self_type& r, self_type& result ) const; 00114 void y_intersection( const self_type& r, self_type& result ) const; 00115 00116 public: 00118 point_type first_point; 00119 00121 point_type second_point; 00122 00123 }; // class box_2d 00124 } // namespace math 00125 } // namespace claw 00126 00127 #include <claw/impl/box_2d.tpp> 00128 00129 #endif // __CLAW_BOX_2D_HPP__