mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibGfx: Fix error & crash in Rect::closest_to
Assertion fails if the point is outside of the rect. This was introduced in introduced in #18970 and causes serenity to crash when changing to 2x resolution for a monitor, if the cursor after resizing is outside of the new screen. Added test to reproduce.
This commit is contained in:
parent
0cb9c9e81e
commit
d52a2ff10e
Notes:
sideshowbarker
2024-07-17 06:40:21 +09:00
Author: https://github.com/SebastianZaha Commit: https://github.com/SerenityOS/serenity/commit/d52a2ff10e Pull-request: https://github.com/SerenityOS/serenity/pull/19696 Reviewed-by: https://github.com/MacDue Reviewed-by: https://github.com/gmta ✅
|
@ -45,3 +45,14 @@ TEST_CASE(rect_shatter)
|
|||
|
||||
EXPECT_EQ(glass_plate.size().area() - hammer.size().area(), total_shard_area);
|
||||
}
|
||||
|
||||
TEST_CASE(rect_closest_to)
|
||||
{
|
||||
Gfx::IntRect const screen_rect = { 0, 0, 960, 540 };
|
||||
Gfx::Point<int> p = { 460, 592 }; // point is below the rect
|
||||
Gfx::Point<int> closest = screen_rect.closest_to(p);
|
||||
EXPECT_EQ(screen_rect.side(closest), Gfx::IntRect::Side::Bottom);
|
||||
p = { 960, 0 }; // point exactly on top right corner
|
||||
closest = screen_rect.closest_to(p);
|
||||
EXPECT_EQ(screen_rect.side(closest), Gfx::IntRect::Side::Top);
|
||||
}
|
||||
|
|
|
@ -656,8 +656,8 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
check_distance({ top_left(), top_right() });
|
||||
check_distance({ bottom_left(), bottom_right() });
|
||||
check_distance({ top_left(), top_right().moved_left(1) });
|
||||
check_distance({ bottom_left().moved_up(1), bottom_right().translated(-1) });
|
||||
if (height() > 2) {
|
||||
check_distance({ { x(), y() + 1 }, { x(), bottom() - 2 } });
|
||||
check_distance({ { right() - 1, y() + 1 }, { right() - 1, bottom() - 2 } });
|
||||
|
|
Loading…
Reference in a new issue