summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pst-intersect/pst-intersect.tex
blob: 099d487e7486b4057c37cf463fcbeaad826e04db (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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
%%
%% This is file `pst-intersect.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% pst-intersect.dtx  (with options: `texfile')
%% 
%% This is a generated file.
%% 
%% Project: pst-intersect
%% Version: 0.3 (2014/03/04)
%% 
%% Copyright (C) 2007-2014 by Christoph Bersch <usenet@bersch.net>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008/05/04 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The current maintainer of this work is Christoph Bersch.
%% 
%% This work consists of the files pst-intersect.dtx and pst-intersect.ins
%% and the derived files
%%     pst-intersect.sty, pst-intersect.tex, pst-intersect.pro.
%% 
\csname PSTintersectLoaded\endcsname
\let\PSTintersectLoaded\endinput

\ifx\PSTricksLoaded\endinput\else\input pstricks.tex \fi
\ifx\PSTXKeyLoaded\endinput\else \input pst-xkey.tex \fi
\ifx\PSTnodesLoaded\endinput\else\input pst-node.tex \fi
\ifx\PSTfuncLoaded\endinput\else \input pst-func.tex \fi

\edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax

\pst@addfams{intersect}
\pstheader{pst-intersect.pro}

\def\pst@intersectdict{tx@IntersectDict begin }
\def\PIT@dict#1{\pst@intersectdict #1 end}
\def\PIT@Verb#1{\pst@Verb{\PIT@dict{#1} }}%
\define@key[psset]{intersect}{tstart}{%
  \pst@checknum{#1}\PIT@key@tstart
}
\define@key[psset]{intersect}{tstop}{%
  \pst@checknum{#1}\PIT@key@tstop
}
\define@key[psset]{intersect}{istart}{%
  \pst@checknum{#1}\PIT@key@istart
}
\define@key[psset]{intersect}{istop}{%
  \pst@checknum{#1}\PIT@key@istop
}
\define@key[psset]{intersect}{name}{%
  \def\PIT@key@name{#1}%
}%
\newif\PIT@saveintersections
\define@boolkey[psset]{intersect}[PIT@]{saveintersections}[true]{}

\psset[intersect]{%
  tstart=-1,
  tstop=-1,
  istart=-1,
  istop=-1,
  name={},
  saveintersections
}%
\def\PIT@use@pscode{%
  \pstverb{%
    \pst@dict
    \tx@STP
    \pst@newpath
    \psk@origin
    \psk@swapaxes
    \pst@code
    end
    count /ocount exch def
  }%
  \gdef\pst@code{}%
}%
\let\PIT@pst@stroke@orig\pst@stroke
\def\PIT@save@path{%
  \PIT@pst@stroke@orig
  \addto@pscode{%
    clear mark
    \pst@intersectdict GetFullPath end
    counttomark 1 add -1 roll pop count }%
}%
\def\PIT@name@default{@tmp}%
\def\PIT@name#1{PIT@#1}%
\def\PIT@checkname#1{%
  \ifx\@empty#1\@empty
    \@pstrickserr{Unexpected empty argument!}\@ehpb
  \fi
}%
\def\pssavebezier{\pst@object{pssavebezier}}
\def\pssavebezier@i#1{%
  \begin@OpenObj
    \PIT@checkname{#1}%
    \addto@pscode{ /\PIT@name{#1} }%
    \pst@getcoors[\pssavebezier@ii%]
}%
\def\pssavebezier@ii{%
  \addto@pscode{%
    counttomark 20 gt { counttomark 20 sub { pop } repeat } if
    counttomark 2 idiv 1 sub
    \psk@plotpoints\space exch
    \txFunc@BezierCurve
    \ifshowpoints \txFunc@BezierShowPoints \else pop \fi
    tx@FuncDict begin Points aload pop end
  }%
  \let\use@pscode\PIT@use@pscode
  \end@OpenObj
  \PIT@Verb{%
    [ count 1 sub 1 roll ] ArrayToPointArray def
  }%
\ignorespaces}%
\def\pssavepath{\pst@object{pssavepath}}%
\long\def\pssavepath@i#1#2{%
  \begin@SpecialObj
    \PIT@checkname{#1}%
    \let\pst@stroke\PIT@save@path
    \let\use@pscode\PIT@use@pscode
    \pscustom{#2}%
    \PIT@Verb{%
      /\PIT@name{#1}
      [ 3 -1 roll 2 add 2 roll ] def }%
  \end@SpecialObj
}%
\def\pstracecurve{\pst@object{pstracecurve}}%
\def\pstracecurve@i#1{%
  \addbefore@par{plotpoints=200}%
  \begin@OpenObj
   \@ifnextchar\bgroup
     {\PIT@traceintersection{#1}}%
     {\PIT@tracecurve{#1}}%
}%
\def\PIT@tracecurve#1{%
  \PIT@checkname{#1}%
  \addto@pscode{%
    \pst@intersectdict
    \PIT@key@tstop\space dup 0 lt { pop \PIT@name{#1} GetSegmentCount } if
    \PIT@key@tstart\space dup 0 lt { pop 0 } if exch
    \PIT@name{#1} GetSegmentCount
    2 copy exch dup 3 1 roll
    lt exch 0 lt or { exch } if pop
    \PIT@name{#1} dup IsPath {
      3 1 roll 2 copy gt {
        exch 3 -1 roll dup 4 1 roll GetSegmentCount
        dup 4 1 roll exch sub 3 1 roll sub exch
        gsave newpath
          [ 4 -1 roll aload pop InitTracing
          { counttomark 0 eq { exit } if
            load exec
          } loop
          reversepath
          GetFullPath ] 3 1 roll
        grestore
      } if
      ShowPathPortion
    }{
      [ exch dup 5 -2 roll
      2 copy gt {
        exch
        2 copy gt { exch } if
        [ 5 -2 roll pop PointArrayToArray aload pop
        counttomark -2 4 { 2 roll } for ] ArrayToPointArray dup
        4 2 roll
      } if
      ToUnitInterval Portion
      { aload pop } forall
      counttomark -2 4 { 2 roll } for
      counttomark 2 sub 2 idiv
      \psk@plotpoints
      exch
      \txFunc@BezierCurve
      \ifshowpoints \txFunc@BezierShowPoints \else pop \fi
    } ifelse
    end
  }%
  \end@OpenObj
}%
\def\PIT@traceintersection#1#2{%
  \PIT@checkname{#2}%
  \addto@pscode{%
    \pst@intersectdict
    \ifx\\#1\\%
    /\PIT@name{\PIT@name@default}
    \else
    /\PIT@name{#1}
    \fi
    dup currentdict exch known not {
      \ifx\\#1\\%
      (You haven't defined an intersection!) ==
      \else
      (You haven't defined the intersection '#1') ==
      \fi
    } if
    load
    dup dup type /dicttype eq exch /\PIT@name{#2} known and not {
      (You haven't defined the intersection '#2') ==
    } if
    dup /\PIT@name{#2} get
    exch /\PIT@name{#2}@t get
    dup length \PIT@key@istart\space ge 0 \PIT@key@istart\space lt and {
      dup \PIT@key@istart\space cvi 1 sub get
    } {
      \PIT@key@tstart
    } ifelse
    dup 0 lt { pop 0 } if
    exch % [curve] t_istart|tstart [ts]
    %
    dup length \PIT@key@istop\space ge 0 \PIT@key@istop\space lt and {
      \PIT@key@istop\space cvi 1 sub get
    } {
      pop \PIT@key@tstop
    } ifelse
    3 -1 roll dup 4 1 roll GetSegmentCount
    2 copy exch dup 3 1 roll % [curve] tstart tstop cnt tstop cnt tstop
    lt exch 0 lt or { exch } if pop % (tstop < 0 | cnt < tstop)
    3 -1 roll dup
    IsPath {
      3 1 roll
      2 copy gt {
        exch 3 -1 roll dup 4 1 roll GetSegmentCount
        dup 4 1 roll exch sub 3 1 roll sub exch
        gsave newpath
          [ 4 -1 roll aload pop InitTracing
          { counttomark 0 eq { exit } if
            load exec
          } loop
          reversepath
          GetFullPath ] 3 1 roll
        grestore
      } if
      ShowPathPortion
    }{
      [ exch dup 5 -2 roll
      exch dup 0 lt { pop 0 } if exch
      dup 0 lt { pop 1 } if
      2 copy gt {
        exch
        [ 5 -2 roll pop PointArrayToArray aload pop
        counttomark -2 4 { 2 roll } for ] ArrayToPointArray dup
        4 2 roll
      } if
      ToUnitInterval Portion
      { aload pop } forall
      counttomark 2 sub 2 idiv
      \psk@plotpoints
      exch
      \txFunc@BezierCurve
      \ifshowpoints \txFunc@BezierShowPoints \else pop \fi
    } ifelse
    end
  }%
  \end@OpenObj
}%
\def\psintersect{\pst@object{psintersect}}
\def\psintersect@i#1#2{%
  \PIT@checkname{#1}%
  \PIT@checkname{#2}%
  \begin@SpecialObj
  \def\PIT@@name{%
    \ifx\PIT@key@name\@empty
      \PIT@name{\PIT@name@default}
    \else
      \PIT@name{\PIT@key@name}
    \fi}%
  \PIT@Verb{%
    currentdict /\PIT@name{#1} known not {
      (You haven't defined the curve or path '#1') ==
    } if
    currentdict /\PIT@name{#2} known not {
      (You haven't defined the curve or path '#2') ==
    } if
    \PIT@name{#1} \PIT@name{#2}
    \PIT@name{#1} IsPath {
      \PIT@name{#2} IsPath {
        IntersectPaths
      }{
        IntersectPathCurve
      } ifelse
    }{
      \PIT@name{#2} IsPath {
        IntersectCurvePath
      }{
        IntersectBeziers
        4 copy LoadIntersectionPoints 5 1 roll
      } ifelse
    } ifelse
    /\PIT@@name\space /\PIT@name{#1} /\PIT@name{#2} 8 3 roll
    SaveIntersection
  }%
  \ifPIT@saveintersections
    \pst@Verb{%
      \pst@intersectdict
        \PIT@@name\space /Points get
        ArrayToPointArray
      end
      dup length 1 1 3 -1 roll {
        2 copy 1 sub get
        \ifPst@saveNodeCoors
          \pst@intersectdict
          2 copy aload pop \tx@UserCoor 3 -1 roll
          20 string cvs (N-\PIT@key@name) exch strcat dup
          (.y) strcat cvn exch (.x) strcat cvn
          end
          4 -1 roll def exch def
        \fi
        cvx
        false 3 -1 roll (N@\PIT@key@name) exch 20 string cvs
        \pst@intersectdict strcat end cvn
        tx@NodeDict begin
          10 {InitPnode} /NodeScale {} def NewNode
        end
      } for
      pop
    }%
  \fi
  \ifshowpoints
    \addto@pscode{%
      \pst@intersectdict
        [ \PIT@@name\space /Points get aload pop
      end
    }%
    \psdots@ii
  \else
    \end@SpecialObj
  \fi
}%
\def\psGetIsectCenter#1#2#3{%
  \pst@intersectdict
  \ifx\\#2\\%
    \PIT@name{#1} /Points get dup #3 1 sub 2 mul get exch #3 2 mul 1 sub get
  \else
    \PIT@name{#1} /\PIT@name{#2@t} get #3 1 sub get
    \PIT@name{#1} /\PIT@name{#2} get
    dup IsPath {
      PreparePath dup length 1 sub
      3 -1 roll dup dup
      cvi sub 4 1 roll
      cvi sub get
    } if
    PointArrayToArray
    tx@FuncDict begin 2 dict begin
      dup length 2 idiv 1 sub /BezierType exch def /Points exch def GetBezierCoor
    end end
  \fi
  end
  \tx@UserCoor /I-#1#3.y exch def /I-#1#3.x exch def
}%
\catcode`\@=\PstAtCode\relax
\endinput
%%
%% End of file `pst-intersect.tex'.