Add Point and Rect setters

While here, fix Rect::GetX2 and Rect::GetY2 off-by-one errors
This commit is contained in:
Dmitry Marakasov 2014-02-11 04:33:24 +04:00
parent 14819ba188
commit 802322ef1b
4 changed files with 56 additions and 2 deletions

View File

@ -76,9 +76,19 @@ int Point::GetX() const {
return point_->x;
}
void Point::SetX(int x) {
assert(!IsNull());
point_->x = x;
}
int Point::GetY() const {
assert(!IsNull());
return point_->y;
}
void Point::SetY(int y) {
assert(!IsNull());
point_->y = y;
}
}

View File

@ -62,7 +62,10 @@ public:
bool IsNull() const;
int GetX() const;
void SetX(int x);
int GetY() const;
void SetY(int y);
};
}

View File

@ -86,29 +86,59 @@ int Rect::GetX() const {
return rect_->x;
}
void Rect::SetX(int x) {
assert(!IsNull());
rect_->x = x;
}
int Rect::GetY() const {
assert(!IsNull());
return rect_->y;
}
void Rect::SetY(int y) {
assert(!IsNull());
rect_->y = y;
}
int Rect::GetW() const {
assert(!IsNull());
return rect_->w;
}
void Rect::SetW(int w) {
assert(!IsNull());
rect_->w = w;
}
int Rect::GetH() const {
assert(!IsNull());
return rect_->h;
}
void Rect::SetH(int h) {
assert(!IsNull());
rect_->h = h;
}
int Rect::GetX2() const {
assert(!IsNull());
return rect_->x + rect_->w;
return rect_->x + rect_->w - 1;
}
void Rect::SetX2(int x2) {
assert(!IsNull());
rect_->w = x2 - rect_->x + 1;
}
int Rect::GetY2() const {
assert(!IsNull());
return rect_->y + rect_->h;
return rect_->y + rect_->h - 1;
}
void Rect::SetY2(int y2) {
assert(!IsNull());
rect_->h = y2 - rect_->y + 1;
}
}

View File

@ -54,11 +54,22 @@ public:
bool IsNull() const;
int GetX() const;
void SetX(int x);
int GetY() const;
void SetY(int y);
int GetW() const;
void SetW(int w);
int GetH() const;
void SetH(int h);
int GetX2() const;
void SetX2(int x2);
int GetY2() const;
void SetY2(int y2);
};
}