claw 1.9.0
 
Loading...
Searching...
No Matches
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@stuff-o-matic.com
24*/
30#ifndef __CLAW_BOX_2D_HPP__
31#define __CLAW_BOX_2D_HPP__
32
34
35namespace claw
36{
37 namespace math
38 {
39 template <class T>
40 class rectangle;
41
46 template <class T>
47 class box_2d
48 {
49 public:
51 typedef T value_type;
52
56
58 typedef box_2d<value_type> self_type;
59
60 public:
61 box_2d();
62 box_2d(const self_type& that);
63 box_2d(const rectangle<value_type>& that);
64 box_2d(const point_type& p1, const point_type& p2);
65 box_2d(const value_type& x1, const value_type& y1, const value_type& x2,
66 const value_type& y2);
67
68 void set(const value_type& x1, const value_type& y1,
69 const value_type& x2, const value_type& y2);
70
71 template <typename U>
72 box_2d<U> cast_value_type_to() const;
73
74 value_type area() const;
75 bool includes(const coordinate_2d<value_type>& p) const;
76 bool includes(const self_type& r) const;
77 bool intersects(const self_type& r) const;
78 self_type intersection(const self_type& r) const;
79 self_type join(const self_type& r) const;
80 bool empty() const;
81
82 value_type top() const;
83 value_type bottom() const;
84 value_type left() const;
85 value_type right() const;
86 point_type top_left() const;
87 point_type top_right() const;
88 point_type bottom_left() const;
89 point_type bottom_right() const;
90
91 void top(const value_type& p);
92 void bottom(const value_type& p);
93 void left(const value_type& p);
94 void right(const value_type& p);
95 void top_left(const coordinate_2d<value_type>& p);
96 void top_right(const coordinate_2d<value_type>& p);
97 void bottom_left(const coordinate_2d<value_type>& p);
98 void bottom_right(const coordinate_2d<value_type>& p);
99
100 void shift_x(const value_type& d);
101 void shift_y(const value_type& d);
102
103 value_type width() const;
104 value_type height() const;
105
106 coordinate_2d<value_type> size() const;
107
108 bool operator==(const self_type& vect) const;
109 bool operator!=(const self_type& vect) const;
110 self_type operator+(const point_type& vect) const;
111 self_type operator-(const point_type& vect) const;
112 self_type& operator+=(const point_type& vect);
113 self_type& operator-=(const point_type& vect);
114
115 private:
116 void x_intersection(const self_type& r, self_type& result) const;
117 void y_intersection(const self_type& r, self_type& result) const;
118
119 public:
122
125
126 }; // class box_2d
127 }
128}
129
130#include <claw/box_2d.tpp>
131
132#endif // __CLAW_BOX_2D_HPP__
coordinate_2d< value_type > point_type
The type of the coordinates of the points representing the corners.
Definition box_2d.hpp:55
T value_type
The type of the values we store.
Definition box_2d.hpp:51
box_2d< value_type > self_type
The type of the current class.
Definition box_2d.hpp:58
Coordinates in a two dimensional space.
A class representing a rectangle by his x,y coordinates, width and height.
Definition rectangle.hpp:52
Coordinates in a two dimensional space.
Manipulation of mathematic, geometric, etc. items.
Definition box_2d.hpp:38
This is the main namespace.