]>
Dogcows Code - chaz/openbox/blob - otk/rect.hh
dc3d05d658b41008cd880d5684b36dc4a94784ae
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
13 //! The Rect class defines a rectangle in the plane.
16 //! Constructs an invalid Rect
17 inline Rect(void) : _x1(0), _y1(0), _x2(0), _y2(0) { }
20 @param x The x component of the point defining the top left corner of the
22 @param y The y component of the point defining the top left corner of the
24 @param w The width of the rectangle
25 @param h The height of the rectangle
27 inline Rect(int x
, int y
, unsigned int w
, unsigned int h
)
28 : _x1(x
), _y1(y
), _x2(w
+ x
- 1), _y2(h
+ y
- 1) { }
29 //! Constructs a Rect from 2 Point objects
31 @param location The point defining the top left corner of the rectangle
32 @param size The width and height of the rectangle
34 inline Rect(const Point
&location
, const Point
&size
)
35 : _x1(location
.x()), _y1(location
.y()),
36 _x2(size
.x() + location
.x() - 1), _y2(size
.y() + location
.y() - 1) { }
37 //! Constructs a Rect from an XRectangle
38 inline explicit Rect(const XRectangle
& xrect
)
39 : _x1(xrect
.x
), _y1(xrect
.y
), _x2(xrect
.width
+ xrect
.x
- 1),
40 _y2(xrect
.height
+ xrect
.y
- 1) { }
42 //! Returns the left coordinate of the Rect. Identical to Rect::x.
43 inline int left(void) const { return _x1
; }
44 //! Returns the top coordinate of the Rect. Identical to Rect::y.
45 inline int top(void) const { return _y1
; }
46 //! Returns the right coordinate of the Rect
47 inline int right(void) const { return _x2
; }
48 //! Returns the bottom coordinate of the Rect
49 inline int bottom(void) const { return _y2
; }
51 //! The x component of the point defining the top left corner of the Rect
52 inline int x(void) const { return _x1
; }
53 //! The y component of the point defining the top left corner of the Rect
54 inline int y(void) const { return _y1
; }
55 //! Returns the Point that defines the top left corner of the rectangle
56 inline Point
location() const { return Point(_x1
, _y1
); }
58 //! Sets the x coordinate of the Rect.
60 @param x The new x component of the point defining the top left corner of
64 //! Sets the y coordinate of the Rect.
66 @param y The new y component of the point defining the top left corner of
70 //! Sets the x and y coordinates of the Rect.
72 @param x The new x component of the point defining the top left corner of
74 @param y The new y component of the point defining the top left corner of
77 void setPos(int x
, int y
);
78 //! Sets the x and y coordinates of the Rect.
80 @param location The point defining the top left corner of the rectangle.
82 void setPos(const Point
&location
);
84 //! The width of the Rect
85 inline unsigned int width(void) const { return _x2
- _x1
+ 1; }
86 //! The height of the Rect
87 inline unsigned int height(void) const { return _y2
- _y1
+ 1; }
88 //! Returns the size of the Rect
89 inline Point
size() const { return Point(_x2
- _x1
+ 1, _y2
- _y1
+ 1); }
91 //! Sets the width of the Rect
93 @param w The new width of the rectangle
95 void setWidth(unsigned int w
);
96 //! Sets the height of the Rect
98 @param h The new height of the rectangle
100 void setHeight(unsigned int h
);
101 //! Sets the size of the Rect.
103 @param w The new width of the rectangle
104 @param h The new height of the rectangle
106 void setSize(unsigned int w
, unsigned int h
);
107 //! Sets the size of the Rect.
109 @param size The new size of the rectangle
111 void setSize(const Point
&size
);
113 //! Sets the position and size of the Rect
115 @param x The new x component of the point defining the top left corner of
117 @param y The new y component of the point defining the top left corner of
119 @param w The new width of the rectangle
120 @param h The new height of the rectangle
122 void setRect(int x
, int y
, unsigned int w
, unsigned int h
);
123 //! Sets the position and size of the Rect
125 @param location The new point defining the top left corner of the rectangle
126 @param size The new size of the rectangle
128 void setRect(const Point
&location
, const Point
&size
);
130 //! Sets the position of all 4 sides of the Rect
132 @param l The new left coordinate of the rectangle
133 @param t The new top coordinate of the rectangle
134 @param r The new right coordinate of the rectangle
135 @param b The new bottom coordinate of the rectangle
137 void setCoords(int l
, int t
, int r
, int b
);
138 //! Sets the position of all 4 sides of the Rect
140 @param tl The new point at the top left of the rectangle
141 @param br The new point at the bottom right of the rectangle
143 void setCoords(const Point
&tl
, const Point
&br
);
145 //! Determines if two Rect objects are equal
147 The rectangles are considered equal if they are in the same position and
150 inline bool operator==(const Rect
&a
)
151 { return _x1
== a
._x1
&& _y1
== a
._y1
&& _x2
== a
._x2
&& _y2
== a
._y2
; }
152 //! Determines if two Rect objects are inequal
156 inline bool operator!=(const Rect
&a
) { return ! operator==(a
); }
158 //! Returns the union of two Rect objects
160 The union of the rectangles will consist of the maximimum area that the two
161 rectangles can make up.
162 @param a A second Rect object to form a union with.
164 Rect
operator|(const Rect
&a
) const;
165 //! Returns the intersection of two Rect objects
167 The intersection of the rectangles will consist of just the area where the
168 two rectangles overlap.
169 @param a A second Rect object to form an intersection with.
170 @return The intersection between this Rect and the one passed to the
173 Rect
operator&(const Rect
&a
) const;
174 //! Sets the Rect to the union of itself with another Rect object
176 The union of the rectangles will consist of the maximimum area that the two
177 rectangles can make up.
178 @param a A second Rect object to form a union with.
179 @return The union between this Rect and the one passed to the function
181 inline Rect
&operator|=(const Rect
&a
) { *this = *this | a
; return *this; }
182 //! Sets the Rect to the intersection of itself with another Rect object
184 The intersection of the rectangles will consist of just the area where the
185 two rectangles overlap.
186 @param a A second Rect object to form an intersection with.
188 inline Rect
&operator&=(const Rect
&a
) { *this = *this & a
; return *this; }
190 //! Returns if the Rect is valid
192 A rectangle is valid only if its right and bottom coordinates are larger
193 than its left and top coordinates (i.e. it does not have a negative width
195 @return true if the Rect is valid; otherwise, false
197 inline bool valid(void) const { return _x2
> _x1
&& _y2
> _y1
; }
199 //! Determines if this Rect intersects another Rect
201 The rectangles intersect if any part of them overlaps.
202 @param a Another Rect object to compare this Rect with
203 @return true if the Rect objects overlap; otherwise, false
205 bool intersects(const Rect
&a
) const;
206 //! Determines if this Rect contains a point
208 The rectangle contains the point if it falls within the rectangle's
210 @param x The x coordinate of the point to operate on
211 @param y The y coordinate of the point to operate on
212 @return true if the point is contained within this Rect; otherwise, false
214 bool contains(int x
, int y
) const;
215 //! Determines if this Rect contains another Rect entirely
217 This rectangle contains the second rectangle if it is entirely within this
218 rectangle's boundaries.
219 @param a The Rect to test for containment inside of this Rect
220 @return true if the second Rect is contained within this Rect; otherwise,
223 bool contains(const Rect
&a
) const;
226 //! The left coordinate of the Rect
228 //! The top coordinate of the Rect
230 //! The right coordinate of the Rect
232 //! The bottom coordinate of the Rect
236 //! A list for Rect objects
237 typedef std::vector
<Rect
> RectList
;
This page took 0.045321 seconds and 4 git commands to generate.