1 \NeedsTeXFormat{LaTeX2e}%
2 \def\PackageName{luamesh}%
3 \def\fileversion{v0.1}%
4 \def\filedate{2016/11/20}%
5 \ProvidesPackage{luamesh}[\filedate\space\fileversion]%
8 \RequirePackage{xkeyval,xcolor,ifthen}%
9 %% one global option: mp or tikz
11 %\define@key{luamesh.sty}{mp}[]{\luameshmptrue}%
12 %\define@key{luamesh.sty}{tikz}[]{\luameshmpfalse}%
14 \RequirePackage{etoolbox} % pour robustifier les commandes
18 \RequirePackage{luamplib}%
20 \RequirePackage{tikz}%
24 \directlua{dofile("luamesh.lua")}%
26 % global def (default value)
27 \newcommand{\MeshPoint}{P}
28 \newcommand{\NewPoint}{P}
29 % for MetaPost (MP) (default value)
30 % default scale u:=1cm;
31 \newcommand\luaMeshScaleMP{1cm}
32 % default color for the plot of a global mesh
33 \newcommand\TeXCluaMeshMP{(0.,0.,0.)}
34 % default color for a new element
35 \newcommand\TeXCluaMeshNewMP{(0.5,0.1,0.1)}
36 % defaut color for the background of new element
37 \newcommand\TeXCluaMeshBackMP{(0.99,0.85,0.85)}
38 % default color for circoncircle
39 \newcommand\TeXCluaMeshCircleMP{(0.1,0.6,0.1)}
41 % for tikz (default value)
42 % default color for the plot of a global mesh
43 \definecolor{TeXCluaMeshTikZ}{rgb}{0.,0.,0.}
44 % default color for a new element
45 \definecolor{TeXCluaMeshNewTikZ}{rgb}{0.5,0.1,0.1}
46 % defaut color for the background of new element
47 \definecolor{TeXCluaMeshBackTikZ}{rgb}{0.99,0.85,0.85}
48 % default color for circoncircle
49 \definecolor{TeXCluaMeshCircleTikZ}{rgb}{0.1,0.6,0.1}
52 %%%%%%%%%%%%%%%% the buildMesh command
54 \newif\ifluameshengineMP%
55 \define@boolkey{buildMesh}{tikz}[true]{}%
56 %% show the bounding box for delaunay
57 \define@choicekey*{buildMesh}{bbox}[\val\nr]{none, show}{%
59 \def\luameshval@bbox{none}%
61 \def\luameshval@bbox{bbox}%
65 \define@key{buildMesh}{scale}[1cm]{\def\luameshval@scale{#1}}%
67 \define@choicekey*{buildMesh}{print}[\val\nr]{none, points}{%
69 \def\luameshval@print{none}%
71 \def\luameshval@print{points}%
74 %% the name of the point
75 \define@key{buildMesh}{meshpoint}[P]{\def\luameshval@meshpoint{#1}}%
76 %% the mode for reading the points
77 \define@choicekey*{buildMesh}{mode}[\val\nr]{int, ext}{%
79 \def\luameshval@mode{int}%
81 \def\luameshval@mode{ext}%
85 %% a complete picture or some code of the engine
86 \define@choicekey*{buildMesh}{picture}[\val\nr]{full, embedded}{%
88 \def\luameshval@picture{full}%
90 \def\luameshval@picture{embedded}%
94 %% the name of the color of drawing
95 \define@key{buildMesh}{color}[black]{\def\luameshval@color{#1}}%
97 \presetkeys{buildMesh}{tikz=false,bbox=none,scale, meshpoint,mode=int,print=none,picture=full,color}{}%
99 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 \newcommand{\buildMesh}[2][]{%
102 % #1 : the string containing the list of points
103 % (x1,y1);(x2,y2);... or the name file containing the points
104 \setkeys{buildMesh}{#1} %
105 \def\MeshPoint{\luameshval@meshpoint}%
106 \ifKV@buildMesh@tikz% if we are using tikz
108 buildMeshTikZ("#2","\luameshval@mode","\luameshval@print","\luameshval@bbox","full","\luameshval@scale","\luameshval@color")%
110 \else % we are using MP
112 buildMeshMP("#2","\luameshval@mode","\luameshval@print","\luameshval@bbox","full","\luameshval@scale","\luameshval@color")%
120 %%the meshAddOnePoint commande
122 \newif\ifluameshengineMP%
123 \define@boolkey{MeshAddOne}{tikz}[true]{}%
125 \define@key{MeshAddOne}{scale}[1cm]{\def\luameshval@scale{#1}}%
126 %% the name of the points
127 \define@key{MeshAddOne}{meshpoint}[P]{\def\luameshval@meshpoint{#1}}%
128 %% the name of the new point
129 \define@key{MeshAddOne}{newpoint}[P]{\def\luameshval@newpoint{#1}}%
130 %% a complete picture or some code of the engine
131 \define@choicekey*{MeshAddOne}{picture}[\val\nr]{full, simple}{%
133 \def\luameshval@picture{full}%
135 \def\luameshval@picture{simple}%
138 %% a complete picture or some code of the engine
139 \define@choicekey*{MeshAddOne}{step}[\val\nr]{badtriangles, cavity, newtriangles}{%
141 \def\luameshval@step{badT}%
143 \def\luameshval@step{cavity}%
145 \def\luameshval@step{newT}%
149 %% the color of drawing
150 \define@key{MeshAddOne}{color}[black]{\def\luameshval@color{#1}}%
151 %% the color of background of new element
152 \define@key{MeshAddOne}{colorBack}[black!20]{\def\luameshval@colorback{#1}}%
153 %% the color of new element
154 \define@key{MeshAddOne}{colorNew}[red]{\def\luameshval@colornew{#1}}%
155 %% the color of circoncircle
156 \define@key{MeshAddOne}{colorCircle}[green]{\def\luameshval@colorcircle{#1}}%
158 %% a complete picture or some code of the engine
159 \define@choicekey*{MeshAddOne}{mode}[\val\nr]{int, ext}{%
161 \def\luameshval@mode{int}%
163 \def\luameshval@mode{ext}%
166 %% a complete picture or some code of the engine
167 \define@choicekey*{MeshAddOne}{picture}[\val\nr]{full, embedded}{%
169 \def\luameshval@picture{full}%
171 \def\luameshval@picture{embedded}%
174 \define@choicekey*{MeshAddOne}{bbox}[\val\nr]{none, show}{%
176 \def\luameshval@bbox{none}%
178 \def\luameshval@bbox{bbox}%
181 \presetkeys{MeshAddOne}{tikz=false,scale, meshpoint,newpoint,color,colorBack,colorNew,colorCircle,step=badtriangles,mode=int,picture=full,bbox=none}{}%
183 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 \newcommand{\meshAddOnePoint}[3][]{%
186 % #1 : the string containing the list of points
187 % (x1,y1);(x2,y2);... or the name file containing the points
188 \setkeys{MeshAddOne}{#1} %
189 \def\MeshPoint{\luameshval@meshpoint}%
190 \def\NewPoint{\luameshval@newpoint}%
191 \ifKV@MeshAddOne@tikz% if we are using tikz
193 buildMeshTikZ("#2","\luameshval@mode","\luameshval@print","\luameshval@bbox","full","\luameshval@scale","\luameshval@color")%
195 \else % we are using MP
196 \mplibcolor{\mpcolorcolor}{\luameshval@color}
197 \mplibcolor{\mpcolorcolorBack}{\luameshval@colorback}
198 \mplibcolor{\mpcolorcolorNew}{\luameshval@colornew}
199 \mplibcolor{\mpcolorcolorCircle}{\luameshval@colorcircle}
201 TeXOnePointMP("#2","#3","\luameshval@step","\luameshval@color","\luameshval@colorback","\luameshval@colornew","\luameshval@colorcircle","\luameshval@scale","\luameshval@mode","\luameshval@picture","\luameshval@bbox")%