Voronoi en TikZ
[delaunay.git] / luamesh.lua
1 -- Bowyer and Watson algorithm
2 -- Delaunay meshing
3 function BowyerWatson (listPoints,bbox)
4    local triangulation = {}
5    local lgth = #listPoints
6    -- add four points to listPoints to have a bounding box
7    listPoints = buildBoundingBox(listPoints)
8    -- the first triangle
9    triangulation[1] = {lgth+1, lgth+2, lgth+3,type="bbox"}
10    -- the second triangle
11    triangulation[2] = {lgth+1, lgth+3, lgth+4,type="bbox"}
12    -- add points one by one
13    for i=1,lgth do
14       -- find the triangles which the circumcircle contained the point to add
15       badTriangles = buildBadTriangles(listPoints[i],triangulation)
16       -- build the polygon of the cavity containing the point to add
17       polygon = buildCavity(badTriangles, triangulation)
18       -- remove the bad triangles
19       for j=1,#badTriangles do
20          table.remove(triangulation,badTriangles[j]-(j-1))
21       end
22       -- build the new triangles and add them to triangulation
23       for j=1,#polygon do
24          if((polygon[j][1]>lgth) or (polygon[j][2]>lgth) or (i>lgth)) then
25             table.insert(triangulation,{polygon[j][1],polygon[j][2],i,type="bbox"})
26          else
27             table.insert(triangulation,{polygon[j][1],polygon[j][2],i,type="in"})
28          end
29       end
30    end  -- end adding points of the listPoints
31    -- remove bounding box
32    if(bbox ~= "bbox") then
33       triangulation = removeBoundingBox(triangulation,lgth)
34       table.remove(listPoints,lgth+1)
35       table.remove(listPoints,lgth+1)
36       table.remove(listPoints,lgth+1)
37       table.remove(listPoints,lgth+1)
38    end
39    return triangulation
40 end
41
42
43 function buildBoundingBox(listPoints)
44    -- listPoints : list of points
45    -- epsV        : parameter for the distance of the bounding box
46    local xmin, xmax, ymin, ymax, eps
47    xmin = 1000
48    ymin = 1000
49    xmax = -1000
50    ymax = -1000
51    for i=1,#listPoints do
52       if (listPoints[i].x < xmin) then
53          xmin = listPoints[i].x
54       end
55       if (listPoints[i].x > xmax) then
56          xmax = listPoints[i].x
57       end
58       if (listPoints[i].y < ymin) then
59          ymin = listPoints[i].y
60       end
61       if (listPoints[i].y > ymax) then
62          ymax = listPoints[i].y
63       end
64    end
65    eps = math.max(math.abs(xmax-xmin),math.abs(ymax-ymin))*0.15
66    xmin = xmin - eps
67    xmax = xmax + eps
68    ymin = ymin - eps
69    ymax = ymax + eps
70    -- add points of the bounding box in last positions
71    table.insert(listPoints,{x=xmin,y=ymin,type="bbox"})
72    table.insert(listPoints,{x=xmin,y=ymax,type="bbox"})
73    table.insert(listPoints,{x=xmax,y=ymax,type="bbox"})
74    table.insert(listPoints,{x=xmax,y=ymin,type="bbox"})
75    return listPoints
76 end
77
78 function removeBoundingBox(triangulation,lgth)
79    -- build the four bounding box edge
80    point1 = lgth+1
81    point2 = lgth+2
82    point3 = lgth+3
83    point4 = lgth+4
84    -- for all triangle
85    newTriangulation = {}
86    for i=1,#triangulation do
87       boolE1 = pointInTriangle(point1,triangulation[i])
88       boolE2 = pointInTriangle(point2,triangulation[i])
89       boolE3 = pointInTriangle(point3,triangulation[i])
90       boolE4 = pointInTriangle(point4,triangulation[i])
91       if((not boolE1) and (not boolE2) and (not boolE3) and (not boolE4)) then
92          table.insert(newTriangulation,triangulation[i])
93       end
94    end
95    return newTriangulation
96 end
97
98
99 function buildBadTriangles(point, triangulation)
100    badTriangles = {}
101    for j=1,#triangulation do -- for all triangles
102       A = listPoints[triangulation[j][1]]
103       B = listPoints[triangulation[j][2]]
104       C = listPoints[triangulation[j][3]]
105       center, radius = circoncircle(A,B,C)
106       CP = Vector(center,point)
107       if(VectorNorm(CP)<radius) then -- the point belongs to the circoncirle
108          table.insert(badTriangles,j)
109       end
110    end
111    return badTriangles
112 end
113
114 -- construction of the cavity composed by the bad triangles around the point to add
115 function buildCavity(badTriangles, triangulation)
116    polygon = {}
117    for j=1,#badTriangles do -- for all bad triangles
118       ind = badTriangles[j]
119       for k=1,3 do -- for all edges
120          edge = {triangulation[ind][k],triangulation[ind][k%3+1]}
121          edgeBord = false
122          for l = 1,#badTriangles do -- for all badtriangles
123             badInd = badTriangles[l]
124             if(badInd ~= ind) then -- if not the current one
125                edgeBord = edgeBord or edgeInTriangle(edge,triangulation[badInd])
126             end
127          end --
128          -- if the edge does not belong to another bad triangle
129          if(edgeBord == false) then
130             -- insert the edge to the cavity
131             table.insert(polygon,edge)
132          end
133       end --
134    end --
135    return polygon
136 end
137
138 function edgeInTriangle(e,t)
139    in1 = false
140    in2 = false
141    for i=1,3 do
142       if e[1] == t[i] then
143          in1 = true
144       end
145       if e[2] == t[i] then
146          in2 = true
147       end
148    end
149    out = (in1 and in2)
150    return out
151 end
152
153 function pointInTriangle(e,t)
154    in1 = false
155    for i=1,3 do
156       if e == t[i] then
157          in1 = true
158       end
159    end
160    return in1
161 end
162
163
164 function Vector(A,B)
165    local out = {x = B.x - A.x, y = B.y - A.y}
166    return out
167 end
168
169 function VectorNorm(NP)
170    return math.sqrt(NP.x*NP.x +NP.y*NP.y)
171 end
172
173 -- circoncircle
174 function circoncircle(M, N, P)
175    -- Compute center and radius of the circoncircle of the triangle M N P
176
177    -- return : (center [Point],radius [float])
178
179    local MN = Vector(M,N)
180    local NP = Vector(N,P)
181    local PM = Vector(P,M)
182    m = VectorNorm(NP)  -- |NP|
183    n = VectorNorm(PM)  -- |PM|
184    p = VectorNorm(MN)  -- |MN|
185
186    d = (m + n + p) * (-m + n + p) * (m - n + p) * (m + n - p)
187    if d > 0 then
188       rad = m * n * p / math.sqrt(d)
189    else
190       rad = 0
191    end
192    d = -2 * (M.x * NP.y + N.x * PM.y + P.x * MN.y)
193    O = {x=0, y=0}
194    OM = Vector(O, M)
195    ON = Vector(O, N)
196    OP = Vector(O, P)
197    om2 = math.pow(VectorNorm(OM),2)  -- |OM|**2
198    on2 = math.pow(VectorNorm(ON),2)  -- |ON|**2
199    op2 = math.pow(VectorNorm(OP),2)  -- |OP|**2
200    x0 = -(om2 * NP.y + on2 * PM.y + op2 * MN.y) / d
201    y0 = (om2 * NP.x + on2 * PM.x + op2 * MN.x) / d
202    if d == 0 then
203       Out = {nil, nil}
204    else
205       Out = {x=x0, y=y0}
206    end
207    return Out, rad  -- (center [Point], R [float])
208 end
209
210 -- compute the list of the circumcircle of a triangulation
211 function listCircumCenter(listPoints,triangulation)
212    list = {}
213    for j=1,#triangulation do
214       A = listPoints[triangulation[j][1]]
215       B = listPoints[triangulation[j][2]]
216       C = listPoints[triangulation[j][3]]
217       center, radius = circoncircle(A,B,C)
218       table.insert(list,{x=center.x,y=center.y,r=radius})
219    end
220    return list
221 end
222
223 -- find the three neighbour triangles of T
224 function findNeighbour(T,i,triangulation)
225    -- T : triangle
226    -- i : index of T in triangualation
227    -- triangulation
228
229    list = {}
230    -- define the three edge
231    e1 = {T[1],T[2]}
232    e2 = {T[2],T[3]}
233    e3 = {T[3],T[1]}
234    for j=1,#triangulation do
235       if j~= i then
236          if(edgeInTriangle(e1,triangulation[j])) then
237             table.insert(list,j)
238          end
239          if(edgeInTriangle(e2,triangulation[j])) then
240             table.insert(list,j)
241          end
242          if(edgeInTriangle(e3,triangulation[j])) then
243             table.insert(list,j)
244          end
245       end
246    end
247    return list
248 end
249
250 -- test if edge are the same (reverse)
251 function equalEdge(e1,e2)
252    if(((e1[1] == e2[1]) and (e1[2] == e2[2])) or ((e1[1] == e2[2]) and (e1[2] == e2[1]))) then
253       return true
254    else
255       return false
256    end
257 end
258
259 -- test if the edge belongs to the list
260 function edgeInList(e,listE)
261    output = false
262    for i=1,#listE do
263       if(equalEdge(e,listE[i])) then
264          output = true
265       end
266    end
267    return output
268 end
269
270 -- build the edges of the Voronoi diagram with a given triangulation
271 function buildVoronoi(listPoints, triangulation)
272    listCircumCircle = listCircumCenter(listPoints, triangulation)
273    listVoronoi = {}
274    for i=1,#listCircumCircle do
275       listN = findNeighbour(triangulation[i],i,triangulation)
276       for j=1,#listN do
277          edge = {i,listN[j]}
278          if( not edgeInList(edge, listVoronoi)) then
279             table.insert(listVoronoi, edge)
280          end
281       end
282    end
283    return listVoronoi
284 end
285
286 -------------------------- TeX
287 -- build the list of points
288 function buildList(chaine, mode)
289    -- if mode = int : the list is given in the chaine string (x1,y1);(x2,y2);...;(xn,yn)
290    -- if mode = ext : the list is given in a file line by line with space separation
291    listPoints = {}
292    if mode == "int" then
293       local points = string.explode(chaine, ";")
294       local lgth=#points
295       for i=1,lgth do
296          Sx,Sy=string.match(points[i],"%((.+),(.+)%)")
297          listPoints[i]={x=tonumber(Sx),y=tonumber(Sy)}
298       end
299    elseif mode == "ext" then
300       io.input(chaine) -- open the file
301       text=io.read("*all")
302       lines=string.explode(text,"\n+") -- all the lines
303       tablePoints={}
304       for i=1,#lines do
305          xy=string.explode(lines[i]," +")
306          listPoints[i]={x=tonumber(xy[1]),y=tonumber(xy[2])}
307       end
308    else
309       print("Non existing mode")
310    end
311    return listPoints
312 end
313
314
315 --
316 function rectangleList(a,b,nbrA,nbrB)
317    stepA = a/nbrA
318    stepB = b/nbrB
319    listPoints = {}
320    k=1
321    for i=1,(nbrA+1) do
322       for j=1,(nbrB+1) do
323          listPoints[k] = {x = (i-1)*stepA, y=(j-1)*stepB}
324          k=k+1
325       end
326    end
327    return listPoints
328 end
329
330
331 -- trace Voronoi with MP
332 function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri)
333    listCircumC = listCircumCenter(listPoints,triangulation)
334    output = "";
335    output = output .. " pair MeshPoints[];"
336    for i=1,#listPoints do
337       output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
338    end
339    output = output .. " pair CircumCenters[];"
340    for i=1,#listCircumC do
341       output = output .. "CircumCenters[".. i .. "] = (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ")*u;"
342    end
343    if(tri=="show") then
344       for i=1,#triangulation do
345          PointI = listPoints[triangulation[i][1]]
346          PointJ = listPoints[triangulation[i][2]]
347          PointK = listPoints[triangulation[i][3]]
348          if(triangulation[i].type == "bbox") then
349             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
350          else
351             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
352          end
353       end
354    end
355    for i=1,#listVoronoi do
356       PointI = listCircumC[listVoronoi[i][1]]
357       PointJ = listCircumC[listVoronoi[i][2]]
358       output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u withcolor \\luameshmpcolorVoronoi;"
359    end
360    if(points=="points") then
361       j=1
362       for i=1,#listPoints do
363          if(listPoints[i].type == "bbox") then
364             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
365             j=j+1
366          else
367             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
368          end
369       end
370       for i=1,#listCircumC do
371          output = output .. "dotlabel.llft (btex $\\CircumPoint_{" .. i .. "}$ etex, (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u ) withcolor \\luameshmpcolorVoronoi ;"
372       end
373    else
374       j=1
375       for i=1,#listPoints do
376          if(listPoints[i].type == "bbox") then
377             output = output .. "drawdot  (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
378             j=j+1
379          else
380             output = output .. "drawdot  (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolor withpen pencircle scaled 3;"
381          end
382       end
383       for i=1,#listCircumC do
384          output = output .. "drawdot  (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ")*u  withcolor \\luameshmpcolorVoronoi withpen pencircle scaled 3;"
385       end
386    end
387
388    return output
389 end
390
391
392 -- trace Voronoi with TikZ
393 function traceVoronoiTikZ(listPoints, triangulation,listVoronoi, points, tri,color,colorBbox,colorVoronoi)
394    listCircumC = listCircumCenter(listPoints,triangulation)
395     output = ""
396    for i=1,#listPoints do
397       output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
398    end
399    for i=1,#listCircumC do
400       output = output .. "\\coordinate (CircumPoints".. i .. ") at  (" .. listCircumC[i].x .. "," .. listCircumC[i].y .. ");"
401    end
402    if(tri=="show") then
403       for i=1,#triangulation do
404          PointI = listPoints[triangulation[i][1]]
405          PointJ = listPoints[triangulation[i][2]]
406          PointK = listPoints[triangulation[i][3]]
407          if(triangulation[i].type == "bbox") then
408             output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
409          else
410             output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
411          end
412       end
413    end
414    for i=1,#listVoronoi do
415       PointI = listCircumC[listVoronoi[i][1]]
416       PointJ = listCircumC[listVoronoi[i][2]]
417       output = output .. "\\draw[color="..colorVoronoi.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..");"
418    end
419    if(points=="points") then
420       j=1
421       for i=1,#listPoints do
422          if(listPoints[i].type == "bbox") then
423             if(listPoints[i].type == "bbox") then
424                output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
425                j=j+1
426             else
427                output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
428             end
429          end
430       end
431       for i=1,#listCircumC do
432          output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\CircumPoint_{" .. i .. "}$};"
433       end
434    else
435       j=1
436       for i=1,#listPoints do
437          if(listPoints[i].type == "bbox") then
438             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
439             j=j+1
440          else
441             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
442          end
443       end
444       for i=1,#listCircumC do
445          output = output .. "\\draw[color="..colorVoronoi.."] (" .. listCircumC[i].x ..",".. listCircumC[i].y .. ") node {$\\bullet$};"
446       end
447    end
448    return output
449 end
450
451
452
453 -- buildVoronoi with MP
454 function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri)
455    listPoints = buildList(chaine, mode)
456    triangulation = BowyerWatson(listPoints,bbox)
457    listVoronoi = buildVoronoi(listPoints, triangulation)
458    output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri)
459    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
460    tex.sprint(output)
461 end
462
463
464 -- buildVoronoi with TikZ
465 function buildVoronoiTikZBW(chaine,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi)
466    listPoints = buildList(chaine, mode)
467    triangulation = BowyerWatson(listPoints,bbox)
468    listVoronoi = buildVoronoi(listPoints, triangulation)
469    output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi)
470    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"   tex.sprint(output)
471 end
472
473
474
475 -- trace a triangulation with TikZ
476 function traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
477    output = ""
478    for i=1,#listPoints do
479       output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
480    end
481    for i=1,#triangulation do
482       PointI = listPoints[triangulation[i][1]]
483       PointJ = listPoints[triangulation[i][2]]
484       PointK = listPoints[triangulation[i][3]]
485       if(triangulation[i].type == "bbox") then
486          output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
487       else
488          output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
489       end
490    end
491    if(points=="points") then
492       j=1
493       for i=1,#listPoints do
494          if(listPoints[i].type == "bbox") then
495             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
496             j=j+1
497          else
498             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
499          end
500       end
501    end
502    return output
503 end
504
505
506 -- trace a triangulation with MP
507 function traceMeshMP(listPoints, triangulation,points)
508    output = "";
509    output = output .. " pair MeshPoints[];"
510    for i=1,#listPoints do
511       output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
512    end
513
514    for i=1,#triangulation do
515       PointI = listPoints[triangulation[i][1]]
516       PointJ = listPoints[triangulation[i][2]]
517       PointK = listPoints[triangulation[i][3]]
518       if(triangulation[i].type == "bbox") then
519          output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
520       else
521          output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
522       end
523    end
524    if(points=="points") then
525       j=1
526       for i=1,#listPoints do
527          if(listPoints[i].type == "bbox") then
528             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{"..j.."}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
529             j=j+1
530          else
531             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
532          end
533       end
534    end
535    return output
536 end
537
538
539 -- buildMesh with MP
540 function buildMeshMPBW(chaine,mode,points,bbox,scale)
541    listPoints = buildList(chaine, mode)
542    triangulation = BowyerWatson(listPoints,bbox)
543    output = traceMeshMP(listPoints, triangulation,points)
544    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
545    tex.sprint(output)
546 end
547
548 -- buildMesh with MP include code
549 function buildMeshMPBWinc(chaine,beginning, ending,mode,points,bbox,scale)
550    listPoints = buildList(chaine, mode)
551    triangulation = BowyerWatson(listPoints,bbox)
552    output = traceMeshMP(listPoints, triangulation,points)
553    output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
554    tex.sprint(output)
555 end
556
557 -- buildMesh with TikZ
558 function buildMeshTikZBW(chaine,mode,points,bbox,scale,color,colorBbox)
559    listPoints = buildList(chaine, mode)
560    triangulation = BowyerWatson(listPoints,bbox)
561    output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
562    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
563    tex.sprint(output)
564 end
565
566 -- buildMesh with TikZ
567 function buildMeshTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,color,colorBbox)
568    listPoints = buildList(chaine, mode)
569    triangulation = BowyerWatson(listPoints,bbox)
570    output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox)
571    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
572    tex.sprint(output)
573 end
574
575
576 -- print points of the mesh
577 function tracePointsMP(listPoints,points)
578    output = "";
579    output = output .. " pair MeshPoints[];"
580    for i=1,#listPoints do
581       output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
582    end
583    if(points=="points") then
584       j=1
585       for i=1,#listPoints do
586          if(listPoints[i].type == "bbox") then
587             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
588             j=j+1
589          else
590             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
591          end
592       end
593    else
594       for i=1,#listPoints do
595          if(listPoints[i].type == "bbox") then
596             output = output .. "drawdot  (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolorBbox withpen pencircle scaled 3;"
597          else
598             output = output .. "drawdot (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u  withcolor \\luameshmpcolor withpen pencircle scaled 3;"
599          end
600       end
601    end
602    return output
603 end
604
605 -- print points of the mesh
606 function tracePointsTikZ(listPoints,points,color,colorBbox)
607    output = "";
608    for i=1,#listPoints do
609       output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
610    end
611    if(points=="points") then
612       j=1
613       for i=1,#listPoints do
614          if(listPoints[i].type == "bbox") then
615             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
616             j = j+1
617          else
618             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
619          end
620       end
621    else
622       for i=1,#listPoints do
623          if(listPoints[i].type == "bbox") then
624             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
625          else
626             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} ;"
627          end
628       end
629    end
630    return output
631 end
632
633 -- print points to mesh
634 function printPointsMP(chaine,mode,points,bbox,scale)
635    listPoints = buildList(chaine, mode)
636    if(bbox == "bbox" ) then
637       listPoints = buildBoundingBox(listPoints)
638    end
639    output = tracePointsMP(listPoints,points)
640    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}"
641    tex.sprint(output)
642 end
643
644
645 -- print points to mesh
646 function printPointsMPinc(chaine,beginning, ending, mode,points,bbox,scale)
647    listPoints = buildList(chaine, mode)
648    if(bbox == "bbox" ) then
649       listPoints = buildBoundingBox(listPoints)
650    end
651    output = tracePointsMP(listPoints,points)
652    output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
653    tex.sprint(output)
654 end
655
656 -- print points to mesh
657 function printPointsTikZ(chaine,mode,points,bbox,scale,color,colorBbox)
658    listPoints = buildList(chaine, mode)
659    if(bbox == "bbox" ) then
660       listPoints = buildBoundingBox(listPoints)
661    end
662    output = tracePointsTikZ(listPoints,points,color,colorBbox)
663    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}"
664    tex.sprint(output)
665 end
666
667
668 -- print points to mesh
669 function printPointsTikZinc(chaine,beginning, ending, mode,points,bbox,scale,color,colorBbox)
670    listPoints = buildList(chaine, mode)
671    if(bbox == "bbox" ) then
672       listPoints = buildBoundingBox(listPoints)
673    end
674    output = tracePointsTikZ(listPoints,points,color,colorBbox)
675    output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}"
676    tex.sprint(output)
677 end
678
679
680 -- buildMesh
681 function buildRect(largeur,a,b,nbrA, nbrB)
682    listPoints = rectangleList(a,b,nbrA,nbrB)
683    triangulation = BowyerWatson(listPoints,"none")
684    traceTikZ(listPoints, triangulation,largeur,"none")
685 end
686
687 local function shallowCopy(original)
688    local copy = {}
689    for key, value in pairs(original) do
690       copy[key] = value
691    end
692    return copy
693 end
694
695 -- function give a real polygon without repeting points
696 function cleanPoly(polygon)
697    polyNew = {}
698    polyCopy = shallowCopy(polygon)
699    e1 = polyCopy[1][1]
700    e2 = polyCopy[1][2]
701    table.insert(polyNew, e1)
702    table.insert(polyNew, e2)
703    table.remove(polyCopy,1)
704    j = 2
705    while #polyCopy>1 do
706       i=1
707       find = false
708       while (i<=#polyCopy and find==false) do
709          bool1 = (polyCopy[i][1] == polyNew[j])
710          bool2 = (polyCopy[i][2] == polyNew[j])
711          if(bool1 or bool2) then -- the edge has a common point with polyNew[j]
712             if(not bool1) then
713                table.insert(polyNew, polyCopy[i][1])
714                find = true
715                table.remove(polyCopy,i)
716                j = j+1
717             elseif(not bool2) then
718                table.insert(polyNew, polyCopy[i][2])
719                find = true
720                table.remove(polyCopy,i)
721                j = j+1
722             end
723          end
724          i=i+1
725       end
726    end
727    return polyNew
728 end
729
730 --
731 function TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack, colorNew, colorCircle,colorBbox)
732    output = ""
733    -- build the triangulation
734    triangulation = BowyerWatson(listPoints,bbox)
735    badTriangles = buildBadTriangles(P,triangulation)
736    for i=1,#listPoints do
737       output = output .. "\\coordinate (MeshPoints".. i .. ") at  (" .. listPoints[i].x .. "," .. listPoints[i].y .. ");"
738    end
739    if(step == "badT") then
740       -- draw all triangle
741       for i=1,#triangulation do
742          PointI = listPoints[triangulation[i][1]]
743          PointJ = listPoints[triangulation[i][2]]
744          PointK = listPoints[triangulation[i][3]]
745          if(triangulation[i].type == "bbox") then
746             output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
747          else
748             output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
749          end
750       end
751       -- draw and fill the bad triangle
752       for i=1,#badTriangles do
753          PointI = listPoints[triangulation[badTriangles[i]][1]]
754          PointJ = listPoints[triangulation[badTriangles[i]][2]]
755          PointK = listPoints[triangulation[badTriangles[i]][3]]
756          output = output .. "\\draw[fill="..colorBack.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
757       end
758       -- draw the circoncircle
759       for i=1,#badTriangles do
760          PointI = listPoints[triangulation[badTriangles[i]][1]]
761          PointJ = listPoints[triangulation[badTriangles[i]][2]]
762          PointK = listPoints[triangulation[badTriangles[i]][3]]
763          center, radius = circoncircle(PointI, PointJ, PointK)
764          output = output .. "\\draw[dashed, color="..colorCircle.."] ("..center.x .. "," .. center.y .. ") circle ("..radius ..");"
765       end
766       -- mark the points
767       j=1
768       for i=1,#listPoints do
769          if(listPoints[i].type == "bbox") then
770             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
771             j = j+1
772          else
773             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
774          end
775       end
776       -- mark the point to add
777       output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
778    elseif(step == "cavity") then
779       polygon = buildCavity(badTriangles, triangulation)
780       polyNew = cleanPoly(polygon)
781       -- remove the bad triangles
782       for j=1,#badTriangles do
783          table.remove(triangulation,badTriangles[j]-(j-1))
784       end
785       -- draw the triangles
786       for i=1,#triangulation do
787          PointI = listPoints[triangulation[i][1]]
788          PointJ = listPoints[triangulation[i][2]]
789          PointK = listPoints[triangulation[i][3]]
790          if(triangulation[i].type == "bbox") then
791             output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
792          else
793             output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
794          end
795       end
796       -- fill and draw the cavity
797       path = ""
798       for i=1,#polyNew do
799          PointI = listPoints[polyNew[i]]
800          path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
801       end
802       output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
803       -- mark the points of the mesh
804       j=1
805       for i=1,#listPoints do
806          if(listPoints[i].type == "bbox") then
807             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
808             j=j+1
809          else
810             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
811          end
812       end
813       -- mark the adding point
814       output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
815    elseif(step == "newT") then
816       polygon = buildCavity(badTriangles, triangulation)
817       polyNew = cleanPoly(polygon)
818       -- remove the bad triangles
819       for j=1,#badTriangles do
820          table.remove(triangulation,badTriangles[j]-(j-1))
821       end
822       -- draw the triangle of the triangulation
823       for i=1,#triangulation do
824          PointI = listPoints[triangulation[i][1]]
825          PointJ = listPoints[triangulation[i][2]]
826          PointK = listPoints[triangulation[i][3]]
827          if(triangulation[i].type == "bbox") then
828             output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
829          else
830             output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;"
831          end
832       end
833       -- fill and draw the cavity
834       path = ""
835       for i=1,#polyNew do
836          PointI = listPoints[polyNew[i]]
837          path = path .. "(".. PointI.x ..",".. PointI.y ..")--"
838       end
839       output = output .. "\\draw[color="..colorNew..",fill ="..colorBack..", thick] " .. path .. "cycle;"
840       -- draw the new triangles composed by the edges of the polygon and the added point
841       for i=1,#polygon do
842          output = output .. "\\draw[color=TeXCluaMeshNewTikZ, thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y ..");"
843          output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][1]].x .. "," .. listPoints[polygon[i][1]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
844          output = output .. "\\draw[color="..colorNew..", thick]".."(".. listPoints[polygon[i][2]].x .. "," .. listPoints[polygon[i][2]].y .. ") -- (" .. P.x .. "," .. P.y ..");"
845       end
846       -- mark points
847       j=1
848       for i=1,#listPoints do
849          if(listPoints[i].type == "bbox") then
850             output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};"
851             j=j+1
852          else
853             output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};"
854          end
855       end
856       -- mark the added point
857       output = output .. "\\draw[color="..colorNew.."] (" .. P.x ..",".. P.y .. ") node {$\\bullet$} node[anchor=north east] {$\\NewPoint$};"
858    end
859    return output
860 end
861
862 function TeXaddOnePointMPBW(listPoints,P,step,bbox)
863    output = "";
864    output = output .. "pair MeshPoints[];"
865    -- build the triangulation
866    triangulation = BowyerWatson(listPoints,bbox)
867    badTriangles = buildBadTriangles(P,triangulation)
868    for i=1,#listPoints do
869       output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;"
870    end
871    if(step == "badT") then
872       -- draw all triangle
873       for i=1,#triangulation do
874          PointI = listPoints[triangulation[i][1]]
875          PointJ = listPoints[triangulation[i][2]]
876          PointK = listPoints[triangulation[i][3]]
877          if(triangulation[i].type == "bbox") then
878             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
879          else
880             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
881          end
882       end
883       -- draw and fill the bad triangle
884       for i=1,#badTriangles do
885          PointI = listPoints[triangulation[badTriangles[i]][1]]
886          PointJ = listPoints[triangulation[badTriangles[i]][2]]
887          PointK = listPoints[triangulation[badTriangles[i]][3]]
888          output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
889          output = output .. "fill (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBack;"
890       end
891       -- draw the circoncircle
892       for i=1,#badTriangles do
893          PointI = listPoints[triangulation[badTriangles[i]][1]]
894          PointJ = listPoints[triangulation[badTriangles[i]][2]]
895          PointK = listPoints[triangulation[badTriangles[i]][3]]
896          center, radius = circoncircle(PointI, PointJ, PointK)
897          output = output .. "draw fullcircle scaled ("..radius .."*2u) shifted ("..center.x .. "*u," .. center.y .. "*u) dashed evenly withcolor \\luameshmpcolorCircle;"
898       end
899       -- mark the points
900       j=1
901       for i=1,#listPoints do
902          if(listPoints[i].type == "bbox") then
903             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
904             j=j+1
905          else
906             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
907          end
908       end
909       -- mark the point to add
910       output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew;"
911    elseif(step == "cavity") then
912       polygon = buildCavity(badTriangles, triangulation)
913       polyNew = cleanPoly(polygon)
914       -- remove the bad triangles
915       for j=1,#badTriangles do
916          table.remove(triangulation,badTriangles[j]-(j-1))
917       end
918       -- draw the triangles
919       for i=1,#triangulation do
920          PointI = listPoints[triangulation[i][1]]
921          PointJ = listPoints[triangulation[i][2]]
922          PointK = listPoints[triangulation[i][3]]
923          if(triangulation[i].type == "bbox") then
924             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
925          else
926             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
927          end
928       end
929       -- fill and draw the cavity
930       path = ""
931       for i=1,#polyNew do
932          PointI = listPoints[polyNew[i]]
933          path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
934       end
935       output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
936       output = output .. "draw " .. path .. "cycle withcolor \\luameshmpcolorNew  withpen pencircle scaled 1pt;"
937       -- mark the points of the mesh
938       j=1
939       for i=1,#listPoints do
940          if(listPoints[i].type == "bbox") then
941             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
942             j=j+1
943          else
944             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
945          end
946       end
947       -- mark the adding point
948       output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
949    elseif(step == "newT") then
950       polygon = buildCavity(badTriangles, triangulation)
951       polyNew = cleanPoly(polygon)
952       -- remove the bad triangles
953       for j=1,#badTriangles do
954          table.remove(triangulation,badTriangles[j]-(j-1))
955       end
956       -- draw the triangle of the triangulation
957       for i=1,#triangulation do
958          PointI = listPoints[triangulation[i][1]]
959          PointJ = listPoints[triangulation[i][2]]
960          PointK = listPoints[triangulation[i][3]]
961          if(triangulation[i].type == "bbox") then
962             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;"
963          else
964             output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;"
965          end
966       end
967       -- fill  the cavity
968       path = ""
969       for i=1,#polyNew do
970          PointI = listPoints[polyNew[i]]
971          path = path .. "(".. PointI.x ..",".. PointI.y ..")*u--"
972       end
973       output = output .. "fill " .. path .. "cycle withcolor \\luameshmpcolorBack;"
974       -- draw the new triangles composed by the edges of the polygon and the added point
975       for i=1,#polygon do
976          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;"
977          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;"
978          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;"
979       end
980       -- mark points
981       j=1
982       for i=1,#listPoints do
983          if(listPoints[i].type == "bbox") then
984             output = output .. "dotlabel.llft (btex $\\MeshPoint^{*}_{" .. j .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolorBbox ;"
985             j=j+1
986          else
987             output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
988          end
989       end
990       -- mark the added point
991       output = output .. "dotlabel.llft (btex $\\NewPoint$ etex,(" .. P.x ..",".. P.y .. ")*u) withcolor \\luameshmpcolorNew ;"
992    end
993    return output
994 end
995
996
997 -- build the list of points extern and stop at nbr
998 function buildListExt(chaine, stop)
999    listPoints = {}
1000    io.input(chaine) -- open the file
1001    text=io.read("*all")
1002    lines=string.explode(text,"\n+") -- all the lines
1003    for i=1,tonumber(stop) do
1004       xy=string.explode(lines[i]," +")
1005       table.insert(listPoints,{x=tonumber(xy[1]),y=tonumber(xy[2])})
1006    end
1007    xy=string.explode(lines[stop+1]," +")
1008    point={x=tonumber(xy[1]),y=tonumber(xy[2])}
1009    return point, listPoints
1010 end
1011
1012
1013 function TeXOnePointTikZBW(chaine,point,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1014    if(mode=="int") then
1015       Sx,Sy=string.match(point,"%((.+),(.+)%)")
1016       P = {x=Sx, y=Sy}
1017       listPoints = buildList(chaine, mode)
1018    else
1019       -- point is a number
1020       P, listPoints = buildListExt(chaine,tonumber(point))
1021    end
1022    output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1023    output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. output .. "\\end{tikzpicture}"
1024    tex.sprint(output)
1025 end
1026
1027 function TeXOnePointTikZBWinc(chaine,point,beginning, ending,step,scale,mode,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1028    if(mode=="int") then
1029       Sx,Sy=string.match(point,"%((.+),(.+)%)")
1030       P = {x=Sx, y=Sy}
1031       listPoints = buildList(chaine, mode)
1032    else
1033       -- point is a number
1034       P, listPoints = buildListExt(chaine,tonumber(point))
1035    end
1036    output = TeXaddOnePointTikZ(listPoints,P,step,bbox,color,colorBack,colorNew,colorCircle,colorBbox)
1037    output = "\\noindent\\begin{tikzpicture}[x="..scale..",y="..scale.."]".. beginning..output ..ending.. "\\end{tikzpicture}"
1038    tex.sprint(output)
1039 end
1040
1041 function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
1042    if(mode=="int") then
1043       Sx,Sy=string.match(point,"%((.+),(.+)%)")
1044       P = {x=Sx, y=Sy}
1045       listPoints = buildList(chaine, mode)
1046    else
1047       -- point is a number
1048       P, listPoints = buildListExt(chaine,tonumber(point))
1049    end
1050    output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
1051    output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale..";".. output .. "endfig;\\end{mplibcode}"
1052    tex.sprint(output)
1053 end
1054
1055 function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
1056    if(mode=="int") then
1057       Sx,Sy=string.match(point,"%((.+),(.+)%)")
1058       P = {x=Sx, y=Sy}
1059       listPoints = buildList(chaine, mode)
1060    else
1061       -- point is a number
1062       P, listPoints = buildListExt(chaine,tonumber(point))
1063    end
1064    output = TeXaddOnePointMPBW(listPoints,P,step,bbox)
1065    output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}"
1066    tex.sprint(output)
1067 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.