Claw  1.7.3
box_2d.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 */
30 #ifndef __CLAW_BOX_2D_HPP__
31 #define __CLAW_BOX_2D_HPP__
32 
33 #include <claw/coordinate_2d.hpp>
34 
35 namespace claw
36 {
37  namespace math
38  {
39  template<class T> class rectangle;
40 
45  template <class T>
46  class box_2d
47  {
48  public:
50  typedef T value_type;
51 
55 
58 
59  public:
60  box_2d();
61  box_2d( const self_type& that );
62  box_2d( const rectangle<value_type>& that );
63  box_2d( const point_type& p1, const point_type& p2 );
64  box_2d( const value_type& x1, const value_type& y1,
65  const value_type& x2, const value_type& y2 );
66 
67  void set( const value_type& x1, const value_type& y1,
68  const value_type& x2, const value_type& y2 );
69 
70  template<typename U>
72 
73  value_type area() const;
74  bool includes( const coordinate_2d<value_type>& p ) const;
75  bool includes( const self_type& r ) const;
76  bool intersects( const self_type& r ) const;
77  self_type intersection( const self_type& r ) const;
78  self_type join( const self_type& r ) const;
79  bool empty() const;
80 
81  value_type top() const;
82  value_type bottom() const;
83  value_type left() const;
84  value_type right() const;
85  point_type top_left() const;
86  point_type top_right() const;
87  point_type bottom_left() const;
88  point_type bottom_right() const;
89 
90  void top( const value_type& p );
91  void bottom( const value_type& p );
92  void left( const value_type& p );
93  void right( const value_type& p );
94  void top_left( const coordinate_2d<value_type>& p );
95  void top_right( const coordinate_2d<value_type>& p );
96  void bottom_left( const coordinate_2d<value_type>& p );
97  void bottom_right( const coordinate_2d<value_type>& p );
98 
99  void shift_x( const value_type& d );
100  void shift_y( const value_type& d );
101 
102  value_type width() const;
103  value_type height() const;
104 
106 
107  bool operator==(const self_type& vect) const;
108  bool operator!=(const self_type& vect) const;
109  self_type operator+(const point_type& vect) const;
110  self_type operator-(const point_type& vect) const;
111  self_type& operator+=(const point_type& vect);
112  self_type& operator-=(const point_type& vect);
113 
114  private:
115  void x_intersection( const self_type& r, self_type& result ) const;
116  void y_intersection( const self_type& r, self_type& result ) const;
117 
118  public:
121 
124 
125  }; // class box_2d
126  } // namespace math
127 } // namespace claw
128 
129 #include <claw/impl/box_2d.tpp>
130 
131 #endif // __CLAW_BOX_2D_HPP__