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-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 */
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       value_type area() const;
00083       bool includes( const coordinate_2d<value_type>& p ) const;
00084       bool includes( const self_type& r ) const;
00085       bool intersects( const self_type& r ) const;
00086       self_type intersection( const self_type& r ) const;
00087 
00088       void set( const value_type& new_x, const value_type& new_y,
00089                 const value_type& new_width, const value_type& new_height );
00090 
00091       value_type left() const;
00092       value_type right() const;
00093       value_type bottom() const;
00094       value_type top() const;
00095 
00096       coordinate_2d<value_type> size() const;
00097 
00098     private:
00099       void x_intersection( const self_type& r, self_type& result ) const;
00100       void y_intersection( const self_type& r, self_type& result ) const;
00101 
00102     public:
00104       coordinate_2d<value_type> position;
00105 
00107       value_type width;
00108 
00110       value_type height;
00111 
00112     }; // class rectangle
00113   } // namespace math
00114 } // namespace claw
00115 
00116 #include <claw/impl/rectangle.tpp>
00117 
00118 #endif // __CLAW_RECTANGLE_HPP__

Generated on Mon Nov 9 05:08:18 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.4.7