Bug dans cleanPoly() réparé
[delaunay.git] / luamesh.lua
index b977e4e..060d389 100644 (file)
@@ -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

Licence Creative Commons Les fichiers de Syracuse sont mis à disposition (sauf mention contraire) selon les termes de la
Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 4.0 International.