82e32149f5dc95813b7b4a98485e30fca6b97c66
[delaunay.git] / luamesh.sty
1 \NeedsTeXFormat{LaTeX2e}%
2 \def\PackageName{luamesh}%
3 \def\fileversion{v0.1}%
4 \def\filedate{2016/11/20}%
5 \ProvidesPackage{luamesh}[\filedate\space\fileversion]%
6 %
7 % package to load
8 \RequirePackage{xkeyval,xcolor,ifthen}%
9 %% one global option: mp or tikz
10 %\newif\ifluameshmp%
11 %\define@key{luamesh.sty}{mp}[]{\luameshmptrue}%
12 %\define@key{luamesh.sty}{tikz}[]{\luameshmpfalse}%
13 %
14 \RequirePackage{etoolbox} % pour robustifier les commandes
15 %
16 %
17 %\ifluameshmp%
18    \RequirePackage{luamplib}%
19 %\else%
20    \RequirePackage{tikz}%
21 %\fi%
22 %
23 % load the lua code
24 \directlua{dofile("luamesh.lua")}%
25 %
26 %%
27 % for tikz (default value)
28 % default color for the plot of a global mesh
29 \definecolor{TeXCluaMeshTikZ}{rgb}{0.,0.,0.}
30 % default color for a new element
31 \definecolor{TeXCluaMeshNewTikZ}{rgb}{0.5,0.1,0.1}
32 % defaut color for the background of new element
33 \definecolor{TeXCluaMeshBackTikZ}{rgb}{0.99,0.85,0.85}
34 % default color for circoncircle
35 \definecolor{TeXCluaMeshCircleTikZ}{rgb}{0.1,0.6,0.1}
36
37
38 %%%%%%%%%%%%%%%% the buildMesh command
39 %% engine of drawing
40 \newif\ifluameshengineMP%
41 \define@boolkey{buildMesh}{tikz}[true]{}%
42 %% show the bounding box for delaunay
43 \define@choicekey*{buildMesh}{bbox}[\val\nr]{none, show}{%
44   \ifcase\nr\relax%
45   \def\luameshval@bm@bbox{none}%
46   \or%
47   \def\luameshval@bm@bbox{bbox}%
48   \fi%
49 }%
50 %% the scale
51 \define@key{buildMesh}{scale}[1cm]{\def\luameshval@bm@scale{#1}}%
52 %% print ponits ?
53 \define@choicekey*{buildMesh}{print}[\val\nr]{none, points}{%
54   \ifcase\nr\relax%
55   \def\luameshval@bm@print{none}%
56   \or%
57   \def\luameshval@bm@print{points}%
58   \fi%
59 }%
60 %% the name of the point
61 \define@key{buildMesh}{meshpoint}[P]{\def\luameshval@bm@meshpoint{#1}}%
62 %% the mode for reading the points
63 \define@choicekey*{buildMesh}{mode}[\val\nr]{int, ext}{%
64   \ifcase\nr\relax%
65   \def\luameshval@bm@mode{int}%
66   \or%
67   \def\luameshval@bm@mode{ext}%
68   \fi%
69 }%
70 %
71 %color
72 %% the name of the color of drawing
73 \define@key{buildMesh}{color}[black]{\def\luameshval@bm@color{#1}}%
74 %% the name of the color of drawing the bbox
75 \define@key{buildMesh}{colorBbox}[black]{\def\luameshval@bm@colorbbox{#1}}%
76 %
77 \presetkeys{buildMesh}{tikz=false,bbox=none,scale, meshpoint,mode=int,print=none,color,colorBbox}{}%
78 %
79 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 % the difinition BW Bowyer and Watson algo
81 \newcommand{\buildMeshBW}[2][]{%
82   % #1 : the string containing the list of points
83   % (x1,y1);(x2,y2);... or the name file containing the points
84   \setkeys{buildMesh}{#1} %
85   \def\MeshPoint{\luameshval@bm@meshpoint}%
86   \ifKV@buildMesh@tikz% if we are using tikz
87   \directlua{%
88     buildMeshTikZ("#2","\luameshval@bm@mode","\luameshval@bm@print","\luameshval@bm@bbox","full","\luameshval@bm@scale","\luameshval@bm@color")%
89   }%
90   \else % we are using MP
91   \mplibcolor{\luameshmpcolor}{\luameshval@bm@color}
92   \mplibcolor{\luameshmpcolorBbox}{\luameshval@bm@colorbbox}
93   \directlua{%
94     buildMeshMPBW("#2","\luameshval@bm@mode","\luameshval@bm@print","\luameshval@bm@bbox","\luameshval@bm@scale")%
95   }%
96   %
97   \fi%
98 }%
99 %
100 %%
101 %
102 %%the meshAddOnePointBW commande
103 %%engine of drawing
104 \newif\ifluameshengineMP%
105 \define@boolkey{MeshAddOne}{tikz}[true]{}%
106 %% the scale
107 \define@key{MeshAddOne}{scale}[1cm]{\def\luameshval@scale{#1}}%
108 %% the name of the points
109 \define@key{MeshAddOne}{meshpoint}[P]{\def\luameshval@meshpoint{#1}}%
110 %% the name of the new point
111 \define@key{MeshAddOne}{newpoint}[P]{\def\luameshval@newpoint{#1}}%
112 %% a complete picture or some code of the engine
113 \define@choicekey*{MeshAddOne}{step}[\val\nr]{badtriangles, cavity, newtriangles}{%
114   \ifcase\nr\relax%
115   \def\luameshval@step{badT}%
116   \or%
117   \def\luameshval@step{cavity}%
118   \or%
119   \def\luameshval@step{newT}%
120   \fi%
121 }%
122 % color
123 %% the color of drawing
124 \define@key{MeshAddOne}{color}[black]{\def\luameshval@color{#1}}%
125 %% the color of background of new element
126 \define@key{MeshAddOne}{colorBack}[black!20]{\def\luameshval@colorback{#1}}%
127 %% the color of new element
128 \define@key{MeshAddOne}{colorNew}[red]{\def\luameshval@colornew{#1}}%
129 %% the color of circoncircle
130 \define@key{MeshAddOne}{colorCircle}[green]{\def\luameshval@colorcircle{#1}}%
131 %% the name of the color of drawing the bbox
132 \define@key{MeshAddOne}{colorBbox}[black]{\def\luameshval@colorbbox{#1}}%
133 %
134 %% a complete picture or some code of the engine
135 \define@choicekey*{MeshAddOne}{mode}[\val\nr]{int, ext}{%
136   \ifcase\nr\relax%
137   \def\luameshval@mode{int}%
138   \or%
139   \def\luameshval@mode{ext}%
140   \fi%
141 }%
142 \define@choicekey*{MeshAddOne}{bbox}[\val\nr]{none, show}{%
143   \ifcase\nr\relax%
144   \def\luameshval@bbox{none}%
145   \or%
146   \def\luameshval@bbox{bbox}%
147   \fi%
148 }%
149 \presetkeys{MeshAddOne}{tikz=false,scale, meshpoint,newpoint,color,colorBack,colorNew,colorCircle,step=badtriangles,mode=int,bbox=none,colorBbox}{}%
150 %
151 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 % the difinition BW Bowyer and Watson algo
153 \newcommand*{\meshAddPointBW}[3][]{%
154   % #1 : the string containing the list of points
155   % (x1,y1);(x2,y2);... or the name file containing the points
156   \setkeys{MeshAddOne}{#1} %
157   \def\MeshPoint{\luameshval@meshpoint}%
158   \def\NewPoint{\luameshval@newpoint}%
159   \ifKV@MeshAddOne@tikz% if we are using tikz
160   \directlua{%
161     buildMeshTikZ("#2","\luameshval@mode","\luameshval@print","\luameshval@bbox","full","\luameshval@scale","\luameshval@color")%
162   }%
163   \else % we are using MP
164   \mplibcolor{\luameshmpcolor}{\luameshval@color}
165   \mplibcolor{\luameshmpcolorBack}{\luameshval@colorback}
166   \mplibcolor{\luameshmpcolorNew}{\luameshval@colornew}
167   \mplibcolor{\luameshmpcolorCircle}{\luameshval@colorcircle}
168   \mplibcolor{\luameshmpcolorBbox}{\luameshval@colorbbox}
169   \directlua{%
170     TeXOnePointMPBW("#2","#3","\luameshval@step","\luameshval@scale","\luameshval@mode","\luameshval@bbox")%
171   }%
172   %
173   \fi%
174 }%
175 %%% the meshAddPointBWinc commande
176 %% engine of drawing
177 \newif\ifluameshengineMP%
178 \define@boolkey{MeshAddOneBWinc}{tikz}[true]{}%
179 %% the scale
180 \define@key{MeshAddOneBWinc}{scale}[1cm]{\def\luameshval@scale{#1}}%
181 %% the name of the points
182 \define@key{MeshAddOneBWinc}{meshpoint}[P]{\def\luameshval@meshpoint{#1}}%
183 %% the name of the new point
184 \define@key{MeshAddOneBWinc}{newpoint}[P]{\def\luameshval@newpoint{#1}}%
185 %% a complete picture or some code of the engine
186 \define@choicekey*{MeshAddOneBWinc}{step}[\val\nr]{badtriangles, cavity, newtriangles}{%
187   \ifcase\nr\relax%
188   \def\luameshval@step{badT}%
189   \or%
190   \def\luameshval@step{cavity}%
191   \or%
192   \def\luameshval@step{newT}%
193   \fi%
194 }%
195 % color
196 %% the color of drawing
197 \define@key{MeshAddOneBWinc}{color}[black]{\def\luameshval@color{#1}}%
198 %% the color of background of new element
199 \define@key{MeshAddOneBWinc}{colorBack}[black!20]{\def\luameshval@colorback{#1}}%
200 %% the color of new element
201 \define@key{MeshAddOneBWinc}{colorNew}[red]{\def\luameshval@colornew{#1}}%
202 %% the color of circoncircle
203 \define@key{MeshAddOneBWinc}{colorCircle}[green]{\def\luameshval@colorcircle{#1}}%
204 \define@key{MeshAddOneBWinc}{colorBbox}[black]{\def\luameshval@colorbbox{#1}}%
205 %
206 %% a complete picture or some code of the engine
207 \define@choicekey*{MeshAddOneBWinc}{mode}[\val\nr]{int, ext}{%
208   \ifcase\nr\relax%
209   \def\luameshval@mode{int}%
210   \or%
211   \def\luameshval@mode{ext}%
212   \fi%
213 }%
214 \define@choicekey*{MeshAddOneBWinc}{bbox}[\val\nr]{none, show}{%
215   \ifcase\nr\relax%
216   \def\luameshval@bbox{none}%
217   \or%
218   \def\luameshval@bbox{bbox}%
219   \fi%
220 }%
221 \presetkeys{MeshAddOneBWinc}{tikz=false,scale, meshpoint,newpoint,color,colorBack,colorNew,colorCircle,step=badtriangles,mode=int,bbox=none,colorBbox}{}%
222 %
223 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 % the difinition BW embedded code between the 2 last arguments
225 \newcommand*{\meshAddPointBWinc}[5][]{%
226   % #1 : the string containing the list of points
227   % (x1,y1);(x2,y2);... or the name file containing the points
228   \setkeys{MeshAddOneBWinc}{#1} %
229   \def\MeshPoint{\luameshval@meshpoint}%
230   \def\NewPoint{\luameshval@newpoint}%
231   \ifKV@MeshAddOne@tikz% if we are using tikz
232   \directlua{%
233     buildMeshTikZ("#2","\luameshval@mode","\luameshval@print","\luameshval@bbox","full","\luameshval@scale","\luameshval@color")%
234   }%
235   \else % we are using MP
236   \mplibcolor{\luameshmpcolor}{\luameshval@color}
237   \mplibcolor{\luameshmpcolorBack}{\luameshval@colorback}
238   \mplibcolor{\luameshmpcolorNew}{\luameshval@colornew}
239   \mplibcolor{\luameshmpcolorCircle}{\luameshval@colorcircle}
240   \mplibcolor{\luameshmpcolorBbox}{\luameshval@colorbbox}
241   \directlua{%
242     TeXOnePointMPBWinc("#2","#3","#4","#5","\luameshval@step","\luameshval@scale","\luameshval@mode","\luameshval@bbox")%
243   }%
244   %
245   \fi%
246 }%
247 %

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.