Claw  1.7.0
rectangle.hpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
31 #ifndef __CLAW_RECTANGLE_HPP__
32 #define __CLAW_RECTANGLE_HPP__
33 
34 #include <claw/coordinate_2d.hpp>
35 #include <claw/box_2d.hpp>
36 
37 namespace claw
38 {
39  namespace math
40  {
50  template<class T>
51  class rectangle
52  {
53  public:
55  typedef T value_type;
56 
59 
60  public:
61  rectangle();
62 
63  template<typename U>
64  rectangle( const rectangle<U>& that );
65 
66  template<typename U>
67  rectangle( const box_2d<U>& that );
68 
69  rectangle( const value_type& _x, const value_type& _y,
70  const value_type& _width, const value_type& _height);
71 
72  template<typename U>
73  rectangle( const coordinate_2d<U>& pos, const value_type& _width,
74  const value_type& _height );
75 
76  template<typename U>
77  rectangle( const coordinate_2d<U>& pos, const coordinate_2d<U>& size );
78 
79  template<typename U>
81 
82  bool operator==( const self_type& that ) const;
83  bool operator!=( const self_type& that ) const;
84 
85  value_type area() const;
86  bool includes( const coordinate_2d<value_type>& p ) const;
87  bool includes( const self_type& r ) const;
88  bool intersects( const self_type& r ) const;
89  self_type intersection( const self_type& r ) const;
90 
91  void set( const value_type& new_x, const value_type& new_y,
92  const value_type& new_width, const value_type& new_height );
93 
94  value_type left() const;
95  value_type right() const;
96  value_type bottom() const;
97  value_type top() const;
98 
100 
101  private:
102  void x_intersection( const self_type& r, self_type& result ) const;
103  void y_intersection( const self_type& r, self_type& result ) const;
104 
105  public:
108 
111 
114 
115  }; // class rectangle
116  } // namespace math
117 } // namespace claw
118 
119 #include <claw/impl/rectangle.tpp>
120 
121 #endif // __CLAW_RECTANGLE_HPP__