X-Git-Url: https://melusine.eu.org/syracuse/G/git/?p=delaunay.git;a=blobdiff_plain;f=luamesh.lua;h=060d3893789e5d5c0c1f1021306a794a5d6f1c68;hp=b977e4ebe8b985f42264b1ffaf9c2b91904328a6;hb=791c961e11f1d1114a9c8ba169d1422a8bcb4a94;hpb=d865bd5b172801559649eabbef29fd8f3898ce70 diff --git a/luamesh.lua b/luamesh.lua index b977e4e..060d389 100644 --- a/luamesh.lua +++ b/luamesh.lua @@ -340,25 +340,43 @@ function buildRect(largeur,a,b,nbrA, nbrB) traceTikZ(listPoints, triangulation,largeur,"none") end +local function shallowCopy(original) + local copy = {} + for key, value in pairs(original) do + copy[key] = value + end + return copy +end -- function give a real polygon without repeting points function cleanPoly(polygon) polyNew = {} - e1 = polygon[1][1] - e2 = polygon[1][2] + polyCopy = shallowCopy(polygon) + e1 = polyCopy[1][1] + e2 = polyCopy[1][2] table.insert(polyNew, e1) table.insert(polyNew, e2) + table.remove(polyCopy,1) j = 2 - for i=2,#polygon do - bool1 = (polygon[i][1] == polyNew[j]) - bool2 = (polygon[i][2] == polyNew[j]) - if(bool1 or bool2) then -- the edge has a common point with polyNew[j] - if(not bool1) then - table.insert(polyNew, polygon[i][1]) - j = j+1 - elseif(not bool2) then - table.insert(polyNew, polygon[i][2]) - j = j+1 + while #polyCopy>1 do + i=1 + find = false + while (i<=#polyCopy and find==false) do + i = i+1 + bool1 = (polyCopy[i][1] == polyNew[j]) + bool2 = (polyCopy[i][2] == polyNew[j]) + if(bool1 or bool2) then -- the edge has a common point with polyNew[j] + if(not bool1) then + table.insert(polyNew, polyCopy[i][1]) + find = true + table.remove(polyCopy,i) + j = j+1 + elseif(not bool2) then + table.insert(polyNew, polyCopy[i][2]) + find = true + table.remove(polyCopy,i) + j = j+1 + end end end end @@ -468,7 +486,6 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi end function TeXaddOnePointMPBW(listPoints,P,step,bbox) - print(bbox) output = ""; output = output .. "pair MeshPoints[];" -- build the triangulation