mirror of
https://github.com/vrld/HC.git
synced 2024-11-18 12:54:23 +00:00
Prevents trying to create sub-polygons (triangles) with less than 3 non-collinear points when triangulating a polygon
fixes #55
This commit is contained in:
parent
dca0947077
commit
bde26eca15
10
polygon.lua
10
polygon.lua
@ -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
|
||||
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
|
||||
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")
|
||||
|
Loading…
Reference in New Issue
Block a user