Skip to content

Commit 8187f17

Browse files
authored
Merge pull request #454 from scratchcpp/fix_default_bounding_rect
Fix #438: Fix default sprite bounding rectangle
2 parents e3b170b + 88c7ecc commit 8187f17

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/scratch/sprite.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ void Sprite::setLayerOrder(int newLayerOrder)
345345
Rect Sprite::boundingRect() const
346346
{
347347
if (!impl->iface)
348-
return Rect();
348+
return Rect(impl->x, impl->y, impl->x, impl->y);
349349

350350
return impl->iface->boundingRect();
351351
}

test/scratch_classes/sprite_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,18 @@ TEST(SpriteTest, KeepInFence)
590590
ASSERT_EQ(std::round(fencedY * 100) / 100, 150.9);
591591
}
592592

593+
TEST(SpriteTest, DefaultBoundingRect)
594+
{
595+
Sprite sprite;
596+
sprite.setX(65.5);
597+
sprite.setY(-45.01);
598+
Rect rect = sprite.boundingRect();
599+
ASSERT_EQ(rect.left(), 65.5);
600+
ASSERT_EQ(rect.top(), -45.01);
601+
ASSERT_EQ(rect.right(), 65.5);
602+
ASSERT_EQ(rect.bottom(), -45.01);
603+
}
604+
593605
TEST(SpriteTest, GraphicsEffects)
594606
{
595607
Sprite sprite;

0 commit comments

Comments
 (0)