Fonction \buildMeshBWinc
[delaunay.git] / luamesh.lua
index 9b761e2..b977e4e 100644 (file)
@@ -6,9 +6,9 @@ function BowyerWatson (listPoints,bbox)
    -- add four points to listPoints to have a bounding box
    listPoints = buildBoundingBox(listPoints)
    -- the first triangle
-   triangulation[1] = {lgth+1, lgth+2, lgth+3}
+   triangulation[1] = {lgth+1, lgth+2, lgth+3,type="bbox"}
    -- the second triangle
-   triangulation[2] = {lgth+1, lgth+3, lgth+4}
+   triangulation[2] = {lgth+1, lgth+3, lgth+4,type="bbox"}
    -- add points one by one
    for i=1,lgth do
       -- find the triangles which the circumcircle contained the point to add
@@ -21,7 +21,11 @@ function BowyerWatson (listPoints,bbox)
       end
       -- build the new triangles and add them to triangulation
       for j=1,#polygon do
-         table.insert(triangulation,{polygon[j][1],polygon[j][2],i})
+         if((polygon[j][1]>lgth) or (polygon[j][2]>lgth) or (i>lgth)) then
+            table.insert(triangulation,{polygon[j][1],polygon[j][2],i,type="bbox"})
+         else
+            table.insert(triangulation,{polygon[j][1],polygon[j][2],i,type="in"})
+         end
       end
    end -- end adding points of the listPoints
    -- remove bounding box
@@ -64,10 +68,10 @@ function buildBoundingBox(listPoints)
    ymin = ymin - eps
    ymax = ymax + eps
    -- add points of the bounding box in last positions
-   table.insert(listPoints,{x=xmin,y=ymin})
-   table.insert(listPoints,{x=xmin,y=ymax})
-   table.insert(listPoints,{x=xmax,y=ymax})
-   table.insert(listPoints,{x=xmax,y=ymin})
+   table.insert(listPoints,{x=xmin,y=ymin,type="bbox"})
+   table.insert(listPoints,{x=xmin,y=ymax,type="bbox"})
+   table.insert(listPoints,{x=xmax,y=ymax,type="bbox"})
+   table.insert(listPoints,{x=xmax,y=ymin,type="bbox"})
    return listPoints
 end
 
@@ -267,7 +271,7 @@ end
 
 
 -- trace a triangulation with MP
-function traceMeshMP(listPoints, triangulation,points,color)
+function traceMeshMP(listPoints, triangulation,points)
    output = "";
    output = output .. " pair MeshPoints[];"
    for i=1,#listPoints do
@@ -278,11 +282,19 @@ function traceMeshMP(listPoints, triangulation,points,color)
       PointI = listPoints[triangulation[i][1]]
       PointJ = listPoints[triangulation[i][2]]
       PointK = listPoints[triangulation[i][3]]
-      output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\mpcolor{"..color.. "};"
+      if(triangulation[i].type == "bbox") then
+         output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
+      else
+         output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
+      end
    end
    if(points=="points") then
       for i=1,#listPoints do
-         output = output .. "dotlabel.llft( btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u) withcolor \\mpcolor{"..color.. "};"
+         if(listPoints[i].type == "bbox") then
+            output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
+         else
+            output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
+         end
       end
    end
    return output
@@ -303,15 +315,21 @@ end
 
 
 -- buildMesh with MP
-function buildMeshMP(chaine,mode,points,bbox,full,scale,color)
+function buildMeshMPBW(chaine,mode,points,bbox,scale)
    listPoints = buildList(chaine, mode)
    triangulation = BowyerWatson(listPoints,bbox)
-   output = traceMeshMP(listPoints, triangulation,points,color)
-   if(full=="full") then
-      output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
-   else
-      output = "u:="..scale.. ";".. output
-   end
+   output = traceMeshMP(listPoints, triangulation,points)
+   output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
+   tex.sprint(output)
+end
+
+
+-- buildMesh with MP include code
+function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
+   listPoints = buildList(chaine, mode)
+   triangulation = BowyerWatson(listPoints,bbox)
+   output = traceMeshMP(listPoints, triangulation,points)
+   output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
    tex.sprint(output)
 end
 
@@ -449,11 +467,12 @@ function TeXaddOnePointTikZ(chaine,point,step,color,colorBack, colorNew, colorCi
    return output
 end
 
-function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCircle)
+function TeXaddOnePointMPBW(listPoints,P,step,bbox)
+   print(bbox)
    output = "";
    output = output .. "pair MeshPoints[];"
    -- build the triangulation
-   triangulation = BowyerWatson(listPoints,"none")
+   triangulation = BowyerWatson(listPoints,bbox)
    badTriangles = buildBadTriangles(P,triangulation)
    for i=1,#listPoints do
       output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
@@ -464,15 +483,19 @@ function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCirc
          PointI = listPoints[triangulation[i][1]]
          PointJ = listPoints[triangulation[i][2]]
          PointK = listPoints[triangulation[i][3]]
-         output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\mpcolor{" .. color .."};"
+         if(triangulation[i].type == "bbox") then
+            output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
+         else
+            output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
+         end
       end
       -- draw and fill the bad triangle
       for i=1,#badTriangles do
          PointI = listPoints[triangulation[badTriangles[i]][1]]
          PointJ = listPoints[triangulation[badTriangles[i]][2]]
          PointK = listPoints[triangulation[badTriangles[i]][3]]
-         output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\mpcolor{" .. color .."};"
-         output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\mpcolor{" .. colorBack .."};"
+         output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
+         output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
       end
       -- draw the circoncircle
       for i=1,#badTriangles do
