Fix Rect::FromCenter and add test for it

This commit is contained in:
Dmitry Marakasov 2014-02-11 06:01:36 +04:00
parent 07bf0aa3d5
commit f6d6572602
2 changed files with 8 additions and 1 deletions

View File

@ -93,7 +93,7 @@ const SDL_Rect* Rect::Get() const {
} }
Rect Rect::FromCenter(int cx, int cy, int w, int h) { Rect Rect::FromCenter(int cx, int cy, int w, int h) {
return Rect(cx - w/2, cy - h/2, cx + w - w/2, cy + h - h/2); return Rect(cx - w/2, cy - h/2, w, h);
} }
bool Rect::IsNull() const { bool Rect::IsNull() const {

View File

@ -119,4 +119,11 @@ BEGIN_TEST()
EXPECT_TRUE(r.GetW() == 16 && r.GetH() == 31); EXPECT_TRUE(r.GetW() == 16 && r.GetH() == 31);
} }
{
Rect r = Rect::FromCenter(100, 100, 5, 7);
EXPECT_TRUE(r.GetX() == 98 && r.GetY() == 97);
EXPECT_TRUE(r.GetX2() == 102 && r.GetY2() == 103);
}
END_TEST() END_TEST()