Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added irregular polygon testing #74

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed contains line method
  • Loading branch information
gamecoder-nz committed May 13, 2024
commit fa5b2225a746ba47494f0236e7ea5b4a3780ec95
19 changes: 19 additions & 0 deletions olcUTIL_Geometry2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,25 @@ namespace olc::utils::geom2d
template<typename T1, typename T2>
inline constexpr bool contains(const polygon<T1>& p, const line<T2>& l)
{
line<T1> l2;

for (size_t i = 0; i < p.pos.size(); i++)
{
if (i == p.pos.size() - 1)
{
l2 = { p.pos[i], p.pos[0] };
}
else
{
l2 = { p.pos[i], p.pos[i + 1] };
}

if (overlaps(l, l2) == true)
{
return false;
}
}

return contains(p, l.start) && contains(p, l.end);
}

Expand Down