Skip to content
Open
Changes from all commits
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
10 changes: 10 additions & 0 deletions LilyPath/Triangulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public void Triangulate (IList<Vector2> points, int offset, int count)

int index = 0;
int computeIndex = 0;

int unsuccesfulLoops = 0;
while (count >= 3) {
bool isEar = true;

Expand Down Expand Up @@ -75,9 +77,17 @@ public void Triangulate (IList<Vector2> points, int offset, int count)
_triPrev[_triNext[index]] = _triPrev[index];
count--;
index = _triPrev[index];
unsuccesfulLoops = 0;
}
else {
index = _triNext[index];
unsuccesfulLoops++;
}

// give up if no ears have been found two times in a row.
// prevents an infinite loop.
if (unsuccesfulLoops > 1) {
break;
}
}

Expand Down