Make setters return reference to self: Point and Rect

This commit is contained in:
Dmitry Marakasov 2015-01-19 00:47:25 +03:00
parent 739629354b
commit 40e8f71efa
4 changed files with 39 additions and 16 deletions

View File

@ -50,16 +50,18 @@ int Point::GetX() const {
return x;
}
void Point::SetX(int nx) {
Point& Point::SetX(int nx) {
x = nx;
return *this;
}
int Point::GetY() const {
return y;
}
void Point::SetY(int ny) {
Point& Point::SetY(int ny) {
y = ny;
return *this;
}
Point Point::operator+(const Point& other) const {

View File

@ -129,8 +129,10 @@ public:
///
/// \param[in] nx New X coordinate value
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
void SetX(int nx);
Point& SetX(int nx);
////////////////////////////////////////////////////////////
/// \brief Get Y coordinate of the point
@ -145,8 +147,10 @@ public:
///
/// \param[in] ny New Y coordinate value
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
void SetY(int ny);
Point& SetY(int ny);
////////////////////////////////////////////////////////////
/// \brief Get point's memberwise addition with another point

View File

@ -84,31 +84,34 @@ int Rect::GetX() const {
return x;
}
void Rect::SetX(int nx) {
Rect& Rect::SetX(int nx) {
x = nx;
return *this;
}
int Rect::GetY() const {
return y;
}
void Rect::SetY(int ny) {
Rect& Rect::SetY(int ny) {
y = ny;
return *this;
}
int Rect::GetW() const {
return w;
}
void Rect::SetW(int nw) {
Rect& Rect::SetW(int nw) {
w = nw;
return *this;
}
int Rect::GetH() const {
return h;
}
void Rect::SetH(int nh) {
Rect& Rect::SetH(int nh) {
h = nh;
}
@ -116,16 +119,18 @@ int Rect::GetX2() const {
return x + w - 1;
}
void Rect::SetX2(int x2) {
Rect& Rect::SetX2(int x2) {
w = x2 - x + 1;
return *this;
}
int Rect::GetY2() const {
return y + h - 1;
}
void Rect::SetY2(int y2) {
Rect& Rect::SetY2(int y2) {
h = y2 - y + 1;
return *this;
}
bool Rect::Contains(int px, int py) const {

View File

@ -186,8 +186,10 @@ public:
///
/// \param[in] nx New X coordinate value
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
void SetX(int nx);
Rect& SetX(int nx);
////////////////////////////////////////////////////////////
/// \brief Get Y coordinate of the rect corner
@ -202,8 +204,10 @@ public:
///
/// \param[in] ny New Y coordinate value
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
void SetY(int ny);
Rect& SetY(int ny);
////////////////////////////////////////////////////////////
/// \brief Get width of the rect
@ -218,8 +222,10 @@ public:
///
/// \param[in] nw New width of the rect
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
void SetW(int nw);
Rect& SetW(int nw);
////////////////////////////////////////////////////////////
/// \brief Get height of the rect
@ -234,8 +240,10 @@ public:
///
/// \param[in] nh New height of the rect
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
void SetH(int nh);
Rect& SetH(int nh);
////////////////////////////////////////////////////////////
/// \brief Get X coordinate of the rect second corner
@ -250,8 +258,10 @@ public:
///
/// \param[in] x2 New X coordinate value
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
void SetX2(int x2);
Rect& SetX2(int x2);
////////////////////////////////////////////////////////////
/// \brief Get Y coordinate of the rect second corner
@ -270,8 +280,10 @@ public:
///
/// This modifies rectangle height internally
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
void SetY2(int y2);
Rect& SetY2(int y2);
////////////////////////////////////////////////////////////
/// \brief Check whether the rect contains given point