]>
Dogcows Code - chaz/openbox/blob - otk/rect.hh
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
14 //! The Rect class defines a rectangle in the plane.
17 //! Constructs an invalid Rect
18 inline Rect(void) : _x1(0), _y1(0), _x2(0), _y2(0) { }
21 @param x The x component of the point defining the top left corner of the
23 @param y The y component of the point defining the top left corner of the
25 @param w The width of the rectangle
26 @param h The height of the rectangle
28 inline Rect(int x
, int y
, int w
, int h
)
29 : _x1(x
), _y1(y
), _x2(w
+ x
- 1), _y2(h
+ y
- 1) { }
30 //! Constructs a Rect from 2 Point objects
32 @param location The point defining the top left corner of the rectangle
33 @param size The width and height of the rectangle
35 inline Rect(const Point
&location
, const Point
&size
)
36 : _x1(location
.x()), _y1(location
.y()),
37 _x2(size
.x() + location
.x() - 1), _y2(size
.y() + location
.y() - 1) { }
38 //! Constructs a Rect from an XRectangle
39 inline explicit Rect(const XRectangle
& xrect
)
40 : _x1(xrect
.x
), _y1(xrect
.y
), _x2(xrect
.width
+ xrect
.x
- 1),
41 _y2(xrect
.height
+ xrect
.y
- 1) { }
43 //! Returns the left coordinate of the Rect. Identical to Rect::x.
44 inline int left(void) const { return _x1
; }
45 //! Returns the top coordinate of the Rect. Identical to Rect::y.
46 inline int top(void) const { return _y1
; }
47 //! Returns the right coordinate of the Rect
48 inline int right(void) const { return _x2
; }
49 //! Returns the bottom coordinate of the Rect
50 inline int bottom(void) const { return _y2
; }
52 //! The x component of the point defining the top left corner of the Rect
53 inline int x(void) const { return _x1
; }
54 //! The y component of the point defining the top left corner of the Rect
55 inline int y(void) const { return _y1
; }
56 //! Returns the Point that defines the top left corner of the rectangle
57 inline Point
location() const { return Point(_x1
, _y1
); }
59 //! Sets the x coordinate of the Rect.
61 @param x The new x component of the point defining the top left corner of
65 //! Sets the y coordinate of the Rect.
67 @param y The new y component of the point defining the top left corner of
71 //! Sets the x and y coordinates of the Rect.
73 @param x The new x component of the point defining the top left corner of
75 @param y The new y component of the point defining the top left corner of
78 void setPos(int x
, int y
);
79 //! Sets the x and y coordinates of the Rect.
81 @param location The point defining the top left corner of the rectangle.
83 void setPos(const Point
&location
);
85 //! The width of the Rect
86 inline int width(void) const { return _x2
- _x1
+ 1; }
87 //! The height of the Rect
88 inline int height(void) const { return _y2
- _y1
+ 1; }
89 //! Returns the size of the Rect
90 inline Point
size() const { return Point(_x2
- _x1
+ 1, _y2
- _y1
+ 1); }
92 //! Sets the width of the Rect
94 @param w The new width of the rectangle
97 //! Sets the height of the Rect
99 @param h The new height of the rectangle
101 void setHeight(int h
);
102 //! Sets the size of the Rect.
104 @param w The new width of the rectangle
105 @param h The new height of the rectangle
107 void setSize(int w
, int h
);
108 //! Sets the size of the Rect.
110 @param size The new size of the rectangle
112 void setSize(const Point
&size
);
114 //! Sets the position and size of the Rect
116 @param x The new x component of the point defining the top left corner of
118 @param y The new y component of the point defining the top left corner of
120 @param w The new width of the rectangle
121 @param h The new height of the rectangle
123 void setRect(int x
, int y
, int w
, int h
);
124 //! Sets the position and size of the Rect
126 @param location The new point defining the top left corner of the rectangle
127 @param size The new size of the rectangle
129 void setRect(const Point
&location
, const Point
&size
);
131 //! Sets the position of all 4 sides of the Rect
133 @param l The new left coordinate of the rectangle
134 @param t The new top coordinate of the rectangle
135 @param r The new right coordinate of the rectangle
136 @param b The new bottom coordinate of the rectangle
138 void setCoords(int l
, int t
, int r
, int b
);
139 //! Sets the position of all 4 sides of the Rect
141 @param tl The new point at the top left of the rectangle
142 @param br The new point at the bottom right of the rectangle
144 void setCoords(const Point
&tl
, const Point
&br
);
146 //! Determines if two Rect objects are equal
148 The rectangles are considered equal if they are in the same position and
151 inline bool operator==(const Rect
&a
)
152 { return _x1
== a
._x1
&& _y1
== a
._y1
&& _x2
== a
._x2
&& _y2
== a
._y2
; }
153 //! Determines if two Rect objects are inequal
157 inline bool operator!=(const Rect
&a
) { return ! operator==(a
); }
159 //! Returns the union of two Rect objects
161 The union of the rectangles will consist of the maximimum area that the two
162 rectangles can make up.
163 @param a A second Rect object to form a union with.
165 Rect
operator|(const Rect
&a
) const;
166 //! Returns the intersection of two Rect objects
168 The intersection of the rectangles will consist of just the area where the
169 two rectangles overlap.
170 @param a A second Rect object to form an intersection with.
171 @return The intersection between this Rect and the one passed to the
174 Rect
operator&(const Rect
&a
) const;
175 //! Sets the Rect to the union of itself with another Rect object
177 The union of the rectangles will consist of the maximimum area that the two
178 rectangles can make up.
179 @param a A second Rect object to form a union with.
180 @return The union between this Rect and the one passed to the function
182 inline Rect
&operator|=(const Rect
&a
) { *this = *this | a
; return *this; }
183 //! Sets the Rect to the intersection of itself with another Rect object
185 The intersection of the rectangles will consist of just the area where the
186 two rectangles overlap.
187 @param a A second Rect object to form an intersection with.
189 inline Rect
&operator&=(const Rect
&a
) { *this = *this & a
; return *this; }
191 //! Returns if the Rect is valid
193 A rectangle is valid only if its right and bottom coordinates are larger
194 than its left and top coordinates (i.e. it does not have a negative width
196 @return true if the Rect is valid; otherwise, false
198 inline bool valid(void) const { return _x2
> _x1
&& _y2
> _y1
; }
200 //! Determines if this Rect intersects another Rect
202 The rectangles intersect if any part of them overlaps.
203 @param a Another Rect object to compare this Rect with
204 @return true if the Rect objects overlap; otherwise, false
206 bool intersects(const Rect
&a
) const;
207 //! Determines if this Rect contains a point
209 The rectangle contains the point if it falls within the rectangle's
211 @param x The x coordinate of the point to operate on
212 @param y The y coordinate of the point to operate on
213 @return true if the point is contained within this Rect; otherwise, false
215 bool contains(int x
, int y
) const;
216 //! Determines if this Rect contains another Rect entirely
218 This rectangle contains the second rectangle if it is entirely within this
219 rectangle's boundaries.
220 @param a The Rect to test for containment inside of this Rect
221 @return true if the second Rect is contained within this Rect; otherwise,
224 bool contains(const Rect
&a
) const;
227 //! The left coordinate of the Rect
229 //! The top coordinate of the Rect
231 //! The right coordinate of the Rect
233 //! The bottom coordinate of the Rect
237 //! A list for Rect objects
238 typedef std::vector
<Rect
> RectList
;
This page took 0.047061 seconds and 4 git commands to generate.