Claw  1.7.3
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>
80  rectangle<U> cast_value_type_to() const;
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  self_type join( const self_type& r ) const;
91 
92  void set( const value_type& new_x, const value_type& new_y,
93  const value_type& new_width, const value_type& new_height );
94 
95  value_type left() const;
96  value_type right() const;
97  value_type bottom() const;
98  value_type top() const;
99 
101 
102  private:
103  void x_intersection( const self_type& r, self_type& result ) const;
104  void y_intersection( const self_type& r, self_type& result ) const;
105 
106  public:
109 
112 
115 
116  }; // class rectangle
117  } // namespace math
118 } // namespace claw
119 
120 #include <claw/impl/rectangle.tpp>
121 
122 #endif // __CLAW_RECTANGLE_HPP__
T value_type
The type of the values we store.
Definition: rectangle.hpp:55
coordinate_2d< value_type > position
value_typeop left coordinates.
Definition: rectangle.hpp:108
coordinate_2d< value_type > size() const
Get the size of the rectangle.
Definition: rectangle.tpp:329
Coordinates in a two dimensional space.
A rectangle represented by two points in a 2D space.
bool operator!=(const self_type &that) const
Tell if this rectangle equals an other rectangle.
Definition: rectangle.tpp:164
void set(const value_type &new_x, const value_type &new_y, const value_type &new_width, const value_type &new_height)
set new position and size to the rectangle.
Definition: rectangle.tpp:270
Implementation of claw::math::rectangle class.
value_type right() const
Get the x-coordinate of the right edge.
Definition: rectangle.tpp:296
self_type join(const self_type &r) const
Get the smallest rectangle bounding both this rectangle and another one.
Definition: rectangle.tpp:248
bool intersects(const self_type &r) const
Tell if there is an intersection of two rectangles.
Definition: rectangle.tpp:212
Coordinates in a two dimensional space.
A class representing a rectangle by his x,y coordinates, width and height.
Definition: box_2d.hpp:39
value_type left() const
Get the x-coordinate of the left edge.
Definition: rectangle.tpp:285
rectangle()
Constructor.
Definition: rectangle.tpp:37
value_type area() const
Calculate the rectangle&#39;s area.
Definition: rectangle.tpp:175
value_type height
Height.
Definition: rectangle.hpp:114
self_type intersection(const self_type &r) const
Intersection of two rectangles.
Definition: rectangle.tpp:227
value_type bottom() const
Get the y-coordinate of the bottom edge.
Definition: rectangle.tpp:307
rectangle< value_type > self_type
The type of the current class.
Definition: rectangle.hpp:58
bool operator==(const self_type &that) const
Tell if this rectangle equals an other rectangle.
Definition: rectangle.tpp:152
A rectangle represented by two points in a 2D space.
Definition: box_2d.hpp:46
value_type top() const
Get the y-coordinate of the top edge.
Definition: rectangle.tpp:318
value_type width
Width.
Definition: rectangle.hpp:111
bool includes(const coordinate_2d< value_type > &p) const
Tell if a point is in a rectangle.
Definition: rectangle.tpp:187