end
end
if(points=="points") then
+ j=1
for i=1,#listPoints do
if(listPoints[i].type == "bbox") then
- output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
+ 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
+-- print points of the mesh
+function tracePointsMP(listPoints,points)
+ output = "";
+ output = output .. " pair MeshPoints[];"
+ for i=1,#listPoints do
+ output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
+ 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
+ else
+ for i=1,#listPoints do
+ if(listPoints[i].type == "bbox") then
+ output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
+ else
+ output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
+ end
+ end
+ end
+ return output
+end
+
+
-- buildMesh with TikZ
function buildMeshTikZ(chaine,mode,points,bbox,full,scale,color)
tex.sprint(output)
end
+-- print points to mesh
+function printPointsMP(chaine,mode,points,bbox,scale)
+ listPoints = buildList(chaine, mode)
+ if(bbox == "bbox" ) then
+ listPoints = buildBoundingBox(listPoints)
+ end
+ output = tracePointsMP(listPoints,points)
+ output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
+ tex.sprint(output)
+end
+
+
+-- print points to mesh
+function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale)
+ listPoints = buildList(chaine, mode)
+ if(bbox == "bbox" ) then
+ listPoints = buildBoundingBox(listPoints)
+ end
+ output = tracePointsMP(listPoints,points)
+ output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\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
+
-- buildMesh
function buildRect(largeur,a,b,nbrA, nbrB)
listPoints = rectangleList(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
end
function TeXaddOnePointMPBW(listPoints,P,step,bbox)
- print(bbox)
output = "";
output = output .. "pair MeshPoints[];"
-- build the triangulation
output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
end
-- mark the points
+ j=1
for i=1,#listPoints do
if(listPoints[i].type == "bbox") then
- output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
+ 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
output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew withpen pencircle scaled 1pt;"
-- mark the points of the mesh
+ j=1
for i=1,#listPoints do
if(listPoints[i].type == "bbox") then
- output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
+ 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
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
+ j=1
for i=1,#listPoints do
if(listPoints[i].type == "bbox") then
- output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
+ 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