diff --git a/SDL2pp/Rect.cc b/SDL2pp/Rect.cc index c5a3f41..c14fc26 100644 --- a/SDL2pp/Rect.cc +++ b/SDL2pp/Rect.cc @@ -93,7 +93,7 @@ const SDL_Rect* Rect::Get() const { } 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 { diff --git a/tests/test_pointrect.cc b/tests/test_pointrect.cc index 7553069..a5378d2 100644 --- a/tests/test_pointrect.cc +++ b/tests/test_pointrect.cc @@ -119,4 +119,11 @@ BEGIN_TEST() 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()