@@ -480,14 +503,18 @@ function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCirc
          PointJ = listPoints[triangulation[badTriangles[i]][2]]
          PointK = listPoints[triangulation[badTriangles[i]][3]]
          center, radius = circoncircle(PointI, PointJ, PointK)
-         output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\mpcolor{" .. colorCircle .."};"
+         output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
       end
       -- mark the points
       for i=1,#listPoints do
-         output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\mpcolor{" .. color .."};"
+         if(listPoints[i].type == "bbox") then
+            output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
+         else
+            output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
+         end
       end
       -- mark the point to add
-      output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\mpcolor{" .. colorNew .."};"
+      output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
    elseif(step == "cavity") then
       polygon = buildCavity(badTriangles, triangulation)
       polyNew = cleanPoly(polygon)
@@ -500,7 +527,11 @@ function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCirc
          PointI = listPoints[triangulation[i][1]]
          PointJ = listPoints[triangulation[i][2]]
          PointK = listPoints[triangulation[i][3]]
-         output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\mpcolor{" .. color .."};"
+         if(triangulation[i].type == "bbox") then
+            output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
+         else
+            output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
+         end
       end
       -- fill and draw the cavity
       path = ""
@@ -508,14 +539,18 @@ function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCirc
          PointI = listPoints[polyNew[i]]
          path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
       end
-      output = output .. "fill " .. path .. "cycle withcolor \\mpcolor{" .. colorBack .."};"
-      output = output .. "draw " .. path .. "cycle withcolor \\mpcolor{" .. colorNew .."} withpen pencircle scaled 1pt;"
+      output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
+      output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew  withpen pencircle scaled 1pt;"
       -- mark the points of the mesh
       for i=1,#listPoints do
-         output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\mpcolor{" .. color .."};"
+         if(listPoints[i].type == "bbox") then
+            output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
+         else
+            output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
+         end
       end
       -- mark the adding point
-      output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\mpcolor{" .. colorNew .."};"
+      output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
    elseif(step == "newT") then
       polygon = buildCavity(badTriangles, triangulation)
       polyNew = cleanPoly(polygon)
@@ -528,7 +563,11 @@ function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCirc
          PointI = listPoints[triangulation[i][1]]
          PointJ = listPoints[triangulation[i][2]]
          PointK = listPoints[triangulation[i][3]]
-         output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\mpcolor{" .. color .."};"
+         if(triangulation[i].type == "bbox") then
+            output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
+         else
+            output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
+         end
       end
       -- fill  the cavity
       path = ""
@@ -536,19 +575,23 @@ function TeXaddOnePointMP(listPoints,P,step,color,colorBack, colorNew, colorCirc
          PointI = listPoints[polyNew[i]]
          path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
       end
-      output = output .. "fill " .. path .. "cycle withcolor \\mpcolor{" .. colorBack .."};"
+      output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
       -- draw the new triangles composed by the edges of the polygon and the added point
       for i=1,#polygon do
-         output = output .. "draw".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ")*u -- (" .. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y ..")*u withcolor \\mpcolor{" .. colorNew .."} withpen pencircle scaled 1pt;"
-         output = output .. "draw".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ")*u -- (" .. P.x .. "," .. P.y ..")*u withcolor \\mpcolor{" .. colorNew .."} withpen pencircle scaled 1pt;"
-         output = output .. "draw".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ")*u -- (" .. P.x .. "," .. P.y ..")*u withcolor \\mpcolor{" .. colorNew .."} withpen pencircle scaled 1pt;"
+         output = output .. "draw".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ")*u -- (" .. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y ..")*u withcolor \\luameshmpcolorNew  withpen pencircle scaled 1pt;"
+         output = output .. "draw".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ")*u -- (" .. P.x .. "," .. P.y ..")*u withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
+         output = output .. "draw".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ")*u -- (" .. P.x .. "," .. P.y ..")*u withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
       end
       -- mark points
       for i=1,#listPoints do
-         output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\mpcolor{" .. color .."};"
+         if(listPoints[i].type == "bbox") then
+            output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
+         else
+            output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
+         end
       end
       -- mark the added point
-      output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\mpcolor{ " .. colorNew .."};"
+      output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
    end
    return output
 end
@@ -576,7 +619,7 @@ function TeXOnePointTikZ(chaine,point,step,color,colorBack,colorNew,colorCircle,
    tex.sprint(output)
 end
 
-function TeXOnePointMP(chaine,point,step,color,colorBack,colorNew,colorCircle,scale,mode,picture)
+function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
    if(mode=="int") then
       Sx,Sy=string.match(point,"%((.+),(.+)%)")
       P = {x=Sx, y=Sy}
@@ -585,11 +628,21 @@ function TeXOnePointMP(chaine,point,step,color,colorBack,colorNew,colorCircle,sc
       -- point is a number
       P, listPoints = buildListExt(chaine,tonumber(point))
    end
-   output = TeXaddOnePointMP(listPoints,P,step,color,colorBack,colorNew,colorCircle)
-   if(picture=="full") then
-      output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
+   output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
+   output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
+   tex.sprint(output)
+end
+
+function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
+   if(mode=="int") then
+      Sx,Sy=string.match(point,"%((.+),(.+)%)")
+      P = {x=Sx, y=Sy}
+      listPoints = buildList(chaine, mode)
    else
-      output = "u:="..scale..";".. output
+      -- point is a number
+      P, listPoints = buildListExt(chaine,tonumber(point))
    end
+   output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
+   output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
    tex.sprint(output)
 end

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.