bbox color
authorMaxime Chupin (Ceremade) <chupin@ceremade.dauphine.fr>
Tue, 22 Nov 2016 15:55:34 +0000 (16:55 +0100)
committerMaxime Chupin (Ceremade) <chupin@ceremade.dauphine.fr>
Tue, 22 Nov 2016 15:55:34 +0000 (16:55 +0100)
luamesh.lua
luamesh.sty
test/delaunay.pdf
test/delaunay.tex

index 28e61db..de0c274 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,11 @@ end
 
 
 -- buildMesh with MP
-function buildMeshMPBW(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
 
@@ -450,6 +458,7 @@ 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
@@ -464,7 +473,11 @@ function TeXaddOnePointMPBW(listPoints,P,step,bbox)
          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 \\luameshmpcolor;"
+         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
@@ -484,7 +497,11 @@ function TeXaddOnePointMPBW(listPoints,P,step,bbox)
       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 \\luameshmpcolor;"
+         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 \\luameshmpcolorNew;"
@@ -500,7 +517,11 @@ function TeXaddOnePointMPBW(listPoints,P,step,bbox)
          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 \\luameshmpcolor;"
+         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 = ""
@@ -512,7 +533,11 @@ function TeXaddOnePointMPBW(listPoints,P,step,bbox)
       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 \\luameshmpcolor ;"
+         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 \\luameshmpcolorNew ;"
@@ -528,7 +553,11 @@ function TeXaddOnePointMPBW(listPoints,P,step,bbox)
          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 \\luameshmpcolor ;"
+         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 = ""
@@ -545,7 +574,11 @@ function TeXaddOnePointMPBW(listPoints,P,step,bbox)
       end
       -- mark points
       for i=1,#listPoints do
-         output = output .. "dotlabel.llft (btex $\\MeshPoint_{" .. i .. "}$ etex, (" .. listPoints[i].x ..",".. listPoints[i].y .. ")*u ) withcolor \\luameshmpcolor ;"
+         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 \\luameshmpcolorNew ;"
@@ -576,7 +609,7 @@ function TeXOnePointTikZ(chaine,point,step,color,colorBack,colorNew,colorCircle,
    tex.sprint(output)
 end
 
-function TeXOnePointMPBW(chaine,point,step,scale,mode,picture,bbox)
+function TeXOnePointMPBW(chaine,point,step,scale,mode,bbox)
    if(mode=="int") then
       Sx,Sy=string.match(point,"%((.+),(.+)%)")
       P = {x=Sx, y=Sy}
@@ -590,7 +623,7 @@ function TeXOnePointMPBW(chaine,point,step,scale,mode,picture,bbox)
    tex.sprint(output)
 end
 
-function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,picture,bbox)
+function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox)
    if(mode=="int") then
       Sx,Sy=string.match(point,"%((.+),(.+)%)")
       P = {x=Sx, y=Sy}
index 9d394d9..82e3214 100644 (file)
 %% show the bounding box for delaunay
 \define@choicekey*{buildMesh}{bbox}[\val\nr]{none, show}{%
   \ifcase\nr\relax%
-  \def\luameshval@bbox{none}%
+  \def\luameshval@bm@bbox{none}%
   \or%
-  \def\luameshval@bbox{bbox}%
+  \def\luameshval@bm@bbox{bbox}%
   \fi%
 }%
 %% the scale
-\define@key{buildMesh}{scale}[1cm]{\def\luameshval@scale{#1}}%
+\define@key{buildMesh}{scale}[1cm]{\def\luameshval@bm@scale{#1}}%
 %% print ponits ?
 \define@choicekey*{buildMesh}{print}[\val\nr]{none, points}{%
   \ifcase\nr\relax%
-  \def\luameshval@print{none}%
+  \def\luameshval@bm@print{none}%
   \or%
-  \def\luameshval@print{points}%
+  \def\luameshval@bm@print{points}%
   \fi%
 }%
 %% the name of the point
-\define@key{buildMesh}{meshpoint}[P]{\def\luameshval@meshpoint{#1}}%
+\define@key{buildMesh}{meshpoint}[P]{\def\luameshval@bm@meshpoint{#1}}%
 %% the mode for reading the points
 \define@choicekey*{buildMesh}{mode}[\val\nr]{int, ext}{%
   \ifcase\nr\relax%
-  \def\luameshval@mode{int}%
+  \def\luameshval@bm@mode{int}%
   \or%
-  \def\luameshval@mode{ext}%
+  \def\luameshval@bm@mode{ext}%
   \fi%
 }%
 %
-%% a complete picture or some code of the engine
-\define@choicekey*{buildMesh}{picture}[\val\nr]{full, embedded}{%
-  \ifcase\nr\relax%
-  \def\luameshval@picture{full}%
-  \or%
-  \def\luameshval@picture{embedded}%
-  \fi%
-}%
 %color
 %% the name of the color of drawing
-\define@key{buildMesh}{color}[black]{\def\luameshval@color{#1}}%
-
-\presetkeys{buildMesh}{tikz=false,bbox=none,scale, meshpoint,mode=int,print=none,picture=full,color}{}%
+\define@key{buildMesh}{color}[black]{\def\luameshval@bm@color{#1}}%
+%% the name of the color of drawing the bbox
+\define@key{buildMesh}{colorBbox}[black]{\def\luameshval@bm@colorbbox{#1}}%
+%
+\presetkeys{buildMesh}{tikz=false,bbox=none,scale, meshpoint,mode=int,print=none,color,colorBbox}{}%
 %
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % the difinition BW Bowyer and Watson algo
   % #1 : the string containing the list of points
   % (x1,y1);(x2,y2);... or the name file containing the points
   \setkeys{buildMesh}{#1} %
-  \def\MeshPoint{\luameshval@meshpoint}%
+  \def\MeshPoint{\luameshval@bm@meshpoint}%
   \ifKV@buildMesh@tikz% if we are using tikz
   \directlua{%
-    buildMeshTikZ("#2","\luameshval@mode","\luameshval@print","\luameshval@bbox","full","\luameshval@scale","\luameshval@color")%
+    buildMeshTikZ("#2","\luameshval@bm@mode","\luameshval@bm@print","\luameshval@bm@bbox","full","\luameshval@bm@scale","\luameshval@bm@color")%
   }%
   \else % we are using MP
+  \mplibcolor{\luameshmpcolor}{\luameshval@bm@color}
+  \mplibcolor{\luameshmpcolorBbox}{\luameshval@bm@colorbbox}
   \directlua{%
-    buildMeshMPBW("#2","\luameshval@mode","\luameshval@print","\luameshval@bbox","full","\luameshval@scale","\luameshval@color")%
+    buildMeshMPBW("#2","\luameshval@bm@mode","\luameshval@bm@print","\luameshval@bm@bbox","\luameshval@bm@scale")%
   }%
   %
   \fi%
 \define@key{MeshAddOne}{colorNew}[red]{\def\luameshval@colornew{#1}}%
 %% the color of circoncircle
 \define@key{MeshAddOne}{colorCircle}[green]{\def\luameshval@colorcircle{#1}}%
+%% the name of the color of drawing the bbox
+\define@key{MeshAddOne}{colorBbox}[black]{\def\luameshval@colorbbox{#1}}%
 %
 %% a complete picture or some code of the engine
 \define@choicekey*{MeshAddOne}{mode}[\val\nr]{int, ext}{%
   \def\luameshval@bbox{bbox}%
   \fi%
 }%
-\presetkeys{MeshAddOne}{tikz=false,scale, meshpoint,newpoint,color,colorBack,colorNew,colorCircle,step=badtriangles,mode=int,bbox=none}{}%
+\presetkeys{MeshAddOne}{tikz=false,scale, meshpoint,newpoint,color,colorBack,colorNew,colorCircle,step=badtriangles,mode=int,bbox=none,colorBbox}{}%
 %
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % the difinition BW Bowyer and Watson algo
   \mplibcolor{\luameshmpcolorBack}{\luameshval@colorback}
   \mplibcolor{\luameshmpcolorNew}{\luameshval@colornew}
   \mplibcolor{\luameshmpcolorCircle}{\luameshval@colorcircle}
+  \mplibcolor{\luameshmpcolorBbox}{\luameshval@colorbbox}
   \directlua{%
     TeXOnePointMPBW("#2","#3","\luameshval@step","\luameshval@scale","\luameshval@mode","\luameshval@bbox")%
   }%
 \define@key{MeshAddOneBWinc}{colorNew}[red]{\def\luameshval@colornew{#1}}%
 %% the color of circoncircle
 \define@key{MeshAddOneBWinc}{colorCircle}[green]{\def\luameshval@colorcircle{#1}}%
+\define@key{MeshAddOneBWinc}{colorBbox}[black]{\def\luameshval@colorbbox{#1}}%
 %
 %% a complete picture or some code of the engine
 \define@choicekey*{MeshAddOneBWinc}{mode}[\val\nr]{int, ext}{%
   \def\luameshval@bbox{bbox}%
   \fi%
 }%
-\presetkeys{MeshAddOneBWinc}{tikz=false,scale, meshpoint,newpoint,color,colorBack,colorNew,colorCircle,step=badtriangles,mode=int,bbox=none}{}%
+\presetkeys{MeshAddOneBWinc}{tikz=false,scale, meshpoint,newpoint,color,colorBack,colorNew,colorCircle,step=badtriangles,mode=int,bbox=none,colorBbox}{}%
 %
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % the difinition BW embedded code between the 2 last arguments
   \mplibcolor{\luameshmpcolorBack}{\luameshval@colorback}
   \mplibcolor{\luameshmpcolorNew}{\luameshval@colornew}
   \mplibcolor{\luameshmpcolorCircle}{\luameshval@colorcircle}
+  \mplibcolor{\luameshmpcolorBbox}{\luameshval@colorbbox}
   \directlua{%
     TeXOnePointMPBWinc("#2","#3","#4","#5","\luameshval@step","\luameshval@scale","\luameshval@mode","\luameshval@bbox")%
   }%
index acecd55..05c518f 100644 (file)
Binary files a/test/delaunay.pdf and b/test/delaunay.pdf differ
index ac45fa4..b45f05d 100644 (file)
@@ -9,9 +9,9 @@
 
 \buildMeshBW[print=points,  meshpoint = I, color=red]{(0,0);(3.5,3);(7,0);(7.5,5);(1.61,3.14);(3,1);(6,1.5)}
 
-\buildMeshBW[tikz, bbox = show]{(0,0);(3.5,3);(7,0);(7.5,5);(1.61,3.14);(3,1);(6,1.5)}
+%\buildMeshBW[tikz, bbox = show]{(0,0);(3.5,3);(7,0);(7.5,5);(1.61,3.14);(3,1);(6,1.5)}
 
-\buildMeshBW[mode=ext]{mesh.txt}
+\buildMeshBW[mode=ext,bbox = show, color=red,colorBbox = blue]{mesh.txt}
 
 \meshAddPointBW[
 meshpoint = x,
@@ -21,6 +21,7 @@ colorCircle = green!70,
 scale=0.6cm]
 {(0,0);(3.5,3);(7,0);(7.5,5);(1.61,3.14);(6,4)}{(3,1)}
 \meshAddPointBW[
+color = green,
 meshpoint = x,
 colorBack=red!10,
 colorNew = green!20!red,
@@ -34,7 +35,8 @@ colorNew = green!20!red,
 scale=0.6cm,
 step=badtriangles,
 newpoint = y,
-bbox = show
+bbox = show,
+colorBbox = black
 ]
 {(0,0);(3.5,3);(7,0);(7.5,5);(1.61,3.14);(6,4)}{(3,1)}
 
@@ -56,7 +58,8 @@ colorNew = green!20!red,
 scale=0.6cm,
 step=badtriangles,
 newpoint = y,
-bbox = show
+bbox = show,
+colorBbox = blue!20,
 ]
 {(0,0);(3.5,3);(7,0);(7.5,5);(1.61,3.14);(6,4)}{(3,1)}{%
 beginfig(0);

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.