summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pst-poly/pst-poly.tex
blob: ab5afcca6506ffa1468726c156b7b8b03d086a90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
%% $Id: pst-poly.tex 332 2010-05-28 18:45:07Z herbert $
%%
%% This is file `pst-poly.tex',
%% 
%% IMPORTANT NOTICE:
%% 
%% (C)
%% Denis Girou (CNRS/IDRIS - France) <Denis.Girou@idris.fr>
%% Herbert Voss <hvoss@tug.org>
%%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN archives
%% in directory macros/latex/base/lppl.txt.
%%
%% DESCRIPTION:
%%   `pst-poly' is a PSTricks package to draw easily various kinds of regular
%%   or non regular polygons, with various customizations.
%%
%
\csname PSTPolygonLoaded\endcsname
\let\PSTPolygonLoaded\endinput
\ifx\PSTricksLoaded\endinput\else\input pstricks.tex\fi
\ifx\PSTnodesLoaded\endinput\else\input pst-node.tex\fi
\ifx\MultidoLoaded\endinput\else \input multido.tex\fi
\ifx\PSTXKeyLoaded\endinput\else \input pst-xkey \fi
%
\def\fileversion{1.63}
\def\filedate{2014/08/28}
\message{`PST-Polygon' v\fileversion, \filedate\space (DG/hv)}
%
\edef\PstAtCode{\the\catcode`\@}
\catcode`\@=11\relax
\pst@addfams{pst-poly}
\define@boolkey[psset]{pst-poly}[Pst@]{PstPicture}[true]{}
\define@key[psset]{pst-poly}{PolyRotation}[0]{\def\PstPoly@Rotation{#1}}
\define@key[psset]{pst-poly}{PolyNbSides}[5]{\pst@getint{#1}{\PstPoly@NbSides}%
  \ifnum\PstPoly@NbSides<3
    \@pstrickserr{PolyNbSides must be greater than 2
                (and not `\PstPoly@NbSides')}{\@eha}%
  \fi%
  \ifnum\PstPoly@NbSides>200
    \@pstrickserr{PolyNbSides must be less than 201
                (and not `\PstPoly@NbSides')}{\@eha}%
  \fi}
\define@key[psset]{pst-poly}{PolyOffset}[1]{\pst@getint{#1}{\PstPoly@Offset}%
  \ifnum\PstPoly@Offset<1
    \@pstrickserr{PolyOffset must be greater than 0
                (and not `\PstPoly@Offset')}{\@eha}%
  \fi}
\newdimen\PstPoly@IntermediatePointDim
\define@key[psset]{pst-poly}{PolyIntermediatePoint}[]{\def\PstPoly@IntermediatePoint{#1}}
\define@key[psset]{pst-poly}{PolyName}[]{\def\PstPoly@Name{#1}}
\define@boolkey[psset]{pst-poly}[Pst@]{PolyCurves}[true]{}
\define@boolkey[psset]{pst-poly}[Pst@]{PolyEpicycloid}[true]{}
\psset{%
  PstPicture=true,PolyRotation=0,PolyNbSides=5,PolyOffset=1,
  PolyIntermediatePoint=,PolyName=,PolyCurves=false,PolyEpicycloid=false}
%
\SpecialCoor
%
\def\PstPolygon{\pst@object{PstPolygon}}
\def\PstPolygon@i{{%
  \use@par
  \if@star\solid@star\fi
  \ifodd\PstPoly@Offset\def\PstPoly@Decimal{.5}\else\def\PstPoly@Decimal{}\fi
  \ifPst@PstPicture\pspicture(-1,-1)(1,1)\fi
  \rput{\PstPoly@Rotation}(0,0){%
    \degrees[\PstPoly@NbSides]%
    \NormalCoor
    \pssetlength{\PstPoly@IntermediatePointDim}{\PstPoly@IntermediatePoint}%
    \SpecialCoor
    \ifx\PstPoly@Name\@empty
    \else
      \pnode(0,0){\PstPoly@Name 0}%
      \ifnum\psxunit=\psyunit
        \def\PstPoly@Node{\pnode(1;\i)}%
      \else
        \def\PstPoly@Node{%
          \pnode(! \i\space 360 \PstPoly@NbSides\space div mul cos
                   \i\space 360 \PstPoly@NbSides\space div mul sin)}%
      \fi
      \multido{\i=0+1}{\PstPoly@NbSides}{%
        \PstPoly@Node{\PstPoly@Name\the\multidocount}}%
    \fi
    \pscustom{
      \ifPst@PolyEpicycloid
        \pst@cnta=\PstPoly@NbSides
        \divide\pst@cnta\tw@
        \multido{\i=0+1}{\PstPoly@NbSides}{%
          \moveto(1;\i)
          \lineto(1;\the\pst@cnta)
          \advance\pst@cnta\PstPoly@Offset}%
      \else
        \ifnum\psxunit=\psyunit \moveto(1,0)\else\moveto(! 1 0)\fi
        \ifx\PstPoly@IntermediatePoint\@empty
          \ifnum\psxunit=\psyunit
            \def\PstPoly@Junction{\lineto(1;\i)}%
          \else
            \def\PstPoly@Junction{\lineto
              (! \i\space 360 \PstPoly@NbSides\space div mul cos
               \i\space 360 \PstPoly@NbSides\space div mul sin)}%
          \fi
          \multido{\i=\PstPoly@Offset+\PstPoly@Offset}{\PstPoly@NbSides}{\PstPoly@Junction}%
        \else
          \ifPst@PolyCurves\let\PstPoly@JunctionType\pscurve\else\let\PstPoly@JunctionType\psline\fi
          \ifnum\psxunit=\psyunit
            \def\PstPoly@Junction{\PstPoly@JunctionType%
              (\PstPoly@IntermediatePointDim;\the\pst@cnta\PstPoly@Decimal)(1;\i)}%
          \else
            \def\PstPoly@Junction{\PstPoly@JunctionType%
              (! \PstPoly@IntermediatePoint\space \the\pst@cnta\PstPoly@Decimal\space 360
                   \PstPoly@NbSides\space div mul cos mul
                 \PstPoly@IntermediatePoint\space \the\pst@cnta\PstPoly@Decimal\space 360
                   \PstPoly@NbSides\space div mul sin mul)
              (! \i\space 360 \PstPoly@NbSides\space div mul cos \i\space 360 \PstPoly@NbSides\space div mul sin)}%
          \fi
          \pst@cnta=\PstPoly@Offset
          \divide\pst@cnta\tw@
          \multido{\i=\PstPoly@Offset+\PstPoly@Offset}{\PstPoly@NbSides}{%
            \PstPoly@Junction
            \advance\pst@cnta\PstPoly@Offset}%
        \fi
      \fi}%
    \ifx\PstPolygonNode\@undefined
    \else\multido{\INode=\z@+\PstPoly@Offset}{\PstPoly@NbSides}{\PstPolygonNode}\fi}%
  \ifPst@PstPicture\endpspicture\fi
}}
%
\def\PstTriangle{\pst@object{PstTriangle}}
\def\PstTriangle@i{{%
  \addto@par{PolyNbSides=3,PolyRotation=90}% For triangle (360/3*(3/4))
  \use@par%
  \if@star\solid@star\fi
  \PstPolygon}}
%
\def\PstSquare{\pst@object{PstSquare}}
  \def\PstSquare@i{{%
  \addto@par{PolyNbSides=4,PolyRotation=45}% For square (360/4/2)
  \use@par%
  \if@star\solid@star\fi
  \PstPolygon}}
%
\def\PstPentagon{\pst@object{PstPentagon}}
  \def\PstPentagon@i{{%
  \addto@par{PolyNbSides=5,PolyRotation=18}% For pentagon (360/5/4)
  \use@par
  \if@star\solid@star\fi
  \PstPolygon}}
%
\def\PstHexagon{\pst@object{PstHexagon}}
\def\PstHexagon@i{{%
  \addto@par{PolyNbSides=6}%
  \use@par%
  \if@star\solid@star\fi
  \PstPolygon}}
%
\def\PstHeptagon{\pst@object{PstHeptagon}}
\def\PstHeptagon@i{{%
  \addto@par{PolyNbSides=7,PolyRotation=38.57}% For heptagon (360/7*(3/4))
  \use@par%
  \if@star\solid@star\fi
  \PstPolygon}}
%
\def\PstOctogon{\pst@object{PstOctogon}}
\def\PstOctogon@i{{%
  \addto@par{PolyNbSides=8,PolyRotation=22.5}% For octogon (360/8/2)
  \use@par%
  \if@star\solid@star\fi
  \PstPolygon}}
%
\def\PstNonagon{\pst@object{PstNonagon}}
\def\PstNonagon@i{{%
  \addto@par{PolyNbSides=9,PolyRotation=10}% For nonagon (360/9/4)
  \use@par%
  \if@star\solid@star\fi
  \PstPolygon}}
%
\def\PstDecagon{\pst@object{PstDecagon}}
\def\PstDecagon@i{{%
  \addto@par{PolyNbSides=10}%
  \use@par%
  \if@star\solid@star\fi
  \PstPolygon}}
%
\def\PstDodecagon{\pst@object{PstDodecagon}}
\def\PstDodecagon@i{{%
  \addto@par{PolyNbSides=12,PolyRotation=15}% For dodecagon (360/12/2)
  \use@par%
  \if@star\solid@star\fi
  \PstPolygon}}
%  
\def\PstStarFiveLines{\pst@object{PstStarFiveLines}}
\def\PstStarFiveLines@i{{%
  \addto@par{PolyOffset=2,PolyRotation=18}%
  \use@par%
  \if@star\solid@star\fi
  \PstPolygon}}
%
\def\PstStarFive{\pst@object{PstStarFive}}
\def\PstStarFive@i{{%
  \addto@par{PolyIntermediatePoint=0.38,PolyRotation=18}%
  \use@par%
  \if@star\solid@star\fi
  \PstPolygon}}
%
% Aspecial version for pst-poly
\def\pst@polypyth#1#2#3{\ifdim#1>#2\pst@@polypyth#1#2#3\else\pst@@polypyth#2#1#3\fi}
\def\pst@@polypyth#1#2#3{%
     \ifdim4#1>9#2 #3=#1\advance#3 .2122#2%
     \else#3=.8384#1\advance#3 .5758#2\fi}
%
\def\pspolygonbox{\pst@object{pspolygonbox}}%   voss 2004-11-20
\def\pspolygonbox@i{\pst@makebox\pspolygonbox@ii}
\def\pspolygonbox@ii{%
   \begingroup%
   \addbefore@par{boxsep=true}%
   \pst@useboxpar%
   \pst@dima=\pslinewidth%
   \ifpsdoubleline%
     \advance\pst@dima by \psdoublesep\pslinewidth%
     \advance\pst@dima by \pslinewidth%
   \fi%
   \advance\pst@dima by \psframesep%
   \pst@dimc=\wd\pst@hbox%
   \pst@dimp=\pst@dimc 
   \advance\pst@dimp by 2\pst@dima
   \pst@dimb=\dp\pst@hbox
   \pst@dimo=\pst@dimb%
   \pst@dimd=\ht\pst@hbox
   \advance\pst@dimo by \pst@dimd% totalheight
   \pst@polypyth\pst@dimp\pst@dimo\pst@dimm
   \global\divide\pst@dimm by 2% Radius
   \setbox\pst@hbox=\hbox{%
     \ifpsboxsep\kern\pst@dima\fi% left side
     \begin@ClosedObj%
       \addto@pscode{
         /framesep \pst@number\pst@dima def
         /boxdepth \pst@number\pst@dimb framesep add def
         /boxheight0 \pst@number\pst@dimd def
         /boxheight boxheight0 framesep add def
         /boxwidth \pst@number\pst@dimc def
         /radius \pst@number\pst@dimm def
         /order \PstPoly@NbSides\space def
         /dAlpha 360 order div def
         /alpha \PstPoly@Rotation\space def
         \pst@cp
         \tx@polygonB
         \psline@iii
         \tx@Polygon
       }%
       \def\pst@linetype{1}%
       \showpointsfalse%
     \end@ClosedObj%
     \box\pst@hbox%
     \ifpsboxsep\kern\pst@dima\fi%% right side
   }%
   \ifpsboxsep%
     \pst@dimn=-.5\pst@dimo\advance\pst@dimn by \pst@dimb%
     \advance\pst@dimn by 0.809\pst@dimm%
     \dp\pst@hbox=\pst@dimn%
     \pst@dimn=\pst@dimm\advance\pst@dimn by 0.5\pst@dimo%
     \advance\pst@dimn by -\pst@dimb%
     \ht\pst@hbox=\pst@dimn\fi%
   \leavevmode%
   \box\pst@hbox%
   \endgroup%
  \ignorespaces}
%
\pst@def{polygonB}<{%
  /x1 framesep neg def
  /x2 boxwidth framesep add def
  /y1 boxdepth framesep add neg def
  /y2 boxheight framesep add def
  x2 x1 add 2 div y2 y1 add 2 div translate
  [
  alpha cos radius mul
  alpha sin radius mul
  order { /alpha alpha dAlpha add def
    radius alpha cos mul
    radius alpha sin mul
  } repeat
}>
%
\catcode`\@=\PstAtCode\relax
\endinput
%%
%% End of file `pst-poly.tex'.