+
+-- trace Voronoi with MP
+function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri,styleD,styleV)
+ if(styleD == "dashed") then
+ sDelaunay = "dashed evenly"
+ else
+ sDelaunay = ""
+ end
+ if(styleV == "dashed") then
+ sVoronoi = "dashed evenly"
+ else
+ sVoronoi = ""
+ end
+ listCircumC = listCircumCenter(listPoints,triangulation)
+ output = "";
+ output = output .. " pair MeshPoints[];"
+ for i=1,#listPoints do
+ output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
+ end
+ output = output .. " pair CircumCenters[];"
+ for i=1,#listCircumC do
+ output = output .. "CircumCenters[".. i .. "] = (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ")*u;"
+ end
+ if(tri=="show") then
+ for i=1,#triangulation do
+ PointI = listPoints[triangulation[i][1]]
+ PointJ = listPoints[triangulation[i][2]]
+ PointK = listPoints[triangulation[i][3]]
+ 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 "..sDelaunay.." withcolor \\luameshmpcolorBbox;"
+ else
+ output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle "..sDelaunay.." withcolor \\luameshmpcolor;"
+ end
+ end
+ end
+ for i=1,#listVoronoi do
+ PointI = listCircumC[listVoronoi[i][1]]
+ PointJ = listCircumC[listVoronoi[i][2]]
+ output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u "..sVoronoi.." withcolor \\luameshmpcolorVoronoi;"
+ end
+ if(points=="points") then
+ j=1
+ for i=1,#listPoints do
+ if(listPoints[i].type == "bbox") then
+ output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
+ j=j+1
+ else
+ output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
+ end
+ end
+ for i=1,#listCircumC do
+ output = output .. "dotlabel.llft (btex $\\CircumPoint_{" .. i .. "}$ etex, (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u ) withcolor \\luameshmpcolorVoronoi ;"
+ end
+ else
+ j=1
+ for i=1,#listPoints do
+ if(listPoints[i].type == "bbox") then
+ output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
+ j=j+1
+ else
+ output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u withcolor \\luameshmpcolor withpen pencircle scaled 3;"
+ end
+ end
+ for i=1,#listCircumC do
+ output = output .. "drawdot (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u withcolor \\luameshmpcolorVoronoi withpen pencircle scaled 3;"
+ end
+ end
+
+ return output
+end
+
+
+-- trace Voronoi with TikZ
+function traceVoronoiTikZ(listPoints, triangulation,listVoronoi, points, tri,color,colorBbox,colorVoronoi,styleD,styleV)
+ if(styleD == "dashed") then
+ sDelaunay = ",dashed"
+ else
+ sDelaunay = ""
+ end
+ if(styleV == "dashed") then
+ sVoronoi = ",dashed"
+ else
+ sVoronoi = ""
+ end
+ listCircumC = listCircumCenter(listPoints,triangulation)
+ output = ""
+ for i=1,#listPoints do
+ output = output .. "\\coordinate (MeshPoints".. i .. ") at (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
+ end
+ for i=1,#listCircumC do
+ output = output .. "\\coordinate (CircumPoints".. i .. ") at (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ");"
+ end
+ if(tri=="show") then
+ for i=1,#triangulation do
+ PointI = listPoints[triangulation[i][1]]
+ PointJ = listPoints[triangulation[i][2]]
+ PointK = listPoints[triangulation[i][3]]
+ if(triangulation[i].type == "bbox") then
+ output = output .. "\\draw[color="..colorBbox..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
+ else
+ output = output .. "\\draw[color="..color..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
+ end
+ end
+ end
+ for i=1,#listVoronoi do
+ PointI = listCircumC[listVoronoi[i][1]]
+ PointJ = listCircumC[listVoronoi[i][2]]
+ output = output .. "\\draw[color="..colorVoronoi..sVoronoi.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..");"
+ end
+ if(points=="points") then
+ j=1
+ for i=1,#listPoints do
+ if(listPoints[i].type == "bbox") then
+ output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
+ j=j+1
+ else
+ output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
+ end
+ end
+ for i=1,#listCircumC do
+ output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\CircumPoint_{" .. i .. "}$};"
+ end
+ else
+ j=1
+ for i=1,#listPoints do
+ if(listPoints[i].type == "bbox") then
+ output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
+ j=j+1
+ else
+ output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
+ end
+ end
+ for i=1,#listCircumC do
+ output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$};"
+ end
+ end
+ return output
+end
+
+
+
+-- buildVoronoi with MP
+function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri,styleD,styleV)
+ listPoints = buildList(chaine, mode)
+ triangulation = BowyerWatson(listPoints,bbox)
+ listVoronoi = buildVoronoi(listPoints, triangulation)
+ output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
+ output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
+ tex.sprint(output)
+end
+
+
+-- buildVoronoi with TikZ
+function buildVoronoiTikZBW(chaine,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi,styleD,styleV)
+ listPoints = buildList(chaine, mode)
+ triangulation = BowyerWatson(listPoints,bbox)
+ listVoronoi = buildVoronoi(listPoints, triangulation)
+ output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
+ output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output)
+end
+
+
+-- buildVoronoi with MP
+function buildVoronoiMPBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,styleD,styleV)
+ listPoints = buildList(chaine, mode)
+ triangulation = BowyerWatson(listPoints,bbox)
+ listVoronoi = buildVoronoi(listPoints, triangulation)
+ output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV)
+ output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
+ tex.sprint(output)
+end
+
+
+-- buildVoronoi with TikZ
+function buildVoronoiTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi)
+ listPoints = buildList(chaine, mode,styleD,styleV)
+ triangulation = BowyerWatson(listPoints,bbox)
+ listVoronoi = buildVoronoi(listPoints, triangulation)
+ output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV)
+ output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
+ tex.sprint(output)
+end
+
+
+