20 TBPoint(
int x_,
int y_) : x(x_), y(y_) {}
29 TBRect() : x(0), y(0), w(0), h(0) {}
30 TBRect(
int x_,
int y_,
int w_,
int h_) : x(x_), y(y_), w(w_), h(h_) {}
32 inline bool IsEmpty()
const {
return w <= 0 || h <= 0; }
33 inline bool IsInsideOut()
const {
return w < 0 || h < 0; }
34 inline bool Equals(
const TBRect &rect)
const {
return rect.x == x && rect.y == y && rect.w == w && rect.h == h; }
35 bool Intersects(
const TBRect &rect)
const;
36 bool Contains(
const TBPoint &p)
const {
return p.x >= x && p.y >= y && p.x < x + w && p.y < y + h; }
38 inline void Reset() { x = y = w = h = 0; }
39 inline void Set(
int x_,
int y_,
int w_,
int h_) { this->x = x_; this->y = y_; this->w = w_; this->h = h_; }
41 inline TBRect Shrink(
int left,
int top,
int right,
int bottom)
const {
return TBRect(x + left, y + top, w - left - right, h - top - bottom); }
42 inline TBRect Expand(
int left,
int top,
int right,
int bottom)
const {
return Shrink(-left, -top, -right, -bottom); }
43 inline TBRect Shrink(
int tx,
int ty)
const {
return TBRect(x + tx, y + ty, w - tx * 2, h - ty * 2); }
44 inline TBRect Expand(
int tx,
int ty)
const {
return Shrink(-tx, -ty); }
45 inline TBRect Offset(
int dx,
int dy)
const {
return TBRect(x + dx, y + dy, w, h); }
101 bool IsEmpty()
const {
return m_num_rects == 0; }
102 int GetNumRects()
const {
return m_num_rects; }
103 const TBRect &GetRect(
int index)
const;
113 #endif // TB_GEOMETRY_H
TBRect RightCenterIn(const TBRect &bounding_rect) const
Return a rect vertically centered on the right side in bounding_rect.
Definition: tb_geometry.cpp:35
void RemoveRect(int index)
Remove the rect at the given index.
Definition: tb_geometry.cpp:86
Simple point class.
Definition: tb_geometry.h:15
TBRegion does calculations on regions represented by a list of rectangles.
Definition: tb_geometry.h:63
bool IncludeRect(const TBRect &include_rect)
Include the rect in the region.
Definition: tb_geometry.cpp:166
bool ExcludeRect(const TBRect &exclude_rect)
Exclude the rect from the region.
Definition: tb_geometry.cpp:190
void RemoveRectFast(int index)
Remove the rect at the given index.
Definition: tb_geometry.cpp:94
bool AddExcludingRects(const TBRect &rect, const TBRect &exclude_rect, bool coalesce)
Add the rectangles that's left of rect after excluding exclude_rect.
Definition: tb_geometry.cpp:213
Simple rectangle class.
Definition: tb_geometry.h:25
TBRect CenterIn(const TBRect &bounding_rect) const
Return a rect centered in bounding_rect.
Definition: tb_geometry.cpp:30
bool AddRect(const TBRect &rect, bool coalesce)
Add the rect without doing any overlap check.
Definition: tb_geometry.cpp:134
TBRect MoveIn(const TBRect &bounding_rect) const
Return a rect moved inside bounding_rect.
Definition: tb_geometry.cpp:23
bool Set(const TBRect &rect)
Set the region to the given rect.
Definition: tb_geometry.cpp:111
void RemoveAll(bool free_memory=true)
Remove all rectangles so the region becomes empty.
Definition: tb_geometry.cpp:100