Merge pull request #58 from MartyMaro/master

Ensure triangulated vertices are not collinear
This commit is contained in:
Matthias Richter 2018-04-08 14:01:27 +02:00 committed by GitHub
commit 58490756e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -320,10 +320,12 @@ function Polygon:triangulate()
next, prev = next_idx[current], prev_idx[current]
local p,q,r = vertices[prev], vertices[current], vertices[next]
if isEar(p,q,r, concave) then
if not areCollinear(p, q, r) then
triangles[#triangles+1] = newPolygon(p.x,p.y, q.x,q.y, r.x,r.y)
next_idx[prev], prev_idx[next] = next, prev
concave[q] = nil
n_vert, skipped = n_vert - 1, 0
end
else
skipped = skipped + 1
assert(skipped <= n_vert, "Cannot triangulate polygon")