From f6d6572602cb4bace10643ade1af13deac5a3110 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Tue, 11 Feb 2014 06:01:36 +0400 Subject: [PATCH] Fix Rect::FromCenter and add test for it --- SDL2pp/Rect.cc | 2 +- tests/test_pointrect.cc | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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()