Tweak polygon ear clipping to behave well with duplicate vertices

This commit is contained in:
Nikita Lisitsa 2022-12-16 01:55:21 +03:00
parent 3f382651c4
commit 1198653891

View file

@ -47,6 +47,15 @@ namespace psemek::cg
result.edges[i + count].twin = i;
}
auto inside = [robust_tag](auto const & t, auto const & p)
{
return true
&& geom::orientation(robust_tag, t[0], t[1], p) == geom::sign_t::positive
&& geom::orientation(robust_tag, t[1], t[2], p) == geom::sign_t::positive
&& geom::orientation(robust_tag, t[2], t[0], p) == geom::sign_t::positive
;
};
auto edge = result.edge(0);
for (IndexType i = 0; i + 3 < count; ++i)
{
@ -64,7 +73,7 @@ namespace psemek::cg
for (auto k = nnext.next(); k != edge; k = k.next())
{
if (geom::contains(triangle, at(k.origin().index())))
if (inside(triangle, at(k.origin().index())))
{
ear = false;
break;