Claw 1.7.0
rectangle.hpp
Go to the documentation of this file.
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-2011 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@gamned.org
00024 */
00031 #ifndef __CLAW_RECTANGLE_HPP__
00032 #define __CLAW_RECTANGLE_HPP__
00033 
00034 #include <claw/coordinate_2d.hpp>
00035 #include <claw/box_2d.hpp>
00036 
00037 namespace claw
00038 {
00039   namespace math
00040   {
00050     template<class T>
00051     class rectangle
00052     {
00053     public:
00055       typedef T value_type;
00056 
00058       typedef rectangle<value_type> self_type;
00059 
00060     public:
00061       rectangle();
00062 
00063       template<typename  U>
00064       rectangle( const rectangle<U>& that );
00065 
00066       template<typename  U>
00067       rectangle( const box_2d<U>& that );
00068 
00069       rectangle( const value_type& _x, const value_type& _y,
00070                  const value_type& _width, const value_type& _height);
00071 
00072       template<typename U>
00073       rectangle( const coordinate_2d<U>& pos, const value_type& _width,
00074                  const value_type& _height );
00075 
00076       template<typename U>
00077       rectangle( const coordinate_2d<U>& pos, const coordinate_2d<U>& size );
00078 
00079       template<typename U>
00080       rectangle<U> cast_value_type_to() const;
00081 
00082       bool operator==( const self_type& that ) const;
00083       bool operator!=( const self_type& that ) const;
00084       
00085       value_type area() const;
00086       bool includes( const coordinate_2d<value_type>& p ) const;
00087       bool includes( const self_type& r ) const;
00088       bool intersects( const self_type& r ) const;
00089       self_type intersection( const self_type& r ) const;
00090 
00091       void set( const value_type& new_x, const value_type& new_y,
00092                 const value_type& new_width, const value_type& new_height );
00093 
00094       value_type left() const;
00095       value_type right() const;
00096       value_type bottom() const;
00097       value_type top() const;
00098 
00099       coordinate_2d<value_type> size() const;
00100 
00101     private:
00102       void x_intersection( const self_type& r, self_type& result ) const;
00103       void y_intersection( const self_type& r, self_type& result ) const;
00104 
00105     public:
00107       coordinate_2d<value_type> position;
00108 
00110       value_type width;
00111 
00113       value_type height;
00114 
00115     }; // class rectangle
00116   } // namespace math
00117 } // namespace claw
00118 
00119 #include <claw/impl/rectangle.tpp>
00120 
00121 #endif // __CLAW_RECTANGLE_HPP__