refactior(zones): make makeTriangles available outside of getTriangles

This commit is contained in:
DokaDoka
2022-05-11 13:28:53 +10:00
parent 9c7d9c44b7
commit 9b5ac35ab3

View File

@@ -1,6 +1,17 @@
local glm = require 'glm'
Zones = {}
local function makeTriangles(t)
local t1, t2
if t[3] and t[4] then
t1 = mat(t[1], t[2], t[3])
t2 = mat(t[2], t[3], t[4])
else
t1 = mat(t[1], t[2], t[3] or t[4])
end
return t1, t2
end
local function getTriangles(polygon)
local extremes = { polygon.projectToAxis(polygon, vec(1, 0, 0)) }
@@ -81,21 +92,6 @@ local function getTriangles(polygon)
return a.x < b.x
end
local function makeTriangles(t)
if t[3] and t[4] then
triangles[#triangles + 1] = mat(t[1], t[2], t[3])
triangles[#triangles + 1] = mat(t[2], t[3], t[4])
for i = 1, #t do
points[t[i]].uses += 1
end
else
triangles[#triangles + 1] = mat(t[1], t[2], t[3] or t[4])
for k, v in pairs(t) do
points[v].uses += 2
end
end
end
for i = 1, #sides do
local side = sides[i]
@@ -189,7 +185,18 @@ local function getTriangles(polygon)
end
if c or d then
makeTriangles({a, b, c, d})
local t = {a, b, c, d}
nTriangles = #triangles
triangles[nTriangles + 1], triangles[nTriangles + 2] = makeTriangles(t)
if c and d then
for i = 1, #t do
points[t[i]].uses += 1
end
else
for k, v in pairs(t) do
points[v].uses += 2
end
end
end
end
else