LibGfx: Implement even-odd method for Quad::contains() and add tests
First PR :)
LibGfx: Addressed simple FIXME comment to improve implementation of LibGfx::Quad::contains():
- Now uses even-odd method to determine if point is inside/outside
- Added
TestQuad.cppfor basic verification of current functions
Docs: Added homebrew package shellcheck to build instructions documentation because I needed that to build on macOS
This has inconsistent behavior at edges (not like code you're replacing had it but), i. e. the following test passes:
TEST_CASE(foo)
{
Gfx::Point<int> p1 { 0, 0 };
Gfx::Point<int> p2 { 2, 0 };
Gfx::Point<int> p3 { 2, 2 };
Gfx::Point<int> p4 { 0, 2 };
Gfx::Quad<int> quad { p1, p2, p3, p4 };
EXPECT(quad.contains({ 0, 0 }));
EXPECT(quad.contains({ 1, 0 }));
EXPECT(quad.contains({ 0, 1 }));
EXPECT(!quad.contains({ 2, 0 }));
EXPECT(!quad.contains({ 2, 1 }));
EXPECT(!quad.contains({ 2, 2 }));
EXPECT(!quad.contains({ 1, 2 }));
EXPECT(!quad.contains({ 0, 2 }));
}
@DanShaders I appreciate your review, ty.
Turns out this behavior is consistent with LibGfx::Rect, i.e. the following test case also passes:
TEST_CASE(foo)
{
Gfx::Point<int> p1 { 0, 0 };
Gfx::Point<int> p2 { 2, 0 };
Gfx::Point<int> p3 { 2, 2 };
Gfx::Point<int> p4 { 0, 2 };
Gfx::Quad<int> quad { p1, p2, p3, p4 };
EXPECT(quad.contains({ 0, 0 }));
EXPECT(quad.contains({ 1, 0 }));
EXPECT(quad.contains({ 0, 1 }));
EXPECT(!quad.contains({ 2, 0 }));
EXPECT(!quad.contains({ 2, 1 }));
EXPECT(!quad.contains({ 2, 2 }));
EXPECT(!quad.contains({ 1, 2 }));
EXPECT(!quad.contains({ 0, 2 }));
Gfx::Rect<int> bounding_rect = quad.bounding_rect();
EXPECT(bounding_rect.contains({ 0, 0 }));
EXPECT(bounding_rect.contains({ 1, 0 }));
EXPECT(bounding_rect.contains({ 0, 1 }));
EXPECT(!bounding_rect.contains({ 2, 0 }));
EXPECT(!bounding_rect.contains({ 2, 1 }));
EXPECT(!bounding_rect.contains({ 2, 2 }));
EXPECT(!bounding_rect.contains({ 1, 2 }));
EXPECT(!bounding_rect.contains({ 0, 2 }));
}
Looks like LibGfx::Rect::contains() treats points at x() and y() inclusively and x() + width() and y() + height() exclusively.
Just added new test case to verify Quad and Rect contains() implementations are consistent.
Hello!
One or more of the commit messages in this PR do not match the Ladybird code submission policy, please check the lint_commits CI job for more details on which commits were flagged and why.
Please do not close this PR and open another, instead modify your commit message(s) with git commit --amend and force push those changes to update this PR.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!
This pull request has been closed because it has not had recent activity. Feel free to re-open if you wish to still contribute these changes. Thank you for your contributions!