]>
Dogcows Code - chaz/openbox/blob - otk/rect.hh
925456a196711acf6d13b7197df73601cd7c4375
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 an XRectangle
30 inline explicit Rect(const XRectangle
& xrect
)
31 : _x1(xrect
.x
), _y1(xrect
.y
), _x2(xrect
.width
+ xrect
.x
- 1),
32 _y2(xrect
.height
+ xrect
.y
- 1) { }
34 //! Returns the left coordinate of the Rect. Identical to Rect::x.
35 inline int left(void) const { return _x1
; }
36 //! Returns the top coordinate of the Rect. Identical to Rect::y.
37 inline int top(void) const { return _y1
; }
38 //! Returns the right coordinate of the Rect
39 inline int right(void) const { return _x2
; }
40 //! Returns the bottom coordinate of the Rect
41 inline int bottom(void) const { return _y2
; }
43 //! The x component of the point defining the top left corner of the Rect
44 inline int x(void) const { return _x1
; }
45 //! The y component of the point defining the top left corner of the Rect
46 inline int y(void) const { return _y1
; }
47 //! Sets the x coordinate of the Rect.
49 @param x The new x component of the point defining the top left corner of
53 //! Sets the y coordinate of the Rect.
55 @param y The new y component of the point defining the top left corner of
59 //! Sets the x and y coordinates of the Rect.
61 @param x The new x component of the point defining the top left corner of
63 @param y The new y component of the point defining the top left corner of
66 void setPos(int x
, int y
);
68 //! The width of the Rect
69 inline unsigned int width(void) const { return _x2
- _x1
+ 1; }
70 //! The height of the Rect
71 inline unsigned int height(void) const { return _y2
- _y1
+ 1; }
72 //! Sets the width of the Rect
74 @param w The new width of the rectangle
76 void setWidth(unsigned int w
);
77 //! Sets the height of the Rect
79 @param h The new height of the rectangle
81 void setHeight(unsigned int h
);
82 //! Sets the width of the Rect.
84 @param w The new width of the rectangle
85 @param h The new height of the rectangle
87 void setSize(unsigned int w
, unsigned int h
);
89 //! Sets the position and size of the Rect
91 @param x The new x component of the point defining the top left corner of
93 @param y The new y component of the point defining the top left corner of
95 @param w The new width of the rectangle
96 @param h The new height of the rectangle
98 void setRect(int x
, int y
, unsigned int w
, unsigned int h
);
100 //! Sets the position of all 4 sides of the Rect
102 @param l The new left coordinate of the rectangle
103 @param t The new top coordinate of the rectangle
104 @param r The new right coordinate of the rectangle
105 @param b The new bottom coordinate of the rectangle
107 void setCoords(int l
, int t
, int r
, int b
);
109 //! Determines if two Rect objects are equal
111 The rectangles are considered equal if they are in the same position and
114 inline bool operator==(const Rect
&a
)
115 { return _x1
== a
._x1
&& _y1
== a
._y1
&& _x2
== a
._x2
&& _y2
== a
._y2
; }
116 //! Determines if two Rect objects are inequal
120 inline bool operator!=(const Rect
&a
) { return ! operator==(a
); }
122 //! Returns the union of two Rect objects
124 The union of the rectangles will consist of the maximimum area that the two
125 rectangles can make up.
126 @param a A second Rect object to form a union with.
128 Rect
operator|(const Rect
&a
) const;
129 //! Returns the intersection of two Rect objects
131 The intersection of the rectangles will consist of just the area where the
132 two rectangles overlap.
133 @param a A second Rect object to form an intersection with.
134 @return The intersection between this Rect and the one passed to the
137 Rect
operator&(const Rect
&a
) const;
138 //! Sets the Rect to the union of itself with another Rect object
140 The union of the rectangles will consist of the maximimum area that the two
141 rectangles can make up.
142 @param a A second Rect object to form a union with.
143 @return The union between this Rect and the one passed to the function
145 inline Rect
&operator|=(const Rect
&a
) { *this = *this | a
; return *this; }
146 //! Sets the Rect to the intersection of itself with another Rect object
148 The intersection of the rectangles will consist of just the area where the
149 two rectangles overlap.
150 @param a A second Rect object to form an intersection with.
152 inline Rect
&operator&=(const Rect
&a
) { *this = *this & a
; return *this; }
154 //! Returns if the Rect is valid
156 A rectangle is valid only if its right and bottom coordinates are larger
157 than its left and top coordinates (i.e. it does not have a negative width
159 @return true if the Rect is valid; otherwise, false
161 inline bool valid(void) const { return _x2
> _x1
&& _y2
> _y1
; }
163 //! Determines if this Rect intersects another Rect
165 The rectangles intersect if any part of them overlaps.
166 @param a Another Rect object to compare this Rect with
167 @return true if the Rect objects overlap; otherwise, false
169 bool intersects(const Rect
&a
) const;
170 //! Determines if this Rect contains a point
172 The rectangle contains the point if it falls within the rectangle's
174 @param x The x coordinate of the point to operate on
175 @param y The y coordinate of the point to operate on
176 @return true if the point is contained within this Rect; otherwise, false
178 bool contains(int x
, int y
) const;
179 //! Determines if this Rect contains another Rect entirely
181 This rectangle contains the second rectangle if it is entirely within this
182 rectangle's boundaries.
183 @param a The Rect to test for containment inside of this Rect
184 @return true if the second Rect is contained within this Rect; otherwise,
187 bool contains(const Rect
&a
) const;
190 //! The left coordinate of the Rect
192 //! The top coordinate of the Rect
194 //! The right coordinate of the Rect
196 //! The bottom coordinate of the Rect
200 //! A list for Rect objects
201 typedef std::vector
<Rect
> RectList
;
This page took 0.042082 seconds and 4 git commands to generate.