Claw  1.7.0
box_2d.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 */
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       self_type join( const self_type& r ) const;
00079       bool empty() const;
00080 
00081       value_type top() const;
00082       value_type bottom() const;
00083       value_type left() const;
00084       value_type right() const;
00085       point_type top_left() const;
00086       point_type top_right() const;
00087       point_type bottom_left() const;
00088       point_type bottom_right() const;
00089 
00090       void top( const value_type& p );
00091       void bottom( const value_type& p );
00092       void left( const value_type& p );
00093       void right( const value_type& p );
00094       void top_left( const coordinate_2d<value_type>& p );
00095       void top_right( const coordinate_2d<value_type>& p );
00096       void bottom_left( const coordinate_2d<value_type>& p );
00097       void bottom_right( const coordinate_2d<value_type>& p );
00098 
00099       void shift_x( const value_type& d );
00100       void shift_y( const value_type& d );
00101 
00102       value_type width() const;
00103       value_type height() const;
00104 
00105       coordinate_2d<value_type> size() const;
00106 
00107       bool operator==(const self_type& vect) const;
00108       bool operator!=(const self_type& vect) const;
00109       self_type operator+(const point_type& vect) const;
00110       self_type operator-(const point_type& vect) const;
00111       self_type& operator+=(const point_type& vect);
00112       self_type& operator-=(const point_type& vect);
00113 
00114     private:
00115       void x_intersection( const self_type& r, self_type& result ) const;
00116       void y_intersection( const self_type& r, self_type& result ) const;
00117 
00118     public:
00120       point_type first_point;
00121 
00123       point_type second_point;
00124 
00125     }; // class box_2d
00126   } // namespace math
00127 } // namespace claw
00128 
00129 #include <claw/impl/box_2d.tpp>
00130 
00131 #endif // __CLAW_BOX_2D_HPP__