Debian Codegraph @

texmf-dist/source/latex/curve2e/curve2e.dtx

raw
1 % \iffalse
2 % !TEX encoding = UTF-8 Unicode
3 %<*internal>
4 \begingroup
5 \input docstrip.tex
6 \keepsilent
7 \preamble
8
9 Copyright (C) 2005--2024 Claudio Beccari all
10 rights reserved.
11 License information appended
12
13 \endpreamble
14
15 \postamble
16
17 Distributable under the LaTeX Project Public
18 License, version 1.3c or higher (your choice).
19 The latest version of this license is at:
20 http://www.latex-project.org/lppl.txt
21
22 This work is "maintained"
23
24 This work consists of file curve2e.dtx, and the
25 derived files curve2e.sty and curve2e.pdf, plus
26 the auxiliary derived files README.txt and
27 curve2e-v161.sty.
28
29 \endpostamble
30 \askforoverwritefalse
31
32 \generate{\file{curve2e.sty}{\from{curve2e.dtx}{package}}}
33 \generate{\file{README.txt}{\from{curve2e.dtx}{readme}}}
34 \generate{\file{curve2e-v161.sty}{\from{curve2e.dtx}{v161}}}
35
36 \def\tmpa{plain}
37 \ifx\tmpa\fmtname\endgroup\expandafter\bye\fi
38 \endgroup
39 %</internal>
40 % \fi
41 %
42 % \iffalse
43 %<*package>
44 %<package>\NeedsTeXFormat{LaTeX2e}[2019/01/01]
45 %</package>
46 %<*driver>
47 \ProvidesFile{curve2e.dtx}%
48 %</driver>
49 %<+package>\ProvidesPackage{curve2e}%
50 %<+readme>File README.txt for package curve2e
51 %<*package|readme>
52 [2024-11-13 v.2.6.0 Extension package for pict2e]
53 %</package|readme>
54 %<*driver>
55 \documentclass{ltxdoc}\errorcontextlines=100
56 \hfuzz 10pt
57 \usepackage[utf8]{inputenc}
58 \usepackage{lmodern,textcomp}
59 \usepackage{mflogo}
60 \usepackage{multicol, amsmath, fancyvrb, graphicx, verbatim, FramedSyntax, trace}
61 \usepackage{xcolor,curve2e}
62 \GetFileInfo{curve2e.dtx}
63 \title{The extension package \textsf{curve2e}}
64 \author{Claudio Beccari\thanks{E-mail: \texttt{claudio dot beccari at gmail dot com}}}
65 \date{Version \fileversion~--~Last revised \filedate.}
66 \providecommand*\diff{\mathop{}\!\mathrm{d}}
67 \renewcommand\meta[1]{{\normalfont\textlangle\textit{#1}\textrangle}}
68 \renewcommand\marg[1]{\texttt{\{\meta{#1}\}}}
69 \providecommand\Marg{}
70 \renewcommand\Marg[1]{\texttt{\{#1\}}}
71 \providecommand\oarg{}
72 \renewcommand\oarg[1]{\texttt{[\meta{#1}]}}
73 \providecommand\Oarg{}
74 \renewcommand\Oarg[1]{\texttt{[#1]}}
75 \providecommand\aarg{}
76 \renewcommand*\aarg[1]{\texttt{<\meta{#1}>}}
77 \providecommand\Aarg{}
78 \renewcommand\Aarg[1]{\texttt{<#1>}}
79 \providecommand\parg{}
80 \renewcommand\parg[1]{\texttt{(\meta{#1})}}
81 \providecommand\Parg{}
82 \renewcommand\Parg[1]{\texttt{(#1)}}
83 \providecommand\eTeX{}
84 \renewcommand\eTeX{\lower0.5ex\hbox{$\varepsilon\!$}\TeX}
85 \providecommand\pack{}
86 \renewcommand\pack[1]{{\normalfont\texttt{#1}}}
87
88 \def\LissajousCoefs#1,#2,#3,#4,#5,#6!{%
89 \edef\LAu{#1}\edef\LNu{#2}\edef\LFu{#3}%
90 \edef\LAd{#4}\edef\LNd{#5}\edef\LFd{#6}}
91
92 \def\LissajousCode#1#2{%
93 \edef\X{\fpeval{\LAu*cosd(\LNu*#1+\LFu)}}%
94 \edef\Y{\fpeval{\LAd*cosd(\LNd*#1+\LFd)}}%
95 \CopyVect\X,\Y to#2\ignorespaces}
96
97 \NewDocumentCommand\Lissajous{m o m}{%
98 \IfValueTF{#2}{\LissajousCoefs#2!\relax
99 \LissajousCode{#1}{#3}}%
100 {\ifcsname LAu\endcsname
101 \LissajousCode{#1}{#3}%
102 \else\PackageError{Lissajous}%
103 {I parametri di questa curva di Lissajous\MessageBreak
104 Non sono mai stati definiti}{Non faccio nulla}\fi}%
105 \ignorespaces}
106
107 \makeatletter
108
109 \NewDocumentCommand\Pall{O{1.5} R(){0,0}}{\put(#2){\circle*{#1}}}
110
111
112 \providecommand\setfontsize{}
113 \RenewDocumentCommand\setfontsize{O{1.2} m}{%
114 \fontsize{#2}{\fpeval{#1*#2}}\selectfont}
115
116 \newwrite\example@out
117 \ProvideDocumentEnvironment{Esempio}{ O{\footnotesize} D(){0.50}}
118 % All definitions and assignments are local
119 % #1 := Lates font size command or \setfontsize{<size>}
120 % %2 := \textwidth percentage for the code box; the complement, less the
121 % column gap for the resulting compiled code
122 % Syntax: \begin{Esempio}[<size command>](<code box percentage width>)
123 %
124 {\par\addvspace{3.0ex plus 0.8ex minus 0.5ex}\vskip -\parskip
125 %\def\Corpo{#1}
126 \dimendef\Wboxu=2570 \dimendef\Wboxd=2572
127 \Wboxu=#2\textwidth\relax
128 \Wboxd=\dimexpr\linewidth-\columnsep-\Wboxu\relax
129 \begingroup
130 \@bsphack
131 \immediate\openout\example@out\jobname-temp.tex
132 \let\do\@makeother\dospecials\catcode`\^^M\active
133 \def\verbatim@processline{%
134 \immediate\write\example@out{\the\verbatim@line}}%
135 \verbatim@start\relax}%
136 {\immediate\closeout\example@out\@esphack\endgroup
137 \begin{lrbox}{0}%
138 \begin{minipage}{\textwidth}%
139 \begin{minipage}{\Wboxu}%
140 #1\relax
141 \verbatiminput{\jobname-temp.tex}
142 \end{minipage}%
143 \hfill
144 \begin{minipage}{\Wboxd}\raggedleft
145 \input{\jobname-temp}%
146 \end{minipage}
147 \end{minipage}%
148 \end{lrbox}%
149
150 \medskip
151 \noindent\makebox[\textwidth]{\box0}%
152 \par%\addvspace{3.0ex plus 0.8ex minus 0.5ex}\vskip -\parskip
153 }
154
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156
157 \begin{document}\errorcontextlines=100
158 \maketitle
159 \columnseprule=0.4pt
160 \begin{multicols}{2}
161 \tableofcontents
162 \end{multicols}
163 \DocInput{curve2e.dtx}
164 \end{document}
165 %</driver>
166 % \fi
167 % \CheckSum{5663}
168 % \begin{abstract}
169 % This file documents the |curve2e| extension package to the
170 % |pict2e| bundle implementation; the latter was described by
171 % Lamport himself in the 1994 second edition of his \LaTeX\
172 % handbook.
173 %
174 % Please take notice that on April 2011 a new
175 % updated version of the package |pict2e| has been
176 % released that incorporates some of the commands
177 % defined in early versions of this package;
178 % apparently there are no conflicts, but only the
179 % advanced features of |curve2e| remain available
180 % for extending the above improved package.
181 %
182 % This extension redefines some commands and
183 % introduces some more drawing facilities that
184 % allow to draw circular arcs and arbitrary curves
185 % with the minimum of user intervention. This
186 % version is open to the contribution of other
187 % users as well as it may be incorporated in other
188 % people's packages. Please cite the original
189 % author and the chain of contributors.
190 % \end{abstract}
191 %
192 %
193 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 % \section{Introduction}
195 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 %
197 % Package \texttt{pict2e} was announced in issue 15 of
198 % \texttt{latexnews} around December 2003; it was specified
199 % that the new package would replace the dummy one that was
200 % been accompanying every release of \LaTeXe\ since its
201 % beginnings in 1994. The dummy package was just issuing an
202 % info message that simply announced the temporary
203 % unavailability of the real package.
204 %
205 % Eventually Gäßlein and Niepraschk implemented what Lamport
206 % himself had already documented in the second edition of his
207 % \LaTeX\ handbook, that is a \LaTeX\ package that contained
208 % the macros capable of removing all the limitations contained
209 % in the standard commands of the original \texttt{picture}
210 % environment; specifically what follows.
211 % \begin{enumerate}
212 % \item
213 % The line and vector slopes were limited to the ratios of
214 % relative prime one-digit integers of magnitude not exceeding 6
215 % for lines and 4 for vectors.
216 %^^A
217 % \item
218 % Filled and unfilled full circles were limited by the
219 % necessarily limited number of specific glyphs contained in the
220 % special \LaTeX\ \texttt{picture} fonts.
221 %^^A
222 % \item
223 % Quarter circles were also limited in their radii for the same
224 % reason.
225 %^^A
226 % \item
227 % Ovals (rectangles with rounded corners) could not be too
228 % small because of the unavailability of small radius quarter
229 % circles, nor could be too large, in the sense that after a
230 % certain radius the rounded corners remained the same and
231 % would not increase proportionally to the oval size.
232 %^^A
233 % \item
234 % Vector arrows had only one possible shape and matched the
235 % limited number of vector slopes.
236 %^^A
237 % \item
238 % For circles and inclined lines and vectors just two possible
239 % thicknesses were available.
240 % \end{enumerate}
241 %
242 % The package \texttt{pict2e} removes most if not all the above
243 % limitations.
244 % \begin{enumerate}
245 % \item
246 % Line and vector slopes are virtually unlimited; the only
247 % remaining limitation is that the direction coefficients must
248 % be three-digit integer numbers (but see below); they need not
249 % be relatively prime; with the 2009 upgrade even this
250 % limitation was removed and now slope coefficients can be any
251 % fractional number whose magnitude does not exceed 16\,384,
252 % the maximum dimension in points that \TeX\ can handle.
253 %^^A
254 % \item
255 % Filled and unfilled circles can be of any size.
256 %^^A
257 % \item
258 % Ovals can be designed with any specified corner curvature and
259 % there is virtually no limitation to such curvatures; of
260 % course corner radii should not exceed half the lower value
261 % between the base and the height of the oval.
262 %^^A
263 % \item
264 % There are two shapes for the arrow tips; the triangular one
265 % traditional with \LaTeX\ vectors, or the arrow tip with
266 % PostScript style.
267 %^^A
268 % \item
269 % The |\linethickness| command changes the thickness of all
270 % lines, straight, curved, vertical, horizontal, arrow tipped,
271 % et cetera.
272 % \end{enumerate}
273 %
274 % This specific extension package |curve2e| adds the following
275 % features.
276 % \begin{enumerate}
277 % \item
278 % Point coordinates my be specified in both cartesian and polar
279 % form: internally they are handled as cartesian coordinates,
280 % but users can specify their points also in polar form.
281 % In order to avoid confusion with other graphic packages,
282 % |curve2e| uses the usual comma separated couple \meta{$x,y$}
283 % of integer or fractional numbers for cartesian coordinates,
284 % and the colon separated pair \meta{$\theta$}:\meta{$\rho$}
285 % for polar coordinates (the angle preceding the radius).
286 % All graphic object commands accept polar or cartesian
287 % coordinates at the choice of users who may use for each
288 % object the formalism they prefer. Also the |put| and
289 % |\multiput| commands have been redefined so as to accept
290 % cartesian or polar coordinates. The same holds true for the
291 % low level |pict2e| commands \cs{moveto}, \cs{lineto}, and
292 % \cs{curveto}.
293 %
294 % Of course the user must pay attention to the meaning of
295 % cartesian vs.~polar coordinates. Both imply a displacement
296 % with respect to the actual origin of the axes. So when a
297 % circle is placed at coordinates $a,b$ with a normal |\put|
298 % command, the circle center is placed exactly is that point;
299 % with a normal |\put| command the same happens if coordinates
300 % $\alpha{:}\rho$ are specified. But if the |\put| command is
301 % nested into another |\put| command, the current origin of the
302 % axes is displaced — this is obvious and the purpose of
303 % nesting |\put| commands is exactly that. But if a segment is
304 % specified so that its ending point is at a specific distance
305 % and in a specific direction from its starting point, polar
306 % coordinates appear to be the most convenient to use; in this
307 % case, though, the origin of the axes becomes the starting
308 % point of the segment, therefore the segment might be drawn
309 % in a strange way. Attention has been paid to avoid such
310 % misinterpretation, but maybe some unusual situation may not
311 % have come to my mind; feedback is very welcome.
312 % Meanwhile pay attention when you use polar coordinates.
313 %^^A
314 %\item
315 % Most if not all cartesian coordinate pairs and polar pairs
316 % are treated as \emph{ordered pairs}, that is \emph{complex
317 % numbers}; in practice users do not notice any difference from
318 % what they were used to, but all the mathematical treatment to
319 % be applied to these entities is coded as complex number
320 % operations, since complex numbers may be viewed non only as
321 % ordered pairs, but also as vectors or as roto-amplification
322 % operators.
323 %^^A
324 % \item
325 % Commands for setting the line terminations were introduced;
326 % the user can chose between square or round caps; the default
327 % is set to round caps; now this feature is directly available
328 % with |pict2e|.
329 %^^A
330 % \item
331 % Commands for specifying the way two lines or curves join to
332 % one another.
333 % ^^A
334 % \item
335 % Originally the |\line| macro was redefined so as to allow
336 % large (up to three digits) integer direction coefficients,
337 % but maintaining the same syntax as in the original
338 % \texttt{picture} environment; now |pict2e| removes the
339 % integer number limitations and allows fractional values,
340 % initially implemented by |curve2e|, and then introduced
341 % directly in |pict2e|.
342 % ^^A
343 % \item
344 % A new macro |\Line| was originally defined by |curve2e| so as
345 % to avoid the need to specify the horizontal projection of
346 % inclined lines; now this functionality is available directly
347 % with |pict2e|; but this |curve2e| macro name now conflicts
348 % with |pict2e| 2009 version; therefore its name is changed to
349 % |\LIne| and supposedly it will not be used very often, if
350 % ever, by the end user (but it is used within this package
351 % macros).
352 % ^^A
353 % \item A new macro |\LINE| was defined in order to join two
354 % points specified with their coordinates; this is now the
355 % normal behaviour of the |\Line| macro of |pict2e| so that in
356 % this package |\LINE| is now renamed |\segment|; there is no
357 % need to use the |\put| command with this line specification.
358 % ^^A
359 % \item
360 % A new macro |\DashLine| (alias: |\Dline|) is defined in order
361 % to draw dashed lines joining any two given points; the dash
362 % length and gap (equal to one another) get specified through
363 % one of the macro arguments. The starting point may be
364 % specified in cartesian or polar form; the end point in
365 % cartesian format specifies the desired end point; while if
366 % the second point is in polar form it is meant
367 % \textcolor{red}{\emph{relative to the starting point}}, not
368 % as an absolute end point. See the examples further on.
369 % ^^A
370 % \item
371 % A similar new macro |\Dotline| is defined in order to draw
372 % dotted straight lines as a sequence of equally spaced dots,
373 % where the gap can be specified by the user; such straight
374 % line may have any inclination, as well as the above dashed
375 % lines. Polar coordinates for the second point have the same
376 % relative meaning as specified for the |\Dashline| macro.
377 % ^^A
378 % \item Similar macros are redefined for vectors; |\vector|
379 % redefines the original macro but with the vector slope
380 % limitations removed; |\Vector| gets specified with its two
381 % horizontal and vertical components in analogy with |\LIne|;
382 % |\VECTOR| joins two specified points (without using the
383 % |\put| command) with the arrow pointing to the second point.
384 %^^A
385 % \item
386 % A new macro |\polyline| for drawing polygonal lines is
387 % defined that accepts from two vertices up to an arbitrary
388 % (reasonably limited) number of them (available now also in
389 % |pict2e|); here it is redefined so as to allow an optional
390 % specification of the way segments for the polyline are joined
391 % to one another. Vertices may be specified with polar
392 % coordinates.
393 %^^A
394 % \item
395 % The |pict2e| |polygon| macro to draw closed polylines (in
396 % practice general polygons) has been redefined in such a way
397 % that it can accept the various vertices specified with polar
398 % coordinates. The |polygon*| macro produces a color filled
399 % polygon; the default color is black, but a different color
400 % may be specified with the usual |\color| command given within
401 % the same group where |\polygon*| is enclosed.
402 %^^A
403 % \item
404 % A new macro |\Arc| is defined in order to draw an arc with
405 % arbitrary radius and arbitrary aperture (angle amplitude);
406 % this amplitude is specified in sexagesimal degrees, not in
407 % radians; a similar functionality is now achieved with the
408 % |\arc| macro of |pict2e|, which provides also the starred
409 % version |\arc*| that fills up the interior of the generated
410 % circular arc with the current color.
411 % It must be noticed that the syntax is slightly different, so
412 % that it is reasonable that these commands, in spite of
413 % producing identical arcs, might be more comfortable with this
414 % or that syntax.
415 %^^A
416 % \item
417 % Two new macros |\VectorArc| and |\VectorARC| (alias
418 % |\VVectorArc|) are defined in order to draw circular arcs
419 % with an arrow at one or both ends.
420 %^^A
421 % \item
422 % A new macro |\Curve| is defined so as to draw arbitrary
423 % curved lines by means of cubic Bézier splines; the |\Curve|
424 % macro requires only the curve nodes and the directions of the
425 % tangents at each node. The starred version fills up the
426 % interior of the curve with the current color.
427 %^^A
428 % \item
429 % The above |\Curve| macro is recursive and it can draw an
430 % unlimited (reasonably limited) number of connected Bézier
431 % spline arcs with continuous tangents except for cusps; these
432 % arcs require only the specification of the tangent direction
433 % at the interpolation nodes. It is possible to use a lower
434 % level macro |\CbezierTo| that does the same but lets the user
435 % specify the control points of each arc; it is more difficult
436 % to use but it is more performant.
437 %^^A
438 % \item
439 % The basic macros used within the cumulative |\Curve| macro
440 % can be used individually in order to draw any curve, one
441 % cubic arc at the time; but they are intended for internal
442 % use, even if it is not prohibited to use them; by themselves
443 % such arcs are not different from those used by |Curve|, but
444 % the final command, |\FillCurve|, should be used in place of
445 % |\CurveFinish|, so as to fill up the closed path with
446 % the locally specified color; see the documentation
447 % |curve2e-manual.pdf| file. It is much more convenient to use
448 % the starred version of the |\Curve| macro.
449 % \end{enumerate}
450 %
451 % The |pict2e| package already defines macros such as
452 % |\moveto|, |\lineto|, |\curveto|, |\closepath|, |\fillpath|,
453 % and |\strokepath|; of course these macros can be used by the
454 % end user, and sometimes they perform better than the macros
455 % defined in this package, because the user has a better
456 % control on the position of each Bézier-spline control points,
457 % while here the control points are sort of rigid. It would be
458 % very useful to resort to the |hobby| package, but its macros
459 % are compatible with those of the |tikz| and |pgf| packages,
460 % not with |curve2e|; an interface should be created in order
461 % to deal with the |hobby| package, but this has not been done
462 % yet. In any case they are redefined so as to accept symbolic
463 % names for the point coordinates in both the cartesian and
464 % polar form.
465 %
466 % In order to make the necessary calculations many macros have
467 % been defined so as to use complex number arithmetics to
468 % manipulate point coordinates, directions (unit vectors, also
469 % known as `versors'), rotations and the like. In the first
470 % versions of this package the trigonometric functions were
471 % also defined in a way that the author believed to be more
472 % efficient than those defined by the |trig| package; in any
473 % case the macro names were sufficiently different to
474 % accommodate both definition sets in the same \LaTeX\ run.
475 % With the progress of the \LaTeX\,3 language, the |xfp|
476 % package functionalities have recently become available
477 % directly in the \LaTeXe\ kernel, by which any sort of
478 % calculations can be done with floating point decimal numbers;
479 % therefore the most common algebraic, irrational and
480 % transcendental functions can be computed in the background
481 % with the stable internal floating point facilities.
482 % We maintain some computation with complex
483 % number algebra, but use the |xfp| functionalities to
484 % implement them and to make other calculations. Most |xfp|
485 % code has been included into the \LaTeX\ kernel, so that most
486 % of this package functionality is already available without
487 % the need of loading that package. Loading is necessary only
488 % when a small set of special functionalities are needed, that
489 % have not made their way to the kernel.
490 %
491 % Many aspects of this extension could be fine tuned for better
492 % performance; many new commands could be defined in order to
493 % further extend this extension. If the new service macros are
494 % accepted by other \TeX\ and \LaTeX\ programmers, this version
495 % could become the start for a real extension of the |pict2e|
496 % package or even become a part of it. Actually some macros
497 % have already been included in the |pict2e| package. The
498 % |\Curve| algorithm, as said before, might be redefined so as
499 % to use the macros introduced by the |hobby| package, that
500 % implements for the |tikz| and |pgf| packages the same
501 % functionalities that John Hobby implemented for the \MF\ and
502 % \MP\ programs.
503 %
504 % For these reasons I suppose that every enhancement should be
505 % submitted to Niepraschk, who is the maintainer of
506 % \texttt{pict2e}; he is the only one who can decide whether or
507 % not to incorporate new macros in the |pict2e| package.
508 %
509 % \textbf{Warning}\quad{\color{red} In 2020 the \LaTeX\ Project
510 % Team upgraded the \LaTeX\ native |picture| environment so
511 % that all information concerning lengths (line and vector
512 % lengths, coordinates, et cetera) may be expressed with
513 % dimension expressions such as |0.71\textwidth|,
514 % |\parindent + 5mm|, |\circle{1ex}|, and so on. With such
515 % dimensional specifications, the information does not depend
516 % anymore on |\unitlength|; therefore such dimensional forms do
517 % not scale by changing the value of |\unitlength|. |pict2e| in
518 % 2020-09-30 was correspondingly upgraded to version~0.4b.
519 % Apparently such upgrades do not have any influence on
520 % |curve2e| workings, or, at least, when no explicit dimensions
521 % are used; this applies in particular when the |\AutoGrid| or
522 % the |GraphGrid| macros are used; also he coordinates
523 % processing should be done with real numbers, not with
524 % dimensions. Nevertheless feedback is welcome if some
525 % corrections are needed}.
526 %
527 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
528 % \section{Acknowledgements}
529 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
530 %
531 % I wish to express my deepest thanks to the various
532 % individuals who spotted some errors and notified them to me;
533 % Many, many thanks to all of them.
534
535 % Michel Goosens spotted some errors and very kindly submitted
536 % them to me so that I was able to correct them.
537 %
538 % Josef Tkadlec and the author collaborated extensively in
539 % order to make a better real long-division so as to get
540 % correctly the quotient fractional part and to avoid as much
541 % as possible any numeric overflow; many Josef's ideas are
542 % incorporated in the macro that was implemented in the
543 % previous versions of this package, although the macro used by
544 % Josef was slightly different. Both versions aim/aimed at a
545 % better accuracy and at widening the operand ranges. In this
546 % version we abandoned our long-division macro, and substituted
547 % it with the floating point division provided by the |xfp|
548 % package.
549 %
550 % Daniele Degiorgi spotted a fault in the kernel definition of
551 % |\linethickness| that heavily influenced also |curve2e|; see
552 % below in the code documentation part.
553 %
554 % Jin-Hwan Cho and Juho Lee suggested a small but crucial
555 % modification in order to have \texttt{curve2e} work smoothly
556 % also with XeTeX (XeLaTeX). Actually if |pict2e|,
557 % version 0.2x or later, dated 2009/08/05 or later, is being
558 % used, such modification is not necessary any more, but it's
559 % true that it became imperative when older versions were used.
560 %
561 % Some others users spotted other “features” that did not
562 % produce the desired results; they have been acknowledged by
563 % footnotes in correspondence with the corrections that were
564 % made thanks their feedback.
565 %
566 % \StopEventually{%
567 % \begin{thebibliography}{9}
568 % \bibitem{pict2e} Gäßlein H., Niepraschk R., and Tkadlec J.
569 % \emph{The \texttt{pict2e} package}, 2020, PDF documentation of
570 % \texttt{pict2e}; this package is part of any modern complete
571 % distribution of the \TeX\ system; it may be read by means of
572 % the line command \texttt{texdoc pict2e}. In case of a basic
573 % or partial system installation, the package may be installed
574 % by means of the specific facilities of the distribution.
575 % \end{thebibliography}
576 % }
577 %
578 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
579 % \section{Source code}
580 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
581 %
582 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
583 % \subsection{Some preliminary extensions to the \texttt{pict2e}
584 % package}
585 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
586 % The necessary preliminary code has already been introduced.
587 % Here we require the \texttt{color} and \texttt{graphicx}
588 % packages plus the \texttt{pict2e} one; for the latter we make
589 % sure that a sufficiently recent version is used. If you want
590 % to use package \texttt{xcolor}, load it \emph{after}
591 % \texttt{curve2e}.
592 %
593 % Here we load also the |xparse| and |xfp|
594 % packages because we use their functionalities;
595 % but we do load them only if they are not
596 % already loaded with or without options;
597 % nevertheless we warn the user who wants
598 % to load them explicitly: do this action before
599 % loading \texttt{curve2e}. The |xfp| package is
600 % absolutely required; if this package is not
601 % found in the \TeX\ system installation,
602 % loading of this new |curve2e| is aborted, and
603 % the previous version 1.61 is loaded in its
604 % place; the overall functionalities should not
605 % change much, but the functionalities of |xfp|
606 % are not available. Most of the functionalities of |xfp| and
607 % |xparse| packages are already included into the \LaTeX
608 % kernel; but there are some unusial features that have not
609 % been included and might be useful also for |curve3e|; so we
610 % load them and they will define only those unusual features.
611 %\iffalse
612 %<*package>
613 %\fi
614 % \begin{macrocode}
615 \IfFileExists{xfp.sty}{%
616 \RequirePackage{graphicx,color}
617 \RequirePackageWithOptions{pict2e}[2014/01/01]
618 \@ifl@aded{sty}{xparse}{}{\RequirePackage{xparse}}
619 \@ifl@aded{sty}{xfp}{}{\RequirePackage{xfp}}%
620 }{%
621 \RequirePackage{curve2e-v161}%
622 \PackageWarningNoLine{curve2e}{%
623 Package xfp is required, but apparently\MessageBreak%
624 such package cannot be found in this \MessageBreak%
625 TeX system installation\MessageBreak%
626 Either your installation is not complete \MessageBreak%
627 or it is older than 2018-10-17.\MessageBreak%
628 \MessageBreak%
629 ***************************************\MessageBreak%
630 Version 1.61 of curve2e has been loaded\MessageBreak%
631 instead of the current version \MessageBreak%
632 ***************************************\MessageBreak}%
633 \endinput
634 }
635 % \end{macrocode}
636 % Since we already loaded package |xfp| or at
637 % least we explicitly load it in our preamble, we
638 % add, if not already defined by the package,
639 % a few new commands that allow to make floating
640 % point tests, and two “while”
641 % cycles\footnote{Thanks to Brian Dunn who
642 % spotted a bug in the previous 2.0.x version
643 % definitions.}. There are also two integer operations:
644 % |\Mod| to compute the expression $m \mathrm{mod} n$, and
645 % |\Ifodd| to test if an integer is odd: it mimics the native
646 % command |\ifodd|, but it uses a robust construction, instead
647 % of the original construction |\ifodd ...\else...\fi|.
648 % There is also the string comparison test; the first two
649 % arguments are the explicit or implicit strings to compare;
650 % the last two arguments are the “true” and “false” codes.
651 % \begin{macrocode}
652 %
653 \ExplSyntaxOn
654 \AtBeginDocument{%
655 \ProvideExpandableDocumentCommand\fptest{m m m}{%
656 \fp_compare:nTF{#1}{#2}{#3}}
657 \ProvideExpandableDocumentCommand\fptestT{m m}{%
658 \fp_compare:nTF{#1}{#2}{\relax}}
659 \ProvideExpandableDocumentCommand\fptestF{m m}{%
660 \fp_compare:nTF{#1}{\relax}{#2}}
661 %
662 \ProvideExpandableDocumentCommand\fpdowhile{m m}{%
663 \fp_do_while:nn{#1}{#2}}
664 \ProvideExpandableDocumentCommand\fpwhiledo{m m}{%
665 \fp_while_do:nn{#1}{#2}}
666 \ProvideExpandableDocumentCommand\Modulo{m m}{%
667 \inteval{\int_mod:nn{#1}{#2}}}
668 \ProvideExpandableDocumentCommand\Ifodd{m m m}{%
669 \int_if_odd:nTF{#1}{#2}{#3}}
670 \ProvideExpandableDocumentCommand\Ifequal{m m m m}%
671 {\str_if_eq:eeTF{#1}{#2}{#3}{#4}}
672 }
673 \ExplSyntaxOff
674
675 % \end{macrocode}
676 % The while-do cycles differ in the order of what they do; see
677 % the |interface3.pdf| documentation file for details.
678 %
679 % The next macros are just for debugging. With the
680 % \texttt{trace} package it would probably be better to define
681 % other macros, but this is not for the users, but for the
682 % developers.
683 % \begin{macrocode}
684 \def\TRON{\tracingcommands\tw@ \tracingmacros\tw@}%
685 \def\TROF{\tracingcommands\z@ \tracingmacros\z@}%
686 % \end{macrocode}
687 %
688 % Next we define some new dimension registers that will be used
689 % by the subsequent macros; should they be already defined,
690 % there will not be any redefinition; nevertheless the macros
691 % should be sufficiently protected so as to avoid overwriting
692 % register values loaded by other macro packages.
693 % \begin{macrocode}
694 \newif\ifCV@polare \let\ifCV@polare\iffalse
695 \ifx\undefined\@tdA \newdimen\@tdA \fi
696 \ifx\undefined\@tdB \newdimen\@tdB \fi
697 \ifx\undefined\@tdC \newdimen\@tdC \fi
698 \ifx\undefined\@tdD \newdimen\@tdD \fi
699 \ifx\undefined\@tdE \newdimen\@tdE \fi
700 \ifx\undefined\@tdF \newdimen\@tdF \fi
701 \ifx\undefined\defaultlinewidth \newdimen\defaultlinewidth \fi
702 % \end{macrocode}
703 %
704 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
705 % \subsection{Line thickness macros}
706 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
707 % It is better to define a macro for setting a different value
708 % for the line and curve thicknesses; the `|\defaultlinewidth|
709 % should contain the equivalent of |\@wholewidth|, that is the
710 % thickness of thick lines; thin lines are half as thick; so
711 % when the default line thickness is specified to, say, 1pt,
712 % thick lines will be 1pt thick and thin lines will be 0.5pt
713 % thick. The default whole width of thick lines is 0,8pt,
714 % but this is specified in the kernel of \LaTeX\ and\slash or
715 % in \texttt{pict2e}. On the opposite it is necessary to
716 % redefine |\linethickness| because the \LaTeX\ kernel global
717 % definition does not hide the space after the closed brace
718 % when you enter something such as |\linethickness{1mm}|
719 % followed by a space or a new line.\footnote{Thanks to Daniele
720 % Degiorgi \texttt{[email protected]}).
721 % This feature should have been eliminated from the \LaTeXe\
722 % <2020.02.02> patch level 4 update. This glitch has been
723 % eliminated according to the LaTeX Newsletter Nr.~32.}
724 % \begin{macrocode}
725 \gdef\linethickness#1{%
726 \@wholewidth#1\@halfwidth.5\@wholewidth\ignorespaces}%
727 \newcommand\defaultlinethickness[1]{\defaultlinewidth=#1\relax
728 \def\thicklines{\linethickness{\defaultlinewidth}}%
729 \def\thinlines{\linethickness{.5\defaultlinewidth}}\thinlines
730 \ignorespaces}%
731 % \end{macrocode}
732 %
733 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
734 % \subsection{Improved line and vector macros}
735 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
736 % The macro |\LIne| allows to draw a line with arbitrary
737 % inclination as if it was a polygonal with just two vertices;
738 % actually it joins the canvas coordinate origin with the
739 % specified relative coordinate; therefore this object must be
740 % set in place by means of a |\put| command.
741 % Since its starting point is always at a relative 0,0
742 % coordinate point inside the box created with |\put|, the two
743 % arguments define the horizontal and the vertical component respectively.
744 % \begin{macrocode}
745 \def\LIne(#1){{\GetCoord(#1)\@tX\@tY
746 \moveto(0,0)
747 \pIIe@lineto{\@tX\unitlength}{\@tY\unitlength}\strokepath}\ignorespaces
748 }%
749 % \end{macrocode}
750 %
751 % A similar macro |\segment| operates between two explicit
752 % points with absolute coordinates, instead of relative to the
753 % position specified by a |\put| command; it resorts to the
754 % |\polyline| macro that shall be defined in a while. The
755 % |\@killglue| command might be unnecessary, but it does not
756 % harm; it eliminates any explicit or implicit spacing that
757 % might precede this command.
758 % \begin{macrocode}
759 \def\segment(#1)(#2){\@killglue\polyline(#1)(#2)}%
760 % \end{macrocode}
761 % By passing its ending points coordinates to the |\polyline|
762 % macro, both macro arguments are a pair of coordinates, not
763 % their components; in other words, if $P_1=(x_1, y_2)$ and
764 % $P_2=(x_2, y_2)$, then the first argument is the couple $x_1, y_1$ and likewise the second argument is $x_2, y_2$.
765 % Notice that since |\polyline| accepts also the vertex
766 % coordinates in polar form, also |\segment| accepts the polar
767 % form. Please remember that the decimal separator is the
768 % decimal \emph{point}, while the \emph{comma} acts as cartesian
769 % coordinate separator. This recommendation is particularly
770 % important for non-anglophone users, since in all other
771 % languages the decimal separator is or must by a comma.
772 %
773 % The |\line| macro is redefined by making use of a division
774 % routine performed in floating point arithmetics; for this
775 % reason the \LaTeX\ kernel and the overall \TeX\ system
776 % installation must be as recent as the release date of the
777 % \texttt{xfp} package, i.e. 2018-10-17. The floating point
778 % division macro receives in input two fractional numbers and
779 % yields on output their fractional ratio. Notice that this
780 % command |\line| should follow the same syntax as the
781 % original pre~1994 \LaTeX\ version; but the new definition
782 % accepts the direction coefficients also in polar mode; that
783 % is, instead of specifying a slope of $30^\circ$ with its
784 % actual sine and cosine values (or values proportional to such
785 % functions), for example, |(0.5,0.866025)|, you may specify it
786 % as |(30:1)|, i.e. as a unit vector with the required slope
787 % of $30^\circ$.
788 %
789 % The beginning of the macro definition is the same as that of \texttt{pict2e}:
790 % \begin{macrocode}
791 \def\line(#1)#2{\begingroup
792 \@linelen #2\unitlength
793 \ifdim\@linelen<\z@\@badlinearg\else
794 % \end{macrocode}
795 % but as soon as it is verified that the line length is not
796 % negative, things change remarkably; in facts the machinery for
797 % complex numbers is invoked. This makes the code much simpler,
798 % not necessarily more efficient; nevertheless |\DirOfVect|
799 % takes the only macro argument (that actually contains a comma
800 % separated pair of fractional numbers) and copies it to
801 % |\Dir@line| (an arbitrarily named control sequence) after
802 % re-normalizing to unit magnitude; this is passed to |GetCoord|
803 % that separates the two components into the control sequences
804 % |\d@mX| and |\d@mY|; these in turn are the values that are
805 % actually operated upon by the subsequent commands.
806 % \begin{macrocode}
807 \expandafter\DirOfVect#1to\Dir@line
808 \GetCoord(\Dir@line)\d@mX\d@mY
809 % \end{macrocode}
810 % The normalised vector direction is actually formed with the
811 % directing cosines of the line direction; since the line length
812 % is actually the horizontal component for non vertical lines,
813 % it is necessary to compute the actual line length for non
814 % vertical lines by dividing the given length by the magnitude
815 % of the horizontal cosine |\d@mX|, and the line length is
816 % accordingly scaled:
817 % \begin{macrocode}
818 \ifdim\d@mX\p@=\z@\else
819 \edef\sc@lelen{\fpeval{1 / abs(\d@mX)}}\relax
820 \@linelen=\sc@lelen\@linelen
821 \fi
822 % \end{macrocode}
823 % Of course, if the line is vertical this division must not take
824 % place. Finally the \texttt{moveto}, \texttt{lineto} and
825 % \texttt{stroke} language keywords are invoked by means of the
826 % internal \texttt{pict2e} commands in order to draw the line.
827 % Notice that even vertical lines are drawn with the PDF
828 % language commands instead of resorting to the DVI low level
829 % language that was used in both \texttt{pict2e} and the
830 % original (pre 1994) \texttt{picture} commands; it had a
831 % meaning in the old times, but it certainly does not have any
832 % nowadays, since lines are drawn by the driver that produces
833 % the output in a human visible document form, not by \TeX\ the
834 % program.
835 % \begin{macrocode}
836 \moveto(0,0)\pIIe@lineto{\d@mX\@linelen}{\d@mY\@linelen}%
837 \strokepath
838 \fi
839 \endgroup\ignorespaces}%
840 % \end{macrocode}
841 % The new definition of the command |\line|, besides the ease
842 % with which is readable, does not do different things from the
843 % definition of |pict2e| 2009, even if it did perform in a
844 % better way compared to the 2004 version that was limited to
845 % integer direction coefficients up to 999 in magnitude.
846 % Moreover this |curve2e| version accepts polar coordinates as
847 % slope pairs, making it much simpler to draw lines with
848 % specific slopes.
849 %
850 % It is necessary to redefine the low level macros \cs{moveto},
851 % \cs{lineto}, and \cs{curveto}, because their original
852 % definitions accept only cartesian coordinates. We proceed the
853 % same as for the \cs{put} command.
854 % \begin{macrocode}
855 \let\originalmoveto\moveto
856 \let\originallineto\lineto
857 \let\originalcurveto\curveto
858
859 \def\moveto(#1){\GetCoord(#1)\MTx\MTy
860 \originalmoveto(\MTx,\MTy)\ignorespaces}
861 \def\lineto(#1){\GetCoord(#1)\LTx\LTy
862 \originallineto(\LTx,\LTy)\ignorespaces}
863 \def\curveto(#1)(#2)(#3){\GetCoord(#1)\CTpx\CTpy
864 \GetCoord(#2)\CTsx\CTsy\GetCoord(#3)\CTx\CTy
865 \originalcurveto(\CTpx,\CTpy)(\CTsx,\CTsy)(\CTx,\CTy)\ignorespaces}
866 % \end{macrocode}
867
868 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
869 % \subsection{Dashed and dotted lines}
870 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
871 % Dashed and dotted lines are very useful in technical drawings;
872 % here we introduce two macros that help drawing them in the
873 % proper way; besides the obvious difference between the use of
874 % dashes or dots, they may refer in a different way to the end
875 % points that must be specified to the various macros.
876 %
877 % The coordinates of the first point $P_1$, where le line
878 % starts, are always referred to the origin of the coordinate
879 % axes; the end point $P_2$ coordinates are referred to the
880 % origin of the axes if in cartesian form, while with the polar
881 % form they are referred to $P_1$; both coordinate types have
882 % their usefulness: see the documentation |curve2e-manual.pdf|
883 % file.
884 %
885 % The above mentioned macros create dashed lines between two
886 % given points, with a dash length that must be specified, or
887 % dotted lines, with a dot gap that must be specified; actually
888 % the specified dash length or dot gap is a desired one; the
889 % actual length or gap is computed by integer division between
890 % the distance of the given points and the desired dash length
891 % or dot gap; when dashes are involved, this integer is tested
892 % in order to see if it is an odd number; if it's not,
893 % it is increased by unity. Then the actual dash length or dot
894 % gap is obtained by dividing the above distance by this number.
895 %
896 % Another vector $P_2-P_1$ is created by dividing it by this
897 % number; then, when dashes are involved, it is multiplied by
898 % two in order to have the increment from one dash to the next;
899 % finally the number of patterns is obtained by integer division
900 % of this number by 2 and increasing it by~1. Since the whole
901 % dashed or dotted line is put in position by an internal |\put|
902 % command, is is not necessary to enclose the definitions within
903 % groups, because they remain internal to the |\put| argument
904 % box.
905 %
906 % Figure~6 of the |curve2e-manual.pdf| user manual shows the
907 % effect of the slight changing of the dash length in order to
908 % maintain \emph{approximately} the same dash-space pattern
909 % along the line, irrespective of the line length. The syntax is
910 % the following:
911 % \begin{Sintassi}
912 % \cs{Dashline}\parg{first point}\parg{second point}\marg{dash length}
913 % \end{Sintassi}
914 % where \meta{first point} contains the coordinates of the
915 % starting point and \meta{second point} the absolute
916 % (cartesian) or relative (polar) coordinates of the ending
917 % point; of course the \meta{dash length}, which equals the dash
918 % gap, is mandatory. An optional asterisk is used to be back
919 % compatible with previous implementations but its use is now
920 % superfluous; with the previous implementation of the code, in
921 % facts, if coordinates were specified in polar form, without
922 % the optional asterisk the dashed line was misplaced, while if
923 % the asterisk was specified, the whole object was put in the
924 % proper position. With this new implementation, both the
925 % cartesian and polar coordinates always play the role they are
926 % supposed to play independently from the asterisk. The
927 % |\IsPolar| macro is introduced to analyse the coordinate type
928 % used for the second argument, and uses such second argument
929 % accordingly.
930 % \begin{macrocode}
931 \def\IsPolar#1:#2?{\def\@TempOne{#2}\unless\ifx\@TempOne\empty
932 \expandafter\@firstoftwo\else
933 \expandafter\@secondoftwo\fi}
934
935 \ifx\Dashline\undefined
936 \def\Dashline{\@ifstar{\Dashline@}{\Dashline@}}% bckwd compatibility
937 \let\Dline\Dashline
938
939 \def\Dashline@(#1)(#2)#3{\put(#1){%
940 \GetCoord(#1)\@tA\@tB \MakeVectorFrom\@tA\@tB to\V@ttA
941 \GetCoord(#2)\@tA\@tB \MakeVectorFrom\@tA\@tB to\V@ttB
942 \IsPolar#2:?{% Polar
943 \Dashline@@(0,0)(\V@ttB){#3}}%
944 {% Cartesian
945 \SubVect\V@ttA from\V@ttB to\V@ttC
946 \Dashline@@(0,0)(\V@ttC){#3}%
947 }
948 }}
949
950 \def\Dashline@@(#1)(#2)#3{%
951 \countdef\NumA3254\countdef\NumB3252\relax
952 \GetCoord(#1)\@tA\@tB \MakeVectorFrom\@tA\@tB to\V@ttA
953 \GetCoord(#2)\@tA\@tB \MakeVectorFrom\@tA\@tB to\V@ttB
954 \SubVect\V@ttA from\V@ttB to\V@ttC
955 \ModOfVect\V@ttC to\DlineMod
956 \DivideFN\DlineMod by#3 to\NumD
957 \NumA=\fpeval{trunc(\NumD,0)}\relax
958 \unless\ifodd\NumA\advance\NumA\@ne\fi
959 \NumB=\NumA \divide\NumB\tw@
960 \DividE\DlineMod\p@ by\NumA\p@ to\D@shMod
961 \DividE\p@ by\NumA\p@ to \@tempa
962 \Multvect{\V@ttC}{\@tempa,0}\V@ttB
963 \Multvect{\V@ttB}{2,0}\V@ttC
964 \advance\NumB\@ne
965 \put(\V@ttA){\multiput(0,0)(\V@ttC){\NumB}{\LIne(\V@ttB)}}
966 \ignorespaces}
967 \fi
968 % \end{macrocode}
969 %
970 % A simpler |\Dotline| macro draws a dotted line between two
971 % given points; the dots are rather small, therefore the inter
972 % dot distance is computed in such a way as to have the first
973 % and the last dot at the exact position of the dotted-line
974 % end-points; again the specified dot distance is nominal in
975 % the sense that it is recalculated in such a way that the
976 % first and last dots coincide with the line end points.
977 % Again if the second point coordinates are in polar form they
978 % are considered as relative to the first point. Since the dots
979 % must emerge from the background of the drawing they should
980 % not be too small: they must be seen; therefore their diameter
981 % cannot be tied to the unit length of the particular drawing,
982 % but must have at visible size; by default it is set to
983 % $0.5\,\mathrm{mm}$ (about 20 mills, in US units) but through
984 % an optional argument to the macro, it may be set to any
985 % desired size; remember that 1\,pt is about one third of a
986 % millimetre; sometimes it might be too small; 1\,mm is a very
987 % black dot, therefore users must pay attention when they
988 % specify the dot diameter, so as not to exaggerate in either
989 % direction. The syntax is as follows:
990 %\begin{Sintassi}
991 %\cs{Dotline}\parg{start point}\parg{end point}\marg{dot distance}\oarg{diameter}
992 %\end{Sintassi}
993 % \begin{macrocode}
994 \ifx\Dotline\undefined
995 \providecommand\Dotline{}
996 \RenewDocumentCommand\Dotline{R(){0,0} R(){1,0} m O{1mm}}{%
997 \put(#1){\edef\Diam{\fpeval{{#4}/\unitlength}}%
998 \IsPolar#2:?{\CopyVect#2to\DirDot}%
999 {\SubVect#1from#2to\DirDot}%
1000 \countdef\NumA=3254\relax
1001 \ModAndAngleOfVect\DirDot to\ModDirDot and\AngDirDot
1002 \edef\NumA{\fpeval{trunc(\ModDirDot/{#3},0)}}%
1003 \edef\ModDirDot{\fpeval{\ModDirDot/\NumA}}%
1004 \multiput(0,0)(\AngDirDot:\ModDirDot){\inteval{\NumA+1}}%
1005 {\makebox(0,0){\circle*{\Diam}}}}\ignorespaces}
1006 \fi
1007 % \end{macrocode}
1008 %
1009 % Notice that vectors as complex numbers in their cartesian
1010 % and polar forms always represent a point position referred to
1011 % a local origin of the axes; this is why in figures~6 and~7
1012 % of the user manual the dashed and dotted lines that start
1013 % from the lower right corner of the graph grid, and that use
1014 % polar coordinates, are put in their correct position thanks
1015 % to the different behaviour obtained with the |\IsPolar|
1016 % macro.
1017 %
1018 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1019 % \subsection{Coordinate handling}
1020 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1021 % The new macro |\GetCoord| splits a vector (or complex
1022 % number) specification into its components; in particular it
1023 % distinguishes the polar from the cartesian form of the
1024 % coordinates. The latter have the usual syntax
1025 % \meta{x\texttt{,}y}, while the former have the syntax
1026 % \meta{angle\texttt{:}radius}. The |\put| and |\multiput|
1027 % commands are redefined to accept the same syntax; the whole
1028 % work is done by |\SplitNod@| and its subsidiaries.
1029 %
1030 % Notice that package |eso-pic| uses |picture| macros in its
1031 % definitions, but its original macro |\LenToUnit| is
1032 % incompatible with this |\GetCoord| macro; its function is
1033 % to translate real lengths into coefficients to be used as
1034 % multipliers of the current |\unitlength|; in case that the
1035 % |eso-pic| had been loaded, at the |\begin{document}|
1036 % execution, the |eso-pic| macro is redefined using the
1037 % e-\TeX\ commands so as to make it compatible with these
1038 % local macros.\footnote{Thanks to Franz-Joseph Berthold who
1039 % was so kind to spot the bug.}
1040 % \begin{macrocode}
1041 \AtBeginDocument{\@ifpackageloaded{eso-pic}{%
1042 \renewcommand\LenToUnit[1]{\strip@pt\dimexpr#1*\p@/\unitlength}}{}}%
1043 % \end{macrocode}
1044 % The above redefinition is delayed at |\AtBeginDocument| in
1045 % order to have the possibility to check if the |eso-pic|
1046 % package had actually been loaded. Nevertheless the code is
1047 % defined here just because the original |eso-pic| macro was
1048 % interfering with the algorithms of coordinate handling.
1049 %
1050 % But let us come to the real subject of this section. We
1051 % define a |\GettCoord| macro that passes control to the
1052 % service macro with the expanded arguments; expanding
1053 % arguments allows to use macros to named points, instead of
1054 % explicit coordinates; with this version of |curve2e| this
1055 % facility is not fully exploited, but a creative user can
1056 % use this feature. Notice the usual trick to use a dummy
1057 % macro that is defined within a group with expanded
1058 % arguments, but where the group is closed by the macro
1059 % itself, so that no traces remain behind after its
1060 % expansion.
1061 % \begin{macrocode}
1062 \def\GetCoord(#1)#2#3{\let\ifCV@polare\iffalse
1063 \bgroup\edef\x{\egroup
1064 \noexpand\IsPolar#1:?}\x
1065 {% Polar
1066 \let\ifCV@polare\iftrue
1067 \bgroup\edef\x{\egroup\noexpand\SplitPolar(#1)}\x\SCt@X\SCt@Y}%
1068 {% Cartesian
1069 \bgroup\edef\x{\egroup\noexpand\SplitCartesian(#1)}\x\SCt@X\SCt@Y}%
1070 \edef#2{\SCt@X}\edef#3{\SCt@Y}\ignorespaces}
1071
1072 \def\SplitPolar(#1:#2)#3#4{%
1073 \edef#3{\fpeval{#2 * cosd#1}}\edef#4{\fpeval{#2 * sind#1}}}
1074
1075 \def\SplitCartesian(#1,#2)#3#4{\edef#3{#1}\edef#4{#2}}
1076
1077 % \end{macrocode}
1078 % The macro that detects the form of the coordinates is
1079 % |\IsPolar|; it examines the parameter syntax in order to
1080 % see if it contains a colon; it has already been used with
1081 % the definition of dashed and dotted lines.
1082 %
1083 % In order to accept polar coordinates with |\put| and
1084 % |\multiput| we resort to using |\GetCoord|; therefore the
1085 % redefinition of |\put| is very simple because it suffices
1086 % to save the original meaning of that macro and redefine the
1087 % new one in terms of the old one.
1088 % \begin{macrocode}
1089 \let\originalput\put
1090 \def\put(#1){\bgroup\GetCoord(#1)\@tX\@tY
1091 \edef\x{\noexpand\egroup\noexpand\originalput(\@tX,\@tY)}\x}
1092 % \end{macrocode}
1093 % For |\multiput| it is more complicated, because the
1094 % increments from one position to the next cannot be done
1095 % efficiently because the increments in the original
1096 % definition are executed within boxes, therefore any macro
1097 % instruction inside these boxes is lost. It is a good
1098 % occasion to modify the |\multiput| definition by means of
1099 % the advanced macro definitions provided by package
1100 % |xparse|; we can add also some error messages for avoiding
1101 % doing anything when some mandatory parameters are either
1102 % missing or empty, or do not contain anything different
1103 % from an ordered pair or a polar form. We add also an
1104 % optional argument to handle the increments outside the
1105 % boxes.
1106 % The new macro has the following syntax:\\[2ex]
1107 % \mbox{\small\cs{multiput}\oarg{shift}\parg{initial}\texttt{(\meta{increment})}\marg{number}\marg{object}\oarg{handler}}\\[2ex]
1108 % where the optional \meta{shift} is used to displace to
1109 % whole set of \meta{object}s from their original position;
1110 % \meta{initial} contains the cartesian or polar coordinates
1111 % of the initial point; \meta{increment} contains the
1112 % cartesian or polar increment for the coordinates to be used
1113 % from the second position to the last; \meta{number} il the
1114 % total number of \meta{object}s to be drawn; \meta{object}
1115 % is the object to be put in position at each cycle
1116 % repetition; the optional \meta{handler} may be used to
1117 % control the current values of the horizontal and vertical
1118 % increments.
1119 % The new definition contains two |\put| commands where the
1120 % second is nested within a while-loop which, in turn, is
1121 % within the argument of the first |\put| command. Basically
1122 % it is the same idea that the original macros, but now the
1123 % increments are computed within the while loop, but outside
1124 % the argument of the inner |\put| command. If the optional
1125 % \meta{handler} is specified the increments are computed
1126 % from the macros specified by the user. Another new feature:
1127 % the fourth argument, that contains the number of objects to
1128 % be put in place, may be an integer expression such as for
1129 % example |3*\N+1|.
1130 %
1131 % The two increments components inside the optional argument
1132 % may be set by means of mathematical expressions operated
1133 % upon by the |\fpeval| function given by the |\xfp| package
1134 % already loaded by |curve2e|. Of course it is the user
1135 % responsibility to pay attention to the scales of the two
1136 % axes and to write meaningful expressions; the figure and
1137 % code shown in the user manual of this package displays some
1138 % examples: see the documentation |curve2e-manual.pdf| file.
1139 % \begin{macrocode}
1140 \RenewDocumentCommand{\multiput}{O{0,0} d() d() m m o }{%
1141 \IfNoValueTF{#2}{\PackageError{curve2e}%
1142 {\string\multiput\space initial point coordinates missing}%
1143 {Nothing done}
1144 }%
1145 {\IfNoValueTF{#3}{\PackageError{curve2e}
1146 {\string\multiput\space Increment components missing}%
1147 {Nothing done}
1148 }%
1149 {\put(#1){\let\c@multicnt\@multicnt
1150 \CopyVect #2 to \R
1151 \CopyVect#3 to\D
1152 \@multicnt=\inteval{#4}\relax
1153 \@whilenum \@multicnt > \z@\do{%
1154 \put(\R){#5}%
1155 \IfValueTF{#6}{#6}{\AddVect#3 and\R to \R}%
1156 \advance\@multicnt\m@ne
1157 }%
1158 }%
1159 }%
1160 }\ignorespaces
1161 }
1162 % \end{macrocode}
1163 % And here it is the new |\xmultiput| command; remember: the
1164 % internal cycling \TeX\ counter |\@multicnt| is now accessible
1165 % with the name |multicnt| as if it was a \LaTeX\ counter, in
1166 % particular the user can access its contents with a command
1167 % such as |\value{multicnt}|. Such counter is \emph{stepped up}
1168 % at each cycle, instead of being \emph{stepped down} as in the
1169 % original |\multiput| command. The code is not so different
1170 % from the one used for the new version of |\multiput|,
1171 % but it appears more efficient and its code more easily
1172 % readable.
1173 % \begin{macrocode}
1174 \NewDocumentCommand{\xmultiput}{O{0,0} d() d() m m o }{%
1175 \IfNoValueTF{#2}{\PackageError{curve2e}{%
1176 \string\Xmultiput\space initial point coordinates missing}%
1177 {Nothing done}}%
1178 {\IfNoValueTF{#3}{\PackageError{curve2e}{%
1179 \string\Xmultiput\space Increment components missing}%
1180 {Nothing done}}%
1181 {\put(#1)%
1182 {\let\c@multicnt\@multicnt
1183 \CopyVect #2 to \R
1184 \CopyVect #3 to \D
1185 \@multicnt=\@ne
1186 \fpdowhile{\value{multicnt} < \inteval{#4+1}}% Test
1187 {%
1188 \put(\R){#5}
1189 \IfValueTF{#6}{#6}{%
1190 \AddVect#3 and\R to \R}
1191 \advance\@multicnt\@ne
1192 }
1193 }
1194 }}\ignorespaces
1195 }
1196 % \end{macrocode}
1197 % Notice that the internal macros |\R| and |\D|, (respectively
1198 % the current point coordinates, in form of a complex number,
1199 % where to put the \meta{object}, and the current displacement
1200 % to find the next point) are accessible to the user both in
1201 % the \meta{object} argument field and the \meta{handler}
1202 % argument field. The code used in figure~18 of the user manual
1203 % shows how to create the hour marks of a clock together with
1204 % the rotated hour roman numerals.
1205 %
1206 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1207 % \subsection{Vectors}
1208 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1209 % The redefinitions and the new definitions for vectors are a
1210 % little more complicated than with segments, because each
1211 % vector is drawn as a filled contour; the original
1212 % \texttt{pict2e} 2004 macro checked if the slopes are
1213 % corresponding to the limitations specified by Lamport
1214 % (integer three digit signed numbers) and sets up a
1215 % transformation in order to make it possible to draw each
1216 % vector as an horizontal left-to-right arrow and then to
1217 % rotate it by its angle about its tail point; with |pict2e|
1218 % 2009, possibly this redefinition of |\vector| is not
1219 % necessary, but we do it as well and for the same reasons we
1220 % had for redefining |\line|; actually there are two macros for
1221 % tracing the contours that are eventually filled by the
1222 % principal macro; each contour macro draws the vector with a
1223 % \LaTeX\ or a PostScript styled arrow tip whose parameters are
1224 % specified by default or may be taken from the parameters
1225 % taken from the |PSTricks| package if this one is loaded
1226 % before |pict2e|; in any case we did not change the contour
1227 % drawing macros because if they are modified the same
1228 % modification is passed on to the arrows drawn with the
1229 % |curve2e| package redefinitions.
1230 %
1231 % Because of these features the new macros are different from
1232 % those used for straight lines.
1233 %
1234 % We start with the redefinition of |\vector| and we use the
1235 % machinery for vectors (as complex numbers) we used for
1236 % |\line|. The actual point is to let |\vector| accept the
1237 % slope parameters also in polar form.
1238 % Therefore it suffices to save the original definition of
1239 % |\vector| as defined in |pict2e| and and use it as a fallback
1240 % after redefining |\vector| in a “vector” format.\footnote{The
1241 % previous version 2.2.9 of this package contained a glitch
1242 % that was visible only with line widths larger than 1.5\.pt. I
1243 % thank very much Ashish Kumar Das who spotted this glitch and
1244 % kindly informed me.}
1245 % \begin{macrocode}
1246 \let\original@vector\vector
1247 \def\vector(#1)#2{%
1248 \begingroup
1249 \GetCoord(#1)\d@mX\d@mY
1250 \original@vector(\d@mX,\d@mY){\fpeval{round(abs(#2),6)}}%
1251 \endgroup}%
1252 % \end{macrocode}
1253 %
1254 % We define the macro that does not require the specification
1255 % of the length or the $l_x$ length component; the way the new
1256 % |\vector| macro works does not actually require this
1257 % specification, because \TeX\ can compute the vector length,
1258 % provided the two direction components are exactly the
1259 % horizontal and vertical vector components. If the horizontal
1260 % component is zero, the actual length must be specified as
1261 % the vertical component. The object defined with |\Vector|,
1262 % as well as |\vector|, must be put in place by means of a
1263 % |\put| command.
1264 % \begin{macrocode}
1265 \def\Vector(#1){{%
1266 \GetCoord(#1)\@tX\@tY
1267 \ifdim\@tX\p@=\z@
1268 \vector(\@tX,\@tY){\@tY}%
1269 \else
1270 \vector(\@tX,\@tY){\@tX}%
1271 \fi}}
1272 % \end{macrocode}
1273 %
1274 % On the opposite the next macro specifies a vector by means of
1275 % the coordinates of its end points; the first point is where
1276 % the vector starts, and the second point is the arrow tip
1277 % side. We need the difference of these two coordinates,
1278 % because it represents the actual vector.
1279 % \begin{macrocode}
1280 \def\VECTOR(#1)(#2){\begingroup
1281 \SubVect#1from#2to\@tempa
1282 \expandafter\put\expandafter(#1){\expandafter\Vector\expandafter(\@tempa)}%
1283 \endgroup\ignorespaces}
1284 % \end{macrocode}
1285 %
1286 % The double tipped vector is built on the |\VECTOR| macro by
1287 % simply drawing two vectors from the middle point of the
1288 % double tipped vector.
1289 % \begin{macrocode}
1290 \def\VVECTOR(#1)(#2){{\SubVect#1from#2to\@tempb
1291 \ScaleVect\@tempb by0.5to\@tempb
1292 \AddVect\@tempb and#1to\@tempb
1293 \VECTOR(\@tempb)(#2)\VECTOR(\@tempb)(#1)}\ignorespaces}
1294 % \end{macrocode}
1295 %
1296 % The |pict2e| documentation says that if the vector length is
1297 % zero the macro draws only the arrow tip; this may work with
1298 % macro |\vector|, certainly not with |\Vector| and |\VECTOR|.
1299 % This might be useful for adding an arrow tip to a circular
1300 % arc. See the documentation |curve2e-manual.pdf| file.
1301 %
1302 %
1303 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1304 % \subsection{Polylines and polygons}
1305 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1306 % We now define the polygonal line macro; its syntax is very
1307 % simple:
1308 % \begin{Sintassi}\ttfamily
1309 % \cs{polyline}\oarg{join}\parg{$P_0$}\parg{$P_1$}\parg{$P_2$}...^^A
1310 %\parg{$P_n$}
1311 % \end{Sintassi}
1312 % Remember: |\polyline| has been incorporated into |pict2e|
1313 % 2009, but we redefine it so as to allow an optional argument
1314 % to specify the line join type.
1315 %
1316 % In order to write a recursive macro we need aliases for the
1317 % parentheses; actually we need only the left parenthesis, but
1318 % some editors complain about unmatched delimiters, so we
1319 % define an alias also for the right parenthesis.
1320 % \begin{macrocode}
1321 \let\lp@r( \let\rp@r)
1322 % \end{macrocode}
1323 % The first call to |\polyline|, besides setting the line
1324 % joins,
1325 % examines the first point coordinates and moves the drawing
1326 % position to this point; afterwards it looks for the second
1327 % point coordinates; they start with a left parenthesis; if
1328 % this is found the coordinates should be there, but if the
1329 % left parenthesis is missing (possibly preceded by spaces that
1330 % are ignored by the |\@ifnextchar| macro) then a warning
1331 % message is output together with the line number where the
1332 % missing parenthesis causes the warning: beware, this line
1333 % number might point to several lines further on along the
1334 % source file!
1335 % In any case it's necessary to insert a |\@killglue| command,
1336 % because |\polyline| refers to absolute coordinates, and not
1337 % necessarily is put in position through a |\put| command that
1338 % provides to eliminate any spurious spaces preceding this
1339 % command.
1340 %
1341 % \begin{figure}[!hb]\vspace*{-1ex}
1342 % \begin{minipage}{0.55\textwidth}
1343 %\begin{Sintassi}\ttfamily\obeylines
1344 % \cs{unitlength}=0.07\cs{hsize}
1345 % \cs{begin}\Marg{picture}(8,8)(-4,-4)\cs{color}\{red\}
1346 % \cs{polygon*}(45:4)(135:4)(-135:4)(-45:4)
1347 % \cs{end}\Marg{picture}
1348 %\end{Sintassi}
1349 % \end{minipage}
1350 % \hfill
1351 % \begin{minipage}{0.4\textwidth}\centering
1352 % \unitlength=0.07\hsize
1353 % \begin{picture}(8,8)(-4,-4)\color{red}
1354 % \polygon*(45:4)(135:4)(-135:4)(-45:4)
1355 % \end{picture}
1356 % \end{minipage}\vspace*{-1ex}
1357 % \caption{The code and the result of defining a polygon with
1358 % its vertex polar coordinates}%
1359 % \label{fig:filled-polygon}
1360 % \end{figure}
1361 %
1362 % In order to allow a specification for the joints of the
1363 % various segments of a polyline it is necessary to allow for
1364 % an optional parameter; the default is the bevel join.
1365 % \begin{macrocode}
1366 \renewcommand*\polyline[1][\beveljoin]{\p@lylin@[#1]}
1367
1368 \def\p@lylin@[#1](#2){\@killglue#1\GetCoord(#2)\d@mX\d@mY
1369 \pIIe@moveto{\d@mX\unitlength}{\d@mY\unitlength}%
1370 \@ifnextchar\lp@r{\p@lyline}{%
1371 \PackageWarning{curve2e}%
1372 {Polylines require at least two vertices!\MessageBreak
1373 Control your polyline specification\MessageBreak}%
1374 \ignorespaces}}
1375
1376 % \end{macrocode}
1377 % But if there is a further point coordinate, the recursive
1378 % macro |\p@lyline| is called; it works on the next point and
1379 % checks for a further point; if such a point exists the macro
1380 % calls itself, otherwise it terminates the polygonal line by
1381 % stroking it.
1382 % \begin{macrocode}
1383 \def\p@lyline(#1){\GetCoord(#1)\d@mX\d@mY
1384 \pIIe@lineto{\d@mX\unitlength}{\d@mY\unitlength}%
1385 \@ifnextchar\lp@r{\p@lyline}{\strokepath\ignorespaces}}
1386 % \end{macrocode}
1387 %
1388 % The same treatment must be done for the \cs{polygon} macros; we
1389 % use the defining commands of package |xparse|, in order to use
1390 % an optional asterisk; as it is usual with |picture| convex
1391 % lines, the command with asterisk does not trace the contour,
1392 % but fills the contour with the current color.The asterisk is
1393 % tested at the beginning and, depending on its presence, a
1394 % temporary switch is set to \texttt{true}; this being the case
1395 % the contour is filled, otherwise it is simply stroked.
1396 % \begin{macrocode}
1397 \providecommand\polygon{}
1398 \RenewDocumentCommand\polygon{s O{\beveljoin} }{\@killglue\begingroup
1399 \IfBooleanTF{#1}{\@tempswatrue}{\@tempswafalse}%
1400 \@polygon[#2]}
1401
1402 \def\@polygon[#1](#2){\@killglue#1\GetCoord(#2)\d@mX\d@mY
1403 \pIIe@moveto{\d@mX\unitlength}{\d@mY\unitlength}%
1404 \@ifnextchar\lp@r{\@@polygon}{%
1405 \PackageWarning{curve2e}%
1406 {Polygons require at least two vertices!\MessageBreak
1407 Control your polygon specification\MessageBreak}%
1408 \ignorespaces}}
1409
1410 \def\@@polygon(#1){\GetCoord(#1)\d@mX\d@mY
1411 \pIIe@lineto{\d@mX\unitlength}{\d@mY\unitlength}%
1412 \@ifnextchar\lp@r{\@@polygon}{\pIIe@closepath
1413 \if@tempswa\pIIe@fillGraph\else\pIIe@strokeGraph\fi
1414 \endgroup
1415 \ignorespaces}}
1416 % \end{macrocode}
1417 % Now, for example, a filled polygon can be drawn using polar
1418 % coordinates for its vertices; see
1419 % figure~\ref{fig:filled-polygon} on
1420 % page~\pageref{fig:filled-polygon}.
1421 %
1422 % Remember; the polygon polar coordinates are relative to the
1423 % origin of the local axes; therefore in order to put a polygon
1424 % in a different position, it is necessary to do it through
1425 % |\put| command.
1426
1427 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1428 % \subsection{The colored service grid}
1429 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1430 % The next command is handy for debugging while
1431 % editing one's drawing; it draws a red grid with
1432 % square meshes that are ten drawing units apart;
1433 % there is no graduation along the grid, since it
1434 % is supposed to be a debugging aid and users
1435 % should know what they are doing. The corner
1436 % displacement does not need to be with
1437 % coordinates multiples of !0; the new version of
1438 % |curve2e| draws the square inner grid lines so
1439 % as according to the dimensions of the grid
1440 % squares (10~|\unitlength| apart) the
1441 % interior line may coincide only with the
1442 % square median line, or there are four lines
1443 % apart, or, besides a thicker median line, there
1444 % are lines 1~|\unitlength| apart, just as in a
1445 % normal technical millimetre drawing paper. The
1446 % syntax id the following
1447 %\begin{Sintassi}
1448 %\cs{GraphGrid}\parg{picture dimensions}\parg{corner offset} \oarg{color}
1449 %\end{Sintassi}
1450 % where the first argument is mandatory, while
1451 % the second and the third ones are optional.
1452 % The default value for the \meta{color} argument
1453 % is ‘red’; if another color is preferred,
1454 % it must be chosen among the relatively light
1455 % ones, in order to avoid confusion with the real
1456 % drawing elements. The second argument plays the
1457 % same role as the second optional argument of
1458 % the |picture| environment; it is the offset of
1459 % the lower left picture corner with respect to
1460 % the origin of the coordinates.
1461 %
1462 % If the second argument is missing, the lower
1463 % left corner is put at the origin of the canvas
1464 % coordinates. Of course also the lower left
1465 % corner offset is recommended to be specified
1466 % with coordinates that are integer values.
1467 % Actually, since both arguments are delimited
1468 % with round parentheses, a single argument is
1469 % assumed to contain both comma separated grid
1470 % dimensions.
1471 %
1472 % In order to render the coloured grid a little
1473 % more automatic, a subsidiary service macro of
1474 % the |picture| environment has been redefined in
1475 % order to store the coordinates of the canvas
1476 % dimensions and of the lower left corner offset
1477 % (the compulsory dimensions and the optional
1478 % lower left corner shift arguments to the
1479 % |picture| opening statement) in two new
1480 % variables, so that when the user specifies the
1481 % (non vanishing) dimensions of the canvas, the
1482 % necessary data are already available and there
1483 % is no need to repeat them to draw the grid.
1484 %
1485 % The new argument-less macro is named
1486 % |\AutoGrid|, while the complete macro is
1487 % |\GraphGrid| that requires its arguments as
1488 % specified above. The advantage of the
1489 % availability of both commands, consists in the
1490 % fact that |\AutoGrid| covers the whole canvas,
1491 % while |\GraphGrid| may compose a grid that
1492 % covers either the whole canvas or just a part of
1493 % it. In both cases, though, it is necessary the
1494 % all the canvas coordinates are specified as
1495 % integer values, better if multiples of 10
1496 % (|\unitlength|s), but not mandatory. This is
1497 % simple when |\GraphGrid| is used, while with
1498 % |\AutoGrid| the default specification are
1499 % already contained in the opening environment
1500 % statement.
1501 %
1502 % Nevertheless even |\AutoGride| accepts both
1503 % parameters as optional round parentheses
1504 % delimited arguments. |\AutoGrid| differs from
1505 % |\GraphGrid| only on the fact thay its
1506 % arguments are both optional, while for
1507 % |\GraphGrid| the first argument is mandatory;
1508 % therefore very often it is possibile to
1509 % substitute |\GraphGrid| with |\AutoGrid|, while
1510 % the opposite is forbidden unless at least the
1511 % first optional argument is specified.
1512 %
1513 % The |AutoGrid| syntax is almost identical to
1514 % the one of |\GraphGrid|:
1515 %\begin{Sintassi}
1516 %\cs{GrAutoGrid}\parg{picture dimensions}\parg{corner offset} \oarg{color}
1517 %\end{Sintassi}
1518 % \begin{macrocode}
1519 \def\@picture(#1,#2)(#3,#4){%
1520 \edef\pict@dimen{#1,#2} % New 2.4.0
1521 \edef\pict@offset{#3,#4}% New 2.4.0
1522 \@picht#2\unitlength
1523 \setbox\@picbox\hb@xt@#1\unitlength\bgroup
1524 \hskip -#3\unitlength
1525 \lower #4\unitlength\hbox\bgroup
1526 \ignorespaces}
1527
1528 % \end{macrocode}
1529 % In order to draw grids with differently spaced
1530 % grid lines, a single |\griglia| command
1531 % (“griglia” stands for ”grid”, but it is less
1532 % likely common to other packages control
1533 % sequences and is similar to the English word)
1534 % This command syntax is the following:
1535 % \begin{Sintassi}
1536 %\cs{griglia}\marg{line thickness}\marg{inter line space} \oarg{color}
1537 % \end{Sintassi}
1538 % The main grid squares are 10 units apart, and
1539 % are always drawn on the canvas; the internal
1540 % lines are at specified 5, or 2, or 1 units
1541 % apart; suitable tests are made by the main grid
1542 % macro to use this or that spacing. The control
1543 % sequences with upper case initials in the
1544 % following definition contain values computed by
1545 % the main macro; those with lowercase initials
1546 % are local values. The computations made with
1547 % the |\fpeval| function are a way to compute
1548 % integer multiples of 10, 5, 2, and 1, the
1549 % spacing values for the horizontal and vertical
1550 % grid lines. Notice that if users prefer to have
1551 % the grid contain just the main lines 10 units
1552 % apart, before activating the grid drawing by
1553 % means of |\AutoGrid| or |\GraphGrid|, they can
1554 % specify |\noinnerlines| and the inner lines are
1555 % skipped in that particular |picture|
1556 % environment; if they specify |\noinnerlines|
1557 % right after the |\begin{document}| statement,
1558 % this setting becomes global and no |picture|
1559 % environment is going to contain any inner lines.
1560 % \begin{macrocode}
1561 \newif\ifinnerlines \let\ifinnerlines\iftrue
1562 \def\noinnerlines{\let\ifinnerlines\iffalse}
1563
1564 \newcommand\griglia[2]{%
1565 \linethickness{#1\p@}%
1566 \edef\ggllx{\Goffx}
1567 \fpdowhile{\ggllx!>\GridWd}{%
1568 \fptest{\ggllx=\fpeval{#2*(round(\ggllx/#2,0))}}%
1569 {\segment(\ggllx,\Goffy)(\ggllx,\GridHt)}{\relax}%
1570 \edef\ggllx{\fpeval{\ggllx+#2}}}%
1571 %
1572 \edef\gglly{\Goffy}
1573 \fpdowhile{\gglly!>\GridHt}{%
1574 \fptest{\gglly=\fpeval{#2*(round(\gglly/#2,0))}}%
1575 {\segment(\Goffx,\gglly)(\GridWd,\gglly)}{\relax}
1576 \edef\gglly{\fpeval{\gglly+#2}}}}
1577
1578 % \end{macrocode}
1579 % The grid main macro comes next. The first 6
1580 % lines of its code are used to get the
1581 % properties of the grid, as the grid colour, and
1582 % computes the fixed elements such as the single
1583 % coordinates of the canvas, the actual
1584 % coordinates of its box relative to the offset
1585 % canvas lower left corner. Such values are
1586 % independent of the grid line density. The
1587 % following macros use the |\griglia| macro to
1588 % draw each set of grid lines of the proper
1589 % thickness, when the actual dimensions are
1590 % taken into account.
1591 % \begin{macrocode}
1592 \NewDocumentCommand\Gr@phGrid{d() d()}{\bgroup
1593 \color{\GridColor}
1594 \edef\Gdim{#1}\edef\Goff{#2}
1595 \GetCoord(\Gdim)\Gllx\Glly
1596 \GetCoord(\Goff)\Goffx\Goffy
1597 \edef\GridWd{\fpeval{\Gllx+\Goffx}}%
1598 \edef\GridHt{\fpeval{\Glly+\Goffy}}%
1599 %
1600 \griglia{1.0}{10}
1601 %
1602 \ifinnerlines
1603 \griglia{0.70}{5}%
1604 \unless\ifdim \unitlength < 1mm
1605 \griglia{0.70}{5}%
1606 \griglia{0.35}{1}%
1607 \fi
1608 \fi
1609 \egroup
1610 \ignorespaces}
1611
1612 % \end{macrocode}
1613 % Eventually the user macros |\AutoGrid| and
1614 % |\GrapgGrid| macros are defined. Their
1615 % definitions are almost identical, the only
1616 % difference being the fact that their first
1617 % arguments era optional for the first macro and
1618 % mandatory for the second one. The mandatory
1619 % and optional arguments are assigned the initial
1620 % default values, as defined by the |picture|
1621 % opening statement arguments. In facts, due to
1622 % the agility of the |\AutoGrid| macro, one may
1623 % wonder if the other macro has to be defined;
1624 % Its utility is mainly for backwards
1625 % compatibility. Nevertheless the companion
1626 % document \textsf{curve2e-manual} displays a few
1627 % examples where |\GraphGrid| is used, just to
1628 % show its usage.
1629 % \begin{macrocode}
1630 \NewDocumentCommand\AutoGrid%
1631 {D(){\pict@dimen} D(){\pict@offset} O{cyan!50!white}}{\bgroup
1632 \def\GridColor{#3}%
1633 \put(0,0){\Gr@phGrid(#1)(#2)}%
1634 \egroup\ignorespaces}
1635
1636 \NewDocumentCommand\GraphGrid%
1637 {R(){\pict@dimen} D(){\pict@offset} O{cyan!50!white}}
1638 {\bgroup
1639 \def\GridColor{#3}%
1640 \put(#2){\Gr@phGrid(#1)(#2)}%
1641 \egroup\ignorespaces}
1642
1643 % \end{macrocode}
1644 % For backwards compatibility we keep the macro
1645 % used to round up the grid margins coordinates
1646 % to multiples of~10.
1647 % \begin{macrocode}
1648 \def\RoundUp#1modulo#2to#3{\edef#3{\fpeval{(ceil(#1/#2,0))*#2}}}%
1649 %
1650 % \end{macrocode}
1651 % The next |\Integer| macro takes a possibly
1652 % fractional numeric argument whose decimal
1653 % separator, if present, \textit{must} be the
1654 % decimal point and uses the point as an argument
1655 % delimiter. If users have the doubt that the
1656 % number being passed to |\Integer| might be an
1657 % integer, they should call the macro with a
1658 % further point; if the argument is truly integer
1659 % this point works as the delimiter of the
1660 % integer part; if the argument being passed is
1661 % fractional this extra point gets discarded as
1662 % well as the fractional part of the number. This
1663 % macro was used within the definition of
1664 % |\RoundUp|; with the |xfp| facilities the
1665 % latter macro does not need it any more, but
1666 % it continues to be used in several other
1667 % macros.
1668 % \begin{macrocode}
1669 \def\Integer#1.#2??{#1}%
1670
1671 % \end{macrocode}
1672 %
1673 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1674 % \section{Labelling the graphical elements}
1675 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1676 %
1677 % While drawing anything with the \pack{curve2e}
1678 % package, it might be necessary to identify some
1679 % graphical objects with some sort of “label”.^^A
1680 %\footnote{Do not confuse this identifier label
1681 % with the \cs{label} command.}
1682 %
1683 % Some commands such as \cs{legenda}
1684 % (\emph{legend}), \cs{Zbox}, and \cs{Pbox} have
1685 % been always used in the documentation of this
1686 % package and its siblings; but we used them in
1687 % many other documents; therefore we thought it
1688 % was useful to have them available to any user of
1689 % \pack{curve2e}.
1690 %
1691 %Their commands follow the following syntax.
1692 %\begin{Sintassi}
1693 %|\Pbox|\parg{coordinates}\oarg{position}\marg{formula}\oarg{dot diameter}\meta{\texttt{*}}\aarg{angle}
1694 %|\Zbox|\parg{coordinates}\oarg{position}\marg{formula}\oarg{dot diameter}
1695 %|\legenda|\parg{coordinates}\marg{formula}
1696 %\end{Sintassi}
1697 %
1698 % These commands have similar but different
1699 % functionalities; the most general one is
1700 % |\Pbox|, while the others are simplified
1701 % versions that have a simpler syntax, and a
1702 % subset of the |\Pbox| functionalities. While we
1703 % describe the arguments of |\Pbox| we emphasise
1704 % the small differences with the other two
1705 % commands.
1706 %\begin{description}
1707 %\item[\meta{coordinates}]
1708 % are the coordinates (explicit, or in vector
1709 % form) of the reference point of the “label”;
1710 % for |\legenda| it is the lower left corner of
1711 % the framed legend contents. They are delimited
1712 % with the usual matched parentheses, and their
1713 % default value is \texttt{(0,0)}, therefore
1714 % either users specify other coordinates, or use
1715 % the |\put| command to place the legend where
1716 % they prefer.
1717 %
1718 %\item[\meta{position}]
1719 % is the optional position of the reference point
1720 % relative to the “label” contents: this means
1721 % that if the “label” should be NE (North East)
1722 % relative to the visible (or invisible) dot it
1723 % labels, the \meta{position} codes should be
1724 % \texttt{tr} (top right); the default
1725 % \meta{position} is \texttt{cc} so that the
1726 % “label” is vertically and horizontally centred
1727 % at the reference point; actually these position
1728 % parameters should always be specified if
1729 % the dot diameter is positive (therefore
1730 % visible), otherwise the “label” and the dot
1731 % overwrite each other.
1732 %
1733 %\item[\meta{formula}]
1734 % may be almost anything; \meta{formula} means
1735 % that the argument is typeset in math mode; if
1736 % some text is desired the argument must be
1737 % surrounded by a matched couple of dollar signs;
1738 % in any case it is possible to enter text mode by
1739 % using a box (for example through a |\hbox| or a
1740 % |\parbox|) so that actually this mandatory
1741 % argument may contain almost anything.
1742 %
1743 %\item[\meta{dot diameter}] the dot diameter
1744 % default value is positive; for |\Zbox| this
1745 % parameter equals |1\unitlength|, while for
1746 % |\Pbox| it equals \texttt{0.5ex}; the user
1747 % should be careful in modifying this value; but
1748 % if the dot diameter is set to zero, the dot is
1749 % absent and the |\Zbox| command behaves almost as
1750 % an unframed legend. The small difference is that
1751 % |\Zbox| accepts a \meta{position} parameter
1752 % while the |\legend| command does not.
1753 %
1754 %\item[\meta{\texttt{*}}] is an optional star; if
1755 % specified the “label” is framed with a visible
1756 % border, otherwise it is framed with an invisible
1757 % one but with a blank gap that tries to adjust
1758 % its thickness so that the “label” is always at
1759 % the same distance from the reference point; if
1760 % this reference point corresponds to a box corner
1761 % it thickness is reduced by approximately a
1762 % factor equal to $\sqrt{0.5}$, in oder to take
1763 % into account the diagonal of the blank gap
1764 % angle.
1765 %
1766 %\item[\meta{angle}] is the rotation angle (in
1767 % degrees) of the “label” about its reference
1768 % point; sometimes such “labels” have to be
1769 % rotated 90° anticlockwise; sometimes they need a
1770 % positive or negative rotation angle in order to
1771 % match the general direction of the “labelled”
1772 % object, be it an oblique line, an axis, or
1773 % whatever. We found it very useful also to
1774 % label the cartesian axes, but also in other
1775 % situations. For example, in order to label the
1776 % $x$ axis the |\Pbox| command might have the
1777 % arrow tip coordinates for the reference point
1778 % and have \texttt{tr} for the \meta{position};
1779 % for the $y$ axis, the reference point is again
1780 % the arrow tip, and the position would be again
1781 % \texttt{tr} if the “label” sits on the left of
1782 % the axis.
1783 %\end{description}
1784 %
1785 % \begin{macrocode}
1786 \providecommand\Pbox{}
1787 \newlength\PbDim
1788 \RenewDocumentCommand\Pbox{D(){0,0} O{cc} m O{0.5ex} s D<>{0}}{%
1789 \put(#1){\rotatebox{#6}{\makebox(0,0){%
1790 \settowidth\PbDim{#2}%
1791 \edef\Rapp{\fpeval{\PbDim/{1ex}}}%
1792 \fptest{\Rapp>1.5}{\fboxsep=0.5ex}{\fboxsep=0.75ex}%
1793 \IfBooleanTF{#5}{\fboxrule=0.4pt}{\fboxrule=0pt}%
1794 \fptest{#4=0sp}%
1795 {\makebox(0,0)[#2]{\fbox{$\relax#3\relax$}}}%
1796 {\edef\Diam{\fpeval{(#4)/\unitlength}}%
1797 \makebox(0,0){\circle*{\Diam}}%
1798 \makebox(0,0)[#2]{\fbox{$\relax\mathsf#3\relax$}}%
1799 }}}%
1800 }\ignorespaces}
1801
1802 \providecommand\Zbox{}
1803 \RenewDocumentCommand\Zbox{R(){0,0} O{cc} m O{1}}{%
1804 \put(#1){\makebox(0,0)[#2]{\fboxrule=0pt\fboxsep=3pt\fbox{$#3$}}%
1805 \makebox(0,0)[cc]{\circle*{#4}}}\ignorespaces}
1806
1807 \providecommand\legenda{}
1808 \newbox\legendbox
1809 \RenewDocumentCommand\legenda{D(){0,0} m}{\put(#1){%
1810 \setbox\legendbox\hbox{$\relax#2\relax$}%
1811 \edef\@tempA{\fpeval{(\wd\legendbox+3\p@)/\unitlength}}%
1812 \edef\@tempB{\fpeval{(\ht\legendbox+\dp\legendbox+3\p@)/\unitlength}}%
1813 \framebox(\@tempA,\@tempB){\box\legendbox}}\ignorespaces}
1814
1815 % \end{macrocode}
1816
1817 % With the above labelling facilities and with use
1818 % of the \pack{xfp} functionalities it is not
1819 % difficult to create diagrams with linear or
1820 % logarithmic axes. In effects the
1821 % \pack{graphpaper} class uses these labelling
1822 % macros and several other ones.
1823 %
1824 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1825 % \section{Math operations on fractional operands}
1826 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1827 % This is not the place to complain about the fact
1828 % that all programs of the \TeX\ system use only
1829 % integer arithmetics; now, with the 2018
1830 % distribution of the modern \TeX\ system,
1831 % package |xfp| is available: this package resorts
1832 % in the background to language \LaTeX\,3; with
1833 % this language now it is possible to compute
1834 % fractional number operations; the numbers are
1835 % coded in decimal notation, not in binary one,
1836 % and it is possible also to use numbers written
1837 % as in computer science, that is as a fractional,
1838 % possibly signed, number followed by an
1839 % expression that contains the exponent of~10
1840 % necessary to (ideally) move the fractional
1841 % separator in one or the other direction
1842 % according to the sign of the exponent of~ 10; in
1843 % other words the L3 library for floating point
1844 % calculations accepts such expressions as
1845 % \texttt{123.456}, \texttt{0.12345e3}, and
1846 % \texttt{12345e-3}, and any other equivalent
1847 % expression. If the first number is integer, it
1848 % assumes that the decimal separator is to the
1849 % right of the rightmost digit of the numerical
1850 % string.
1851 %
1852 % Floating point calculations may be done through
1853 % the |\fpeval| L3 function with a very simple
1854 % syntax:
1855 % \begin{Sintassi}
1856 % \cs{fpeval}\marg{mathematical expression}
1857 % \end{Sintassi}
1858 % where \meta{mathematical expression} can contain
1859 % the usual algebraic operation sings,
1860 % |`+' - * / ** ^| and the function names of the
1861 % most common algebraic, trigonometric, and
1862 % transcendental functions; for direct and inverse
1863 % trigonometric functions it accepts arguments in
1864 % radians and in sexagesimal degrees; it accepts
1865 % the group of rounding/truncating operators; it
1866 % can perform several kinds of comparisons; as to
1867 % now (Nov. 2019) the todo list includes the
1868 % direct and inverse hyperbolic functions. The
1869 % mantissa length of the floating point operands
1870 % amounts to~16 decimal digits. Further details
1871 % may be read in the documentations of the |xfp|
1872 % and |interface3| packages, just by typing into a
1873 % command line window the command \texttt{texdoc
1874 % \meta{document}}, where \meta{document} is just
1875 % the name of the above named files without the
1876 % need of stating the extension.
1877 %
1878 % Furthermore we added a few interface macros with
1879 % the internal L3 floating point functions;
1880 % |\fptest| and |\fpdowhile|. They have the
1881 % following syntax.
1882 %\begin{Sintassi}\ttfamily\obeylines
1883 % \string\fptest\marg{logical expression}\marg{true code}\marg{false code}
1884 % \string\fptestT\marg{logical expression}\marg{true code}
1885 % \string\fptestF\marg{logicalexpression}\marg{false code}
1886 % \string\fpdowhile\marg{logical expression}\marg{code}
1887 %\end{Sintassi}
1888 % The \meta{logical expression} compares
1889 % numerical values of any kind by means of the
1890 % usual \texttt{>}, \texttt{=}, and \texttt{<}
1891 % operators that may be negated with the “not”
1892 % operator \texttt{!}; furthermore the logical
1893 % results of these comparisons may be acted upon
1894 % with the “and” operator \texttt{\&\&} and the
1895 % “or” operator \texttt{\string|\string|}.
1896 % The \meta{true code}, and \meta{code} are
1897 % executed if or while the \meta{logical
1898 % expression} is true, while the \meta{false code}
1899 % is executed if the \meta{logical expression}
1900 % is false
1901 %
1902 % This package defines Some other advanced
1903 % commands, although they are not used for
1904 % drawing; they might be useful for some users.
1905 % They are |\Modulo|, |\Ifodd|, |\IfEqual|; namely
1906 % the function to compute the expression
1907 % $x= a \mod b$, in other words the remainder of
1908 % the integer quotient of $a/b$; the equivalent of
1909 % the native command |\ifodd| with the difference
1910 % that it can test directly an integer expression;
1911 % similarly |\IfEqual| extends the functionality
1912 % of the native command |\ifx|, but can compare
1913 % any kind of tokens; they are all robust commands
1914 % while the original tests are fragile.
1915 %
1916 % Before the availability of the |xfp| package, it
1917 % was necessary to fake fractional number
1918 % computations by means of the native e-\TeX\
1919 % commands |\dimexpr|, i.e. to multiply each
1920 % fractional number by the unit |\p@| (1\,pt) so
1921 % as to get a length; operate on such lengths, and
1922 % then stripping off the `pt' component from the
1923 % result; very error prone and with less
1924 % precision as the one that the modern decimal
1925 % floating point calculations can do. Of course it
1926 % is not so important to use fractional numbers
1927 % with more than 5 or 6 fractional digits,
1928 % because the other \TeX\ and \LaTeX\ macros
1929 % cannot handle them, but it is very convenient to
1930 % have simpler and more readable code. We
1931 % therefore switched to the new floating point
1932 % functionality, even if this maintains the
1933 % |curve2e| functionality, but renders this
1934 % package unusable with older \LaTeX\ kernel
1935 % installations. It has already been explained
1936 % that the input of this up-to-date version of
1937 % |curve2e| is aborted if the |xfp| package is not
1938 % available, but the previous 1.61 version is
1939 % loaded in its place; very little functionality
1940 % is lost, but, hopefully, this new version
1941 % performs in a better way.
1942 %
1943 %
1944 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1945 % \subsection{The division macro}
1946 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1947
1948 % The most important macro is the division of two
1949 % fractional numbers; we seek a macro that gets
1950 % dividend and divisor as fractional numbers and
1951 % saves their ratio in a macro; this is done in a
1952 % simple way with the following code.
1953 % \begin{macrocode}
1954 \def\DividE#1by#2to#3{\edef#3{\fpeval{#1 / #2}}}
1955 % \end{macrocode}
1956 % In order to avoid problems with divisions by
1957 % zero, or with numbers that yield results too
1958 % large to be used as multipliers of unit lengths,
1959 % it would be preferable that the above code be
1960 % preceded or followed by some tests and possible
1961 % messages.
1962 % Actually we decided to avoid such tests and
1963 % messages, because the internal L3 functions
1964 % already provide some. This was done in the
1965 % previous versions of this package, when the
1966 % |\fpeval| L3 function was not available.
1967 %
1968 % Notice that operands |#1| and |#2| may be
1969 % integer numbers or fractional, or mixed numbers.
1970 % They may be also dimensions: in this case our
1971 % function |\fpeval| treats the unit symbols as
1972 % special numerical constants that transform the
1973 % dimensions into typographical points; for
1974 % example |mm| is the (dimensionless) ratio of
1975 % two lengths
1976 %$1\mathrm{pt}/1\mathrm{mm}=(72{,}27\mathrm{pt/in})/(25{,}4\mathrm{mm/in})=2{,}84527559055118$;
1977 % therefore both expressions
1978 %\begin{verbatim}
1979 %\DividE(1mm)by(3mm)to\result
1980 %\Divide 1mm by 3mm to\result
1981 %\end{verbatim}
1982 % yield correctly |\result=0.33333333|.
1983 %
1984 % For backwards compatibility we need an alias.
1985 % \begin{macrocode}
1986 \let\DivideFN\DividE
1987 % \end{macrocode}
1988 %
1989 % We do the same in order to multiply two integer
1990 % or fractional numbers held in the first two
1991 % arguments, and the third argument is a definable
1992 % token that will hold the result of
1993 % multiplication in the form of a fractional
1994 % number, possibly with a non null fractional
1995 % part; a null fractional part is stripped off.
1996 % \begin{macrocode}
1997 \def\MultiplY#1by#2to#3{\edef#3{\fpeval{#1 * #2}}}\relax
1998 \let\MultiplyFN\MultiplY
1999 % \end{macrocode}
2000 % but with multiplication it is better to avoid
2001 % computations with lengths.
2002 %
2003 % The next macro uses the |\fpeval| macro to get
2004 % the numerical value of a measure in points. One
2005 % has to call |\Numero| with a control sequence
2006 % and a dimension, with the following syntax; the
2007 % dimension value in points is assigned to the
2008 % control sequence.
2009 %\begin{Sintassi}
2010 %\cs{Numero}\meta{control sequence result}\meta{dimension}
2011 %\end{Sintassi}
2012 % \begin{macrocode}
2013 \providecommand\Numero[2]{\edef#1{\fpeval{round(#2,6)}}}
2014 % \end{macrocode}
2015 % The numerical value is rounded to 6 fractional
2016 % digits that are more than sufficient for the
2017 % graphical actions performed by |curve2e|.
2018 %
2019 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2020 % \subsection{Trigonometric functions}
2021 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2022 % We now start with trigonometric functions. In
2023 % previous versions of this package we defined the
2024 % macros |\SinOf|, |\CosOf|, and |\TanOf|
2025 % (|\CotOf| did not appear so essential)
2026 % by means of the parametric formulas that require
2027 % the knowledge of the tangent of the half angle.
2028 % We wanted, and still want, to specify the angles
2029 % in sexagesimal degrees, not in radians, so that
2030 % accurate reductions to the main quadrants are
2031 % possible. The bisection formulas are
2032 % \begin{eqnarray*}
2033 % \sin\theta &=& \frac{2}{\cot x + \tan x}\\
2034 % \cos\theta &=& \frac{\cot x - \tan x}{\cot x + \tan x}\\
2035 % \tan\theta &=& \frac{2}{\cot x - \tan x}\\
2036 % \noalign{\hbox{where}}
2037 % x &=& \theta/114.591559
2038 % \end{eqnarray*}
2039 % is the half angle in degrees converted to radians.
2040 %
2041 % But now, in this new version, the availability
2042 % of the floating point computations with the
2043 % specific L3 library makes all the above
2044 % superfluous; actually the above approach gave
2045 % good results but it was cumbersome and limited
2046 % by the fixed radix computations of the \TeX\
2047 % system programs.
2048 %
2049 % Matter of facts, we compared the results (with 6
2050 % fractional digits) of the computations executed
2051 % with the \texttt{sind} function name, in order
2052 % to use the angles in degrees, and a table of
2053 % trigonometric functions with the same number of
2054 % fractional digits, and we did not find any
2055 % difference, not even one unit on the sixth
2056 % decimal digit. Probably the |\fpeval|
2057 % computations, without rounding before the
2058 % sixteenth significant digit, are much more
2059 % accurate, but it is useless to have a higher
2060 % accuracy when the other \TeX\ and \LaTeX\
2061 % macros would not be able to exploit them.
2062 %
2063 % Having available such powerful instrument, even
2064 % the tangent appears to be of little use for the
2065 % kind of computations that are supposed to be
2066 % required in this package.
2067 %
2068 % The codes for the computation of |\SinOf| and
2069 % |\CosOf| of the angle in degrees is now
2070 % therefore the following
2071 % \begin{macrocode}
2072 \def\SinOf#1to#2{\edef#2{\fpeval{round(sind#1,6)}}}\relax
2073 \def\CosOf#1to#2{\edef#2{\fpeval{round(cosd#1,6)}}}\relax
2074 % \end{macrocode}
2075 %
2076 %
2077 % Sometimes the argument of a complex number is
2078 % necessary; therefore with macro |\ArgOfVect| we
2079 % calculate the four quadrant arctangent (in
2080 % degrees) of the given vector taking into account
2081 % the sings of the vector components. We use the
2082 % |xfp| |atand| with two arguments, so that it
2083 % automatically takes into account all the signs
2084 % for determining the argument of vector $x,y$ by
2085 % giving the values $x$ and $y$ in the
2086 % proper order to the function |atan|:
2087 %\[
2088 %\mbox{if\quad } x + \mathrm{i}y = M\mathrm{e}^{\mathrm{i}\varphi}\mbox{\quad then\quad }
2089 %\varphi = \mathtt{\string\fpeval\{atand(\mbox{$y$},\mbox{$x$})\}}
2090 %\]
2091 % The |\ArgOfVect| macro receives on input a
2092 % vector and determines its four quadrant
2093 % argument; it only checks if both vector
2094 % components are zero, because in this case
2095 % nothing is done, and the argument is assigned
2096 % the value zero.
2097 % \begin{macrocode}
2098 \def\ArgOfVect#1to#2{\GetCoord(#1){\t@X}{\t@Y}%
2099 \fptest{\t@X=\z@&&\t@Y=\z@}{\edef#2{0}%
2100 \PackageWarning{curve2e}{Null vector}{%
2101 Check your data\MessageBreak
2102 Computations go on, but the results may be meaningless}%
2103 }{\edef#2{\fpeval{round(atand(\t@Y,\t@X),6)}}}%
2104 \ignorespaces}
2105 % \end{macrocode}
2106 % Since the argument of a null vector is
2107 % meaningless, we set it to zero in case that
2108 % input data refer to such a null vector.
2109 % Computations go on anyway, but the results may
2110 % be meaningless; such strange results are an
2111 % indications that some controls on the code
2112 % should be done by the user.
2113 %
2114 % It is worth examining the following table, where
2115 % the angles of nine vectors $45^\circ$ degrees
2116 % apart from one another are computed by using
2117 % this macro.
2118 % \begin{center}
2119 % \begin{tabular}{l*9r}
2120 % Vector &0,\,0 &1,\,0 &1,\,1 & 0,\,1 & -1,\,1& -1,\,0&-1,\,-1&0, -1&1,\,-1\\
2121 % Angle & 0 & 0 & 45 & 90 & 135 & 180 &-135 & -90& -45
2122 % \end{tabular}
2123 % \end{center}
2124 % Real computations with the |\ArgOfVect| macro
2125 % produce those very numbers without the need of
2126 % rounding; |\fpeval| produces by itself all the
2127 % necessary trimming of lagging zeros and the
2128 % result rounding.
2129 %
2130 %
2131 %
2132 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2133 % \subsection{Arcs and curves preliminary information}
2134 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2135 % We would like to define now a macro for drawing
2136 % circular arcs of any radius and any angular
2137 % aperture; the macro should require the arc
2138 % center, the arc starting point and the angular
2139 % aperture. The arc has its reference point in its
2140 % center, therefore it does not need to be put in
2141 % place by the command |\put|; nevertheless if
2142 % |\put| is used, it may displace the arc into
2143 % another position.
2144 %
2145 % The command should have the following syntax:
2146 % \begin{Sintassi}
2147 % \cs{Arc}(\meta{center})(\meta{starting point})\marg{angle}
2148 % \end{Sintassi}
2149 % which is totally equivalent to:
2150 % \begin{Sintassi}
2151 % \cs{put}(\meta{center})\marg{\upshape\cs{Arc}(0,0)(\meta{starting
2152 % point})\marg{angle}}
2153 % \end{Sintassi}
2154 % If the \meta{angle}, i.e. the arc angular
2155 % aperture, is positive the arc runs
2156 % counterclockwise from the starting
2157 % point; clockwise if it is negative.
2158 % Notice that since the \meta{starting point} is
2159 % relative to the \meta{center} point, its polar
2160 % coordinates are very convenient, since they
2161 % become \parg{\meta{start angle}:\meta{radius}},
2162 % where the \meta{start angle} is relative to the
2163 % arc center. Therefore you can think about a
2164 % syntax such as this one:
2165 %\begin{Sintassi}
2166 %\cs{Arc}\parg{center}\parg{start angle\texttt{\upshape :}{radius}}\marg{angle}
2167 %\end{Sintassi}
2168 %
2169 % The difference between the |pict2e| |\arc|
2170 % definition consists in a very different syntax:
2171 %\begin{Sintassi}
2172 %\cs{arc}\Oarg{\meta{start angle}\texttt{,}\meta{end angle}}\marg{radius}
2173 %\end{Sintassi}
2174 % and the center is assumed to be at the
2175 % coordinate established with a required |\put|
2176 % command; moreover the difference in
2177 % specifying angles is that \meta{end angle}
2178 % equals the sum of \meta{start angle} and
2179 % \meta{angle}. With the definition of this
2180 % |curve2e| package use of a |\put| command is not
2181 % prohibited, but it may be used for fine tuning
2182 % the arc position by means of a simple
2183 % displacement; moreover the \meta{starting point}
2184 % may be specified with polar coordinates (that
2185 % are relative to the arc center).
2186 %
2187 % It's necessary to determine the end point and
2188 % the control points of the Bézier spline(s) that
2189 % make up the circular arc.
2190 %
2191 % The end point is obtained from the rotation of
2192 % the starting point around the center; but the
2193 % \texttt{pict2e} command |\pIIe@rotate| is such
2194 % that the pivoting point appears to be non
2195 % relocatable. It is therefore necessary to resort
2196 % to low level \TeX\ commands and the defined
2197 % trigonometric functions and a set of macros that
2198 % operate on complex numbers used as vector
2199 % roto-amplification operators.
2200 %
2201 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2202 % \subsection{Complex number macros}
2203 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2204 % In this package \emph{complex number} is a vague
2205 % phrase; it may be used in the mathematical sense
2206 % of an ordered pair of real numbers; it can be
2207 % viewed as a vector joining the origin of the
2208 % coordinate axes to the coordinates indicated by
2209 % the ordered pair; it can be interpreted as a
2210 % roto-amplification operator that scales its
2211 % operand and rotates it about a pivot point;
2212 % besides the usual conventional representation
2213 % used by the mathematicians where the ordered
2214 % pair is enclosed in round parentheses (which is
2215 % in perfect agreement with the standard code used
2216 % by the |picture| environment) there is the
2217 % other conventional representation used by the
2218 % engineers that stresses the roto-amplification
2219 % nature of a complex number:
2220 %\[
2221 %(x, y) = x + \mathrm{j}y =M \mathrm{e}^{\mathrm{j}\theta}
2222 %\]
2223 % Even the imaginary unit is indicated with
2224 % $\mathrm{i}$ by mathematicians and with
2225 % $\mathrm{j}$ by engineers. In spite of
2226 % these differences, such objects, the
2227 % \emph{complex numbers}, are used without any
2228 % problem by both mathematicians and engineers.
2229 %
2230 % The important point is that these objects can be
2231 % summed,% subtracted, multiplied, divided, raised
2232 % to any power (integer, fractional, positive or
2233 % negative), be the argument of transcendental
2234 % functions according to rules that are agreed
2235 % upon by everybody. We do not need all these
2236 % properties, but we need some and we must create
2237 % the suitable macros for doing some of these
2238 % operations.
2239 %
2240 % In facts we need macros for summing,
2241 % subtracting, multiplying, dividing complex
2242 % numbers, for determining their directions
2243 % (unit vectors or versors); a unit vector is the
2244 % complex number divided by its magnitude so that
2245 % the result is the cartesian or polar form of the
2246 % Euler's formula
2247 % \[
2248 % \mathrm{e}^{\mathrm{j}\phi} = \cos\phi+\mathrm{j}\sin\phi
2249 % \]
2250 %
2251 % The magnitude of a vector is determined by
2252 % taking the positive square root of the sum of
2253 % the squared real and imaginary parts (often
2254 % called \emph{Pitagorean sum}); see further on.
2255 %
2256 % It's better to represent each complex number
2257 % with one control sequence; this implies frequent
2258 % assembling and disassembling the pair of real
2259 % numbers that make up a complex number. These
2260 % real components are assembled into the defining
2261 % control sequence as a couple of coordinates,
2262 % i.e.\ two comma separated integer or fractional
2263 % signed decimal numbers.
2264 %
2265 % For assembling two real numbers into a complex
2266 % number we use the following elementary macro:
2267 % \begin{macrocode}
2268 \def\MakeVectorFrom#1#2to#3{\edef#3{#1,#2}}%
2269 % \end{macrocode}
2270 % Another elementary macro copies a complex number
2271 % into another one:
2272 % \begin{macrocode}
2273 \def\CopyVect#1to#2{\edef#2{#1}\ignorespaces}%
2274 % \end{macrocode}
2275 % The magnitude is determined with the macro
2276 % |\ModOfVect| with delimited arguments; as usual
2277 % it is assumed that the results are retrieved by
2278 % means of control sequences, not used directly.
2279 %
2280 % In the preceding versions of package |curve2e|
2281 % the magnitude $M$ was determined by taking the
2282 % moduli of the real and imaginary parts, by
2283 % changing their signs if necessary; the larger
2284 % component was then taken as the reference one,
2285 % so that, if $a$ is larger than $b$, the square
2286 % root of the sum of their squares is computed as
2287 % such:
2288 % \[
2289 % M = \sqrt{a^2+b^2} = \vert a\vert\sqrt{1+(b/a)^2}
2290 % \]
2291 % In this way the radicand never exceeds 2 and it
2292 % was quite easy to get its square root by means
2293 % of the Newton iterative process; due to the
2294 % quadratic convergence, five iterations were more
2295 % than sufficient. When one of the components was
2296 % zero, the Newton iterative process was skipped.
2297 %
2298 % With the availability of the |xfp| package
2299 % functionalities and its floating point
2300 % algorithms it is much easier to compute the
2301 % magnitude of a complex number; since these
2302 % algorithms allow to use very large numbers, it
2303 % is not necessary to normalise the complex
2304 % number components to the largest one; therefore
2305 % the code is much simpler than the one used for
2306 % implementing the Newton method used in the
2307 % previous
2308 % versions of this package.
2309 % \begin{macrocode}
2310 \def\ModOfVect#1to#2{\GetCoord(#1)\t@X\t@Y
2311 \edef#2{\fpeval{round(sqrt(\t@X*\t@X + \t@Y*\t@Y),6)}}\ignorespaces}%
2312 % \end{macrocode}
2313 %
2314 % Since the macro for determining the magnitude of
2315 % a vector is available, we can now normalise the
2316 % vector to its magnitude, therefore getting the
2317 % Cartesian form of the direction vector.
2318 % If by any chance the direction of the null
2319 % vector is requested, the output is again the
2320 % null vector, without
2321 % normalisation.
2322 % \begin{macrocode}
2323 \def\DirOfVect#1to#2{\GetCoord(#1)\t@X\t@Y
2324 \ModOfVect#1to\@tempa
2325 \fptestF{\@tempa=\z@}{%
2326 \edef\t@X{\fpeval{round(\t@X/\@tempa,6)}}%
2327 \edef\t@Y{\fpeval{round(\t@Y/\@tempa,6)}}%
2328 }\MakeVectorFrom\t@X\t@Y to#2\ignorespaces}%
2329 % \end{macrocode}
2330 %
2331 % A cumulative macro uses the above ones to
2332 % determine with one call both the magnitude and
2333 % the direction of a complex number.
2334 % The first argument is the input complex number,
2335 % the second its magnitude, and the third is again
2336 % a complex number normalised to unit magnitude
2337 % (unless the input was the null complex number);
2338 % remember always that output quantities must be
2339 % specified with control sequences to be used at a
2340 % later time.
2341 % \begin{macrocode}
2342 \def\ModAndDirOfVect#1to#2and#3{%
2343 \ModOfVect#1to#2%
2344 \DirOfVect#1to#3\ignorespaces}%
2345 % \end{macrocode}
2346 % The next macro computes the magnitude and the
2347 % direction of the difference of two complex
2348 % numbers; the first input argument is the
2349 % minuend, the second is the subtrahend; the
2350 % output quantities are the third argument
2351 % containing the magnitude of the difference and
2352 % the fourth is the direction of the difference.
2353 % Please notice the difference between
2354 % |\ModAndDirOfVect| and |\DistanceAndDirOfVect|;
2355 % the former computes the modulus and the
2356 % direction of a complex number, that is a vector
2357 % with its tail in the origin of the axes; the
2358 % latter measures the length of the difference of
2359 % two complex numbers; in a way |\ModAndDirOfVect|
2360 % \meta{vector} |to| \meta{macro} |and|
2361 % \meta{versor} produces the same result as
2362 % |\DistanceAndDirOfVect| \meta{vector}
2363 % |minus {0,0} to| \meta{macro} |and|
2364 % \meta{versor}.
2365 % Actually |\DistanceAndDirOfVect| yields the
2366 % distance of two complex numbers and the
2367 % direction of their difference.
2368 % The service macro |\SubVect| executes the
2369 % difference of two complex numbers and is
2370 % described further on; its code implements just
2371 % this statement.
2372 % \begin{macrocode}
2373 \def\DistanceAndDirOfVect#1minus#2to#3and#4{%
2374 \SubVect#2from#1to\@tempa
2375 \ModAndDirOfVect\@tempa to#3and#4\ignorespaces}%
2376 % \end{macrocode}
2377 % We now have two macros intended to fetch just
2378 % the real or, respectively, the imaginary part of
2379 % the input complex number.
2380 % \begin{macrocode}
2381 \def\XpartOfVect#1to#2{\GetCoord(#1)#2\@tempa\ignorespaces}%
2382 %
2383 \def\YpartOfVect#1to#2{\GetCoord(#1)\@tempa#2\ignorespaces}%
2384 % \end{macrocode}
2385 % With the next macro we create a direction vector
2386 % (second argument) from a given angle (first
2387 % argument, in degrees).
2388 % \begin{macrocode}
2389 \def\DirFromAngle#1to#2{%
2390 \edef\t@X{\fpeval{round(cosd#1,6)}}%
2391 \edef\t@Y{\fpeval{round(sind#1,6)}}%
2392 \MakeVectorFrom\t@X\t@Y to#2\ignorespaces}%
2393 % \end{macrocode}
2394 %
2395 % Sometimes it is necessary to scale (multiply) a
2396 % vector by an arbitrary real factor; this implies
2397 % scaling both the real and imaginary part of the
2398 % input given vector.
2399 % \begin{macrocode}
2400 \def\ScaleVect#1by#2to#3{\GetCoord(#1)\t@X\t@Y
2401 \edef\t@X{\fpeval{#2 * \t@X}}%
2402 \edef\t@Y{\fpeval{#2 * \t@Y}}%
2403 \MakeVectorFrom\t@X\t@Y to#3\ignorespaces}%
2404 % \end{macrocode}
2405 % Again, sometimes it is necessary to reverse the
2406 % direction of rotation; this implies changing the
2407 % sign of the imaginary part of a given complex
2408 % number; this operation produces the complex
2409 % conjugate of the given number.
2410 % \begin{macrocode}
2411 \def\ConjVect#1to#2{\GetCoord(#1)\t@X\t@Y
2412 \edef\t@Y{-\t@Y}\MakeVectorFrom\t@X\t@Y to#2\ignorespaces}%
2413 % \end{macrocode}
2414 %
2415 % With all the low level elementary operations we
2416 % can now proceed to the definitions of the binary
2417 % operations on complex numbers. We start with the
2418 % addition:
2419 % \begin{macrocode}
2420 \def\AddVect#1and#2to#3{\GetCoord(#1)\tu@X\tu@Y
2421 \GetCoord(#2)\td@X\td@Y
2422 \edef\t@X{\fpeval{\tu@X + \td@X}}%
2423 \edef\t@Y{\fpeval{\tu@Y + \td@Y}}%
2424 \MakeVectorFrom\t@X\t@Y to#3\ignorespaces}%
2425 % \end{macrocode}
2426 % Then the subtraction:
2427 % \begin{macrocode}
2428 \def\SubVect#1from#2to#3{\GetCoord(#1)\tu@X\tu@Y
2429 \GetCoord(#2)\td@X\td@Y
2430 \edef\t@X{\fpeval{\td@X - \tu@X}}%
2431 \edef\t@Y{\fpeval{\td@Y - \tu@Y}}%
2432 \MakeVectorFrom\t@X\t@Y to#3\ignorespaces}%
2433 % \end{macrocode}
2434 %
2435 % For the multiplication we need to split the
2436 % operation according to the fact that we want to
2437 % multiply by the second operand or by the complex
2438 % conjugate of the second operand; it would be
2439 % nice if we could use the usual postfixed
2440 % asterisk notation for the complex conjugate, but
2441 % in the previous versions of this package we
2442 % could not find a simple means for doing so.
2443 % Therefore the previous version contained a
2444 % definition of the |\MultVect| macro that
2445 % followed a simple syntax with an optional
2446 % asterisk \emph{prefixed} to the second operand.
2447 % Its syntax, therefore, allowed the following
2448 % two forms:
2449 %\begin{Sintassi}\ttfamily
2450 %\cs{MultVect}\meta{first factor} by \meta{second factor} to \meta{output macro}\\
2451 %\cs{MultVect}\meta{first factor} by $\star$ \meta{second factor} to \meta{output macro}\\
2452 %\end{Sintassi}
2453 %
2454 % With the availability of the |xparse| package
2455 % and its special argument descriptors for the
2456 % arguments, we were able to define a different
2457 % macro, |\Multvect|, with both optional positions
2458 % for the asterisk: \emph{after} and
2459 % \emph{before}; its syntax allows the
2460 % following four forms:
2461 %\begin{Sintassi}
2462 %\cs{Multvect}\marg{first factor}\marg{second factor}\meta{output macro}
2463 %\cs{Multvect}\marg{first factor}$\star$\marg{second factor}\meta{output macro}
2464 %\cs{Multvect}\marg{first factor}\marg{second factor}$\star$\meta{output macro}
2465 %\cs{Multvect}\marg{first factor}$\star$\marg{second factor}$\star$\meta{output macro}
2466 %\end{Sintassi}
2467 %
2468 % Nevertheless we maintain a sort of interface
2469 % between the old syntax and the new one, so that
2470 % the two old forms can be mapped to two suitable
2471 % forms of the new syntax. Old documents are still
2472 % compilable; users who got used to the old syntax
2473 % can maintain their habits.
2474 %
2475 % First we define the new macro: it receives the
2476 % three arguments, the first two as balanced
2477 % texts; the last one must always be a macro,
2478 % therefore a single (complex) token that does not
2479 % require braces, even if it is not forbidden
2480 % to use them. Asterisks are optional. The input
2481 % arguments are transformed into couples of
2482 % argument and modulus; this makes multiplication
2483 % much simpler as the output modulus is just the
2484 % product of the input moduli, while the output
2485 % argument is just the sum of input arguments;
2486 % eventually it is necessary to transform this
2487 % polar version of the result into an ordered
2488 % couple of cartesian values to be assigned to the
2489 % output macro. In order to maintain the single
2490 % macros pretty simple we need a couple of service
2491 % macros and a named counter. We use |\ModOfVect|
2492 % previously defined, and a new macro
2493 % |\ModAndAngleOfVect| with the following syntax:
2494 %\begin{Sintassi}\ttfamily \cs{ModAndAngleOfVect}\meta{input vector} to \meta{output modulus} and \meta{output angle in degrees}
2495 %\end{Sintassi}
2496 % The output quantities are always macros, so they
2497 % do not need balanced bracing; angles in degrees
2498 % are always preferred because, in case of
2499 % necessity, they are easy to reduce to the range
2500 % $-180^\circ < \alpha \leq +180^\circ$.
2501 % \begin{macrocode}
2502 \def\ModAndAngleOfVect#1to#2and#3{\ModOfVect#1to#2\relax
2503 \ArgOfVect#1to#3\ignorespaces}
2504 % \end{macrocode}
2505 % We name a new service counter
2506 % \begin{macrocode}
2507 \newcount\MV@C
2508 % \end{macrocode}
2509 %
2510 % Now comes the real macro\footnote{A warm
2511 % thank-you to Enrico Gregorio, who kindly
2512 % attracted my attention on the necessity of
2513 % braces when using this kind of macro; being
2514 % used to the syntax with delimited arguments I
2515 % had taken the bad habit of avoiding braces.
2516 % Braces are very important, but the syntax of the
2517 % original \TeX\ language, that did not
2518 % have available the L3 one, spoiled me with the
2519 % abuse of delimited arguments.}:
2520 % \begin{macrocode}
2521 \NewDocumentCommand\Multvect{m s m s m}%
2522 {\ModAndAngleOfVect#1to\MV@uM and\MV@uA
2523 \ModAndAngleOfVect#3to\MV@dM and\MV@dA
2524 \fptestT{%
2525 \IfBooleanTF{#2}{1}{0}+\IfBooleanTF{#4}{1}{0}!=0}%
2526 {\edef\MV@dA{-\MV@dA}}%
2527 \edef\MV@rM{\fpeval{round((\MV@uM*\MV@dM),6)}}%
2528 \edef\MV@rA{\fpeval{round((\MV@uA+\MV@dA),6)}}%
2529 \edef#5{\fpeval{\MV@rM*cosd\MV@rA},\fpeval{\MV@rM*sind\MV@rA}}}
2530
2531 % \end{macrocode}
2532 %
2533 % In order to remain backward compatible, the
2534 % macro reduces to two simple macros that take
2535 % the input delimited arguments and passes them
2536 % in braced form to the above
2537 % general macro:
2538 % \begin{macrocode}
2539 \def\MultVect#1by{\@ifstar{\let\MV@c1\@MultVect#1 by}{\let\MV@c0\@MultVect#1by}}
2540
2541 \def\@MultVect#1by#2to#3{%
2542 \fptest{\MV@c!=0}{\Multvect{#1}{#2}*{#3}}%
2543 {\Multvect{#1}{#2}{#3}}%
2544 }%
2545 % \end{macrocode}
2546 % Testing of both the new and the old macros shows
2547 % that they behave as expected, although, using
2548 % real numbers for trigonometric functions, some
2549 % small rounding unit on the sixth decimal digit
2550 % still remains; nothing to worry about with a
2551 % package used for drawing.
2552 %
2553 %
2554 % The division of two complex numbers implies
2555 % scaling down the dividend by the magnitude of
2556 % the divisor and by rotating the dividend scaled
2557 % vector by the conjugate versor of the divisor:
2558 %\[
2559 % \frac{\vec{N}}{\vec{D}}= \frac{\vec{N}}{M\vec{u}}=
2560 % \frac{\vec{N}}{M}\vec{u}^{\mkern2mu\star}
2561 %\]
2562 % therefore:
2563 % \begin{macrocode}
2564 \def\DivVect#1by#2to#3{\Divvect{#1}{#2}{#3}}
2565
2566 \NewDocumentCommand \Divvect{m m m}%
2567 {\ModOfVect#2to\DV@dD
2568 \fptest{\DV@dD=0}{\PackageWarning{curve2e}{^^J%
2569 ******************************************^^J%
2570 Division by zero!^^J%
2571 Result set to maxdimen in scaled points^^J%
2572 ******************************************^^J}%
2573 \edef#3{\fpeval{\maxdimen*2**16},0}}%
2574 {\edef\DV@sF{\fpeval{1/\DV@dD**2}}%
2575 \Multvect{#2}{\DV@sF,0}{\DV@dD}%
2576 \Multvect{#1}{\DV@dD}*{#3}}}%
2577 % \end{macrocode}
2578 % Macros |\DivVect| and |\Divvect| are almost
2579 % equivalent; the second is possibly slightly more
2580 % robust. They match the corresponding macros for
2581 % multiplying two vectors.
2582 % Attention! The new macro |\Divvect| performs a
2583 % test on a zero valued divisor; in case it issues
2584 % a warning, and sets the result as the maxdimen
2585 % value expressed in scaled points and it does not
2586 % stop the job; the following results are going to
2587 % be very wrong, but the strongly emphasised
2588 % warning message in the console and\slash or in
2589 % the log file warns users to review their data.
2590 %
2591 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2592 % \subsection{Arcs and curved vectors}
2593 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2594 % We are now in the position of really doing
2595 % graphic work.
2596 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2597 % \subsubsection{Arcs}
2598 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2599 % We provide two ways to produce arcs so as to use
2600 % different although similar macros; they follow
2601 % the following syntax:
2602 %\begin{Sintassi}
2603 % \cs{Arc}\parg{center coordinates}\parg{starting point cartesian coordinates}\marg{angle}
2604 %
2605 % \cs{Arc}\parg{centercoordinates}\parg{starting point polar coordinates}\marg{ange}
2606 %\end{Sintassi}
2607 %
2608 % The difference between these macros and that of
2609 % the standard \pack{pict2e} package assumes that
2610 % these new ones are easier to use. The latter
2611 % does no require the center coordinates and must
2612 % be put in place with a |\put| command; its
2613 % reference point becomes the arc center; is it
2614 % necessary to specify the coordinates of both the
2615 % starting and the ending point angles and the
2616 % radius; this implies that the user specifies
2617 % compatible data; not too difficult, but it is
2618 % delicate for choosing the correct angles and the
2619 % correct distance from the implicit center.
2620 %
2621 % These new alternative macros leave the
2622 % calculation of the radius to the software and
2623 % the Pythagorean distance between the center and
2624 % the starting point, and require the
2625 % specification of the rotation angle; but even
2626 % in this way, used in the previous version of
2627 % this package, the cartesian coordinates of the
2628 % staring point are very easy when they imply
2629 % an angle of an integer number of right angles
2630 % starting from the $x$ axis, but they become not
2631 % that easy when the center and the starting point
2632 % don't share either their abscissas or their
2633 % ordinates. The new alternate syntax uses the
2634 % polar coordinates; their reference point is the
2635 % arc center and it appears to be easier to
2636 % specify the position of the starting point,
2637 % because its angle and it distance are both
2638 % specified by the user. With the drawings made
2639 % with the extended |picture| environment it seems
2640 % to be easier to have available both the absolute
2641 % cartesian specification and the centred polar
2642 % specification.
2643 %
2644 % Therefore tracing a circular arc of arbitrary
2645 % center, arbitrary starting point and arbitrary
2646 % aperture; the first macro checks the aperture;
2647 % if this is not zero it actually proceeds with
2648 % the necessary computations, otherwise it does
2649 % nothing.
2650 % \begin{macrocode}
2651 \def\Arc(#1)(#2)#3{\begingroup
2652 \edef\tempG{#3}%
2653 \fptestF{#3=0}{\@Arc(#1)(#2)}}%
2654 % \end{macrocode}
2655 % The aperture is already memorised in |\@tdA|;
2656 % the |\@Arc| macro receives the center
2657 % coordinates in the first argument and the
2658 % coordinates of the starting point in the second
2659 % argument. For easier calculation we assume that
2660 % the angles are positive when rotating
2661 % counterclockwise; if the user specification is
2662 % negative, we change sign, but remember the
2663 % original sign so that in the end the arc will
2664 % floe=w in the right direction
2665 % \begin{macrocode}
2666
2667 \def\@Arc(#1)(#2){%
2668 \fptest{\tempG>\z@}%
2669 {\let\Segno+}%
2670 {\let\Segno-%
2671 \edef\tempG{\fpeval{abs(\tempG)}}%
2672 }%
2673 % \end{macrocode}
2674 % The rotation angle sign is memorised in |\Segno|
2675 % and |\@tdA| now contains the absolute value of
2676 % the arc aperture.
2677 %
2678 % If the rotation angle is larger than $360^\circ$
2679 % a message is issued that informs the user that
2680 % the angle will be reduced modulo $360^\circ$;
2681 % this operation is performed by successive
2682 % subtractions rather than with modular
2683 % arithmetics on the assumption that in general
2684 % one subtraction suffices.
2685 % \begin{macrocode}
2686 \fptestT{\tempG>360}{%
2687 \PackageWarning{curve2e}%
2688 {The arc aperture is \tempG\space degrees
2689 and gets reduced^^J%
2690 to the interval 0--360 taking the sign into
2691 consideration}%
2692 \edef\tempG{\Modulo{\tempG}{360}}%
2693 }%
2694 % \end{macrocode}
2695 % Now the radius is determined and the drawing
2696 % point is moved to the starting point.
2697 % \begin{macrocode}
2698 \GetCoord(#2)\@pPunX\@pPunY
2699 \ifCV@polare
2700 \ModOfVect#2to\@Raggio
2701 \CopyVect#1to\@Cent
2702 \AddVect#2and#1to\@pPun% starting point
2703 \GetCoord(\@pPun)\@pPunX\@pPunY
2704 \else
2705 \SubVect#2from#1to\@V
2706 \ModOfVect\@V to\@Raggio
2707 \CopyVect#2to\@pPun
2708 \CopyVect#1to\@Cent
2709 \GetCoord(\@pPun)\@pPunX\@pPunY
2710 \fi
2711 % \end{macrocode}
2712 % From now on it's better to define a new macro
2713 % that will be used also in the subsequent macros
2714 % that draw arcs; here we already have the
2715 % starting point coordinates and the angle to
2716 % draw the arc, therefore we just call the new
2717 % macro, stroke the line and exit.
2718 % \begin{macrocode}
2719 \@@Arc\strokepath\endgroup\ignorespaces}%
2720 % \end{macrocode}
2721 % And the new macro |\@@Arc| starts with moving
2722 % the drawing point to the first point and does
2723 % everything needed for drawing the requested arc,
2724 % except stroking it; we leave the |\strokepath|
2725 % command to the completion of the calling macro
2726 % and nobody forbids to use the |\@@Arc| macro for
2727 % other purposes.
2728 % \begin{macrocode}
2729 \def\@@Arc{%
2730 \pIIe@moveto{\@pPunX\unitlength}%
2731 {\@pPunY\unitlength}%
2732 % \end{macrocode}
2733 % If the aperture is larger than $180^\circ$ it
2734 % traces a% semicircle in the right direction and
2735 % correspondingly reduces
2736 % the overall aperture.
2737 % \begin{macrocode}
2738 \fptestT{\tempG>180}{%
2739 \edef\tempG{\fpeval{\tempG-180}}%
2740 \SubVect\@pPun from\@Cent to\@V
2741 \AddVect\@V and\@Cent to\@sPun
2742 \Multvect{\@V}{0,-1.3333333}{\@V}%
2743 \if\Segno-\ScaleVect\@V by-1to\@V\fi
2744 \AddVect\@pPun and\@V to\@pcPun
2745 \AddVect\@sPun and\@V to\@scPun
2746 \GetCoord(\@pcPun)\@pcPunX\@pcPunY
2747 \GetCoord(\@scPun)\@scPunX\@scPunY
2748 \GetCoord(\@sPun)\@sPunX\@sPunY
2749 \pIIe@curveto{\@pcPunX\unitlength}%
2750 {\@pcPunY\unitlength}%
2751 {\@scPunX\unitlength}%
2752 {\@scPunY\unitlength}%
2753 {\@sPunX\unitlength}%
2754 {\@sPunY\unitlength}%
2755 \CopyVect\@sPun to\@pPun}%
2756 % \end{macrocode}
2757 % If the remaining aperture is not zero it
2758 % continues tracing the rest of the arc. Here we
2759 % need the extrema of the arc and the coordinates
2760 % of the control points of the Bézier cubic spline
2761 % that traces the arc. The control points lay on
2762 % the perpendicular to the vectors that join the
2763 % arc center to the% starting and end points
2764 % respectively.
2765 %
2766 % With reference to figure~12 of the
2767 % |curve2e-manual.pdf| file, the points $P_1$ and
2768 % $P_2$ are the arc end-points; $C_1$ and $C_2$
2769 % are the Bézier-spline control-points; $P$ is the
2770 % arc mid-point, that should be distant from the
2771 % center of the arc the same as $P_1$ and $P_2$.
2772 % Choosing a convenient orientation of the arc
2773 % relative to the coordinate axes, the coordinates
2774 % of these five points are:
2775 %\begin{align*}
2776 %P_1 &= (-R\sin\theta, 0)\\
2777 %P_2 &= (R\sin\theta, 0)\\
2778 %C_1 &= (-R\sin\theta+K\cos\theta, K\sin\theta)\\
2779 %C_2 &= (R\sin\theta-K\cos\theta, K\sin\theta)\\
2780 %P &= (0, R(1-\cos\theta))
2781 %\end{align*}
2782 % The Bézier cubic spline interpolating the end
2783 % and mid points is given by the parametric
2784 % equation:
2785 %\begin{equation*}
2786 %P= P_1(1-t)^3 + 3C_1 (1-t)^2t + 3C_2 (1-t)t^2 + P_2t^3
2787 %\end{equation*}
2788 % where the mid point is obtained for $t=0.5$;
2789 % the four coefficients then become
2790 % $1/8, 3/8, 3/8, 1/8$ and the only unknown
2791 % remains $K$. Solving for $K$ we obtain the
2792 % formula
2793 %\begin{equation}\label{equ:corda}
2794 % K= \frac{4}{3}\,\frac{1-\cos\theta}{\sin\theta}R
2795 % =\frac{4}{3}\,\frac{1-\cos\theta}{\sin^2\theta}s
2796 %\end{equation}
2797 % where $\theta$ is half the arc aperture, $R$ is
2798 % its radius, and $s$ is half the arc chord.
2799 % \begin{macrocode}
2800 \fptestT{\tempG>0}{%
2801 \DirFromAngle\tempG to\@Dir
2802 \if\Segno-\ConjVect\@Dir to\@Dir \fi
2803 \SubVect\@Cent from\@pPun to\@V
2804 \Multvect{\@V}{\@Dir}\@V
2805 \AddVect\@Cent and\@V to\@sPun
2806 \edef\tempG{\fpeval{\tempG/2}}%
2807 \DirFromAngle\tempG to\@Phimezzi
2808 \GetCoord(\@Phimezzi)\@cosphimezzi\@sinphimezzi
2809 \@tdB=1.3333333\p@ \@tdB=\@Raggio\@tdB
2810 \@tdC=\p@ \advance\@tdC -\@cosphimezzi\p@
2811 \Numero\@tempa\@tdC
2812 \@tdB=\@tempa\@tdB
2813 \DividE\@tdB by\@sinphimezzi\p@ to\@cZ
2814 \ScaleVect\@Phimezzi by\@cZ to\@Phimezzi
2815 \ConjVect\@Phimezzi to\@mPhimezzi
2816 \if\Segno-%
2817 \let\@tempa\@Phimezzi
2818 \let\@Phimezzi\@mPhimezzi
2819 \let\@mPhimezzi\@tempa
2820 \fi
2821 \SubVect\@sPun from\@pPun to\@V
2822 \DirOfVect\@V to\@V
2823 \Multvect{\@Phimezzi}{\@V}\@Phimezzi
2824 \AddVect\@sPun and\@Phimezzi to\@scPun
2825 \ScaleVect\@V by-1to\@V
2826 \Multvect{\@mPhimezzi}{\@V}\@mPhimezzi
2827 \AddVect\@pPun and\@mPhimezzi to\@pcPun
2828 \GetCoord(\@pcPun)\@pcPunX\@pcPunY
2829 \GetCoord(\@scPun)\@scPunX\@scPunY
2830 \GetCoord(\@sPun)\@sPunX\@sPunY
2831 \pIIe@curveto{\@pcPunX\unitlength}%
2832 {\@pcPunY\unitlength}%
2833 {\@scPunX\unitlength}%
2834 {\@scPunY\unitlength}%
2835 {\@sPunX\unitlength}%
2836 {\@sPunY\unitlength}%
2837 }}%
2838 % \end{macrocode}
2839 % It is important to remember that the cubic spline
2840 % used to draw the arc is not the equation of an
2841 % arc circumference, but a very good approximation;
2842 % the approximation error is zero at the arc end
2843 % points and at the midpoint by construction. The
2844 % approximation error is maximum more or less at
2845 % the mid point between $\textsf{P}_1$ and
2846 % $\textsf{P}$, and between $\textsf{P}$ and
2847 % $\textsf{P}_2$.
2848 % See figure~\ref{fig:arc error}, where the red
2849 % line should be much more close to the desired
2850 % arc, and the black arc is the one obtained with
2851 % the \cs{Arc} macro.
2852 %\begin{figure}\centering
2853 %\unitlength=0.00925\textwidth
2854 %\begin{picture}(100,50)(-50,0)
2855 %{\linethickness{1pt}\Arc(0,0)(50,0){180}}\relax
2856 %{\color{red}\Arc(0,0)(50,0){90}\relax
2857 % \Arc(0,0)(0,50){90}}\relax
2858 %\Zbox(50,0)[l]{P_2}[1]
2859 %\Zbox(0,50)[b]{P}[1]
2860 %\Zbox(-50,0)[r]{P_1}[1]
2861 %\Zbox(0,0)[br]{O}[1]
2862 %\VVECTOR(0,0)(45:50)\Zbox(45:25)[tl]{R}[0]
2863 %\end{picture}
2864 %\caption{Approximation of a Bézier arc (black) to a circumference arc (red)}%
2865 %\label{fig:arc error}
2866 %\end{figure}
2867 %
2868 % As it can be seen in figure~\ref{fig:arc error}
2869 % the error is hardly noticed and in most
2870 % circumstances the error is negligible, since it
2871 % amounts to about 2\% of the radius with an arc
2872 % opening of 180°; it becomes absolutely invisible
2873 % if the arc aperture gets smaller and smaller; in
2874 % a 90° arc the error exists but it is invisible.
2875 % In rare circumstances it might be necessary to
2876 % split the total arc in two or three sub-arcs.
2877 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2878 % \subsubsection{Arc vectors}
2879 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2880 % We exploit much of the above definitions of the
2881 % |\Arc| macro for drawing circular arcs with an
2882 % arrow tip at one or both ends; the first macro
2883 % |\VectorArc| draws an arrow at the ending point
2884 % of the arc; the second macro |\VectorARC| (with
2885 % alias |\VVectorArc|) draws arrows at both ends;
2886 % the arrows tips have the same shape as those for
2887 % vectors; actually they are drawn by putting a
2888 % vector of zero length at the proper arc end(s),
2889 % therefore they are styled as traditional \LaTeX\
2890 % or PostScript arrows according to the specific
2891 % option to the \texttt{pict2e} package.
2892 %
2893 % It goes by itself that the ending point may be
2894 % specified as absolute cartesian coordinates or
2895 % centred polar ones, the same as it was described
2896 % above for the arcs without vector tips.
2897 %
2898 % But the arc drawing done here shortens it so as
2899 % not to overlap on the arrow tip(s); the only
2900 % arrow tip (or both tips) are also lightly tilted
2901 % in order to avoid the impression of a corner
2902 % where the arc enters the arrow tip.
2903 %
2904 % All these operations require a lot of “playing”
2905 % with vector directions, but even if the
2906 % operations are numerous, they do not do anything
2907 % else but: (a) determining the end point and
2908 % its direction; (b) determining the arrow length
2909 % as an angular quantity, i.e. the arc amplitude
2910 % that must be subtracted from the total arc to be
2911 % drawn; (c) the direction of the arrow should
2912 % correspond to the tangent to the arc at the point
2913 % where the arrow tip is attached; (d) tilting the
2914 % arrow tip by half its angular amplitude; (e)
2915 % determining the resulting position and direction
2916 % of the arrow tip so as to draw a zero length
2917 % vector; (f\/) possibly repeating the same
2918 % procedure for the other end of the arc; (g)
2919 % shortening the total arc angular amplitude by the
2920 % amount of the arrow tip(s) already set, and
2921 % finally (h) drawing the circular arc that joins
2922 % the starting point to the final arrow or one
2923 % arrow to the other one.
2924 %
2925 % The calling macros are very similar to the |\Arc|
2926 % macro initial one:
2927 % \begin{macrocode}
2928 \def\VectorArc(#1)(#2)#3{\begingroup
2929 \def\tempG{#3}%
2930 \fptestF{#3=0}{\@VArc(#1)(#2)}}%
2931 % \end{macrocode}
2932 %
2933 % The single arrow tipped arc is defined with the
2934 % following long macro where all the described
2935 % operations are performed more or less in the
2936 % described succession; probably the macro requires
2937 % a little cleaning, but since it works fine we did
2938 % not try to optimise it for time or number of
2939 % tokens. The final part of the macro is almost
2940 % identical to that of the plain arc; the
2941 % beginning also is quite similar. The central part
2942 % is dedicated to the positioning of the arrow tip
2943 % and to the necessary calculations for determining
2944 % the tip tilt and the reduction of the total arc
2945 % length; pay attention that the arrow length,
2946 % stored in |\@tdE| is a real length, while the
2947 % radius stored in |\@Raggio| is just a multiple of
2948 % the |\unitlength|, so that the division (that
2949 % yields a good angular approximation to the
2950 % arrow length as seen from the center of the
2951 % arc) must be done with real lengths. The already
2952 % defined |\@@Arc| macro actually draws the curved
2953 % vector stem without stroking it.
2954 % \begin{macrocode}
2955 \def\@VArc(#1)(#2){%
2956 \fptest{\tempG>\z@}%
2957 {\let\Segno+}%
2958 {\let\Segno-%
2959 \edef\tempG{\fpeval{abs(\tempG)}}}%
2960 \let\@gradi\tempG
2961 \fptestT{\tempG>360}
2962 {\PackageWarning{curve2e}%
2963 {The arc aperture is \tempG\space degrees
2964 and gets reduced^^J%
2965 to the range 0--360 taking the sign into
2966 consideration}%
2967 \edef\tempG{\Modulo{\tempG}{360}}%
2968 }%
2969 \let\@gradi\tempG
2970 \GetCoord(#2)\@pPunX\@pPunY
2971 \ifCV@polare
2972 \ModOfVect#2to\@Raggio \CopyVect#2to\@V
2973 \CopyVect#1to\@Cent
2974 \AddVect#2and#1to\@pPun% punto iniziale
2975 \GetCoord(\@pPun)\@pPunX\@pPunY
2976 \else
2977 \SubVect#1from#2to\@V \ModOfVect\@V to\@Raggio
2978 \CopyVect#2to\@pPun
2979 \CopyVect#1to\@Cent \GetCoord(\@pPun)\@pPunX\@pPunY
2980 \fi
2981 \@tdE=\pIIe@FAW\@wholewidth \@tdE=\pIIe@FAL\@tdE
2982 \DividE\@tdE by \@Raggio\unitlength to\DeltaGradi
2983 \@tdD=\DeltaGradi\p@
2984 \@tdD=57.29578\@tdD \Numero\DeltaGradi\@tdD
2985 \@tdD=\ifx\Segno--\fi\@gradi\p@ \Numero\@tempa\@tdD
2986 \DirFromAngle\@tempa to\@Dir
2987 \Multvect{\@V}{\@Dir}\@sPun
2988 \edef\@tempA{\ifx\Segno-\m@ne\else\@ne\fi}%
2989 \Multvect{\@sPun}{0,\@tempA}\@vPun
2990 \DirOfVect\@vPun to\@Dir
2991 \AddVect\@sPun and #1 to \@sPun
2992 \GetCoord(\@sPun)\@tdX\@tdY
2993 \@tdD\ifx\Segno--\fi\DeltaGradi\p@
2994 \@tdD=.5\@tdD \Numero\DeltaGradi\@tdD
2995 \DirFromAngle\DeltaGradi to\@Dird
2996 \Multvect{\@Dir}*{\@Dird}\@Dir%
2997 \GetCoord(\@Dir)\@xnum\@ynum
2998 \put(\@tdX,\@tdY){\vector(\@xnum,\@ynum){0}}%
2999 \@tdE =\ifx\Segno--\fi\DeltaGradi\p@
3000 \advance\@tdA -\@tdE \Numero\@gradi\@tdA
3001 \CopyVect#1to\@Cent \GetCoord(\@pPun)\@pPunX\@pPunY
3002 \@@Arc
3003 \strokepath\endgroup\ignorespaces}%
3004 %
3005 % \end{macrocode}
3006 %
3007 % The macro for the arc terminated with arrow tips
3008 % at both ends is again very similar, but it is
3009 % necessary to repeat the arrow tip positioning
3010 % also at the starting point. The |\@@Arc| macro
3011 % draws the curved stem.
3012 % \begin{macrocode}
3013 %
3014 \def\VectorARC(#1)(#2)#3{\begingroup
3015 \def\tempG{#3}%
3016 \fptestF{#3=0}{\@VARC(#1)(#2)}}%
3017 %
3018 \let\VVectorArc\VectorARC% alias
3019 %
3020
3021 \def\@VARC(#1)(#2){%
3022 \fptest{\tempG>\z@}%
3023 {\let\Segno+}%
3024 {\let\Segno-%
3025 \edef\tempG{\fpeval{abs(\tempG)}}}%
3026 \let\@gradi\tempG
3027 \fptestT{\tempG>360}{%
3028 \PackageWarning{curve2e}%
3029 {The arc aperture is \@gradi\space degrees
3030 and gets reduced\MessageBreak%
3031 to the range 0--360 taking the sign into
3032 consideration}%
3033 \edef\tempG{\Modulo{\tempG}{360}\p@}}
3034 \@tdA=\tempG\p@ \let\@gradi\tempG
3035 \GetCoord(#2)\@pPunX\@pPunY
3036 \ifCV@polare
3037 \ModOfVect#2to\@Raggio \CopyVect#2to\@V
3038 \CopyVect#1to\@Cent
3039 \AddVect#2and#1to\@pPun% punto iniziale
3040 \GetCoord(\@pPun)\@pPunX\@pPunY
3041 \else
3042 \SubVect#1from#2to\@V \ModOfVect\@V to\@Raggio
3043 \CopyVect#2to\@pPun
3044 \CopyVect#1to\@Cent \GetCoord(\@pPun)\@pPunX\@pPunY
3045 \fi
3046 %
3047 \@tdE=\pIIe@FAW\@wholewidth \@tdE=\pIIe@FAL\@tdE
3048 \DividE\@tdE by \@Raggio\unitlength to\DeltaGradi
3049 \edef\DeltaGradi{\fpeval{57.29578*\DeltaGradi}}
3050 \@tdD=\if\Segno--\fi\@gradi\p@ \Numero\@tempa\@tdD
3051 \DirFromAngle\@tempa to\@Dir
3052 \Multvect{\@V}{\@Dir}\@sPun% correct the end point
3053 \edef\@tempA{\if\Segno--\fi1}%
3054 \Multvect{\@sPun}{0,\@tempA}\@vPun
3055 \DirOfVect\@vPun to\@Dir
3056 \AddVect\@sPun and #1 to \@sPun
3057 \GetCoord(\@sPun)\@tdX\@tdY
3058 \@tdD\if\Segno--\fi\DeltaGradi\p@
3059 \@tdD=.5\@tdD \Numero\@tempB\@tdD
3060 \DirFromAngle\@tempB to\@Dird
3061 \Multvect{\@Dir}*{\@Dird}\@Dir
3062 \GetCoord(\@Dir)\@xnum\@ynum
3063 \put(\@tdX,\@tdY){\vector(\@xnum,\@ynum){0}}% end point arrow tip
3064 \@tdE =\DeltaGradi\p@
3065 \advance\@tdA -2\@tdE \Numero\@gradi\@tdA
3066 \CopyVect#1to\@Cent \GetCoord(\@pPun)\@pPunX\@pPunY
3067 \SubVect\@Cent from\@pPun to \@V
3068 \edef\@tempa{\if\Segno-\else-\fi\@ne}%
3069 \Multvect{\@V}{0,\@tempa}\@vPun
3070 \@tdE\if\Segno--\fi\DeltaGradi\p@
3071 \Numero\@tempB{0.5\@tdE}%
3072 \DirFromAngle\@tempB to\@Dird
3073 \Multvect{\@vPun}{\@Dird}\@vPun% correct the starting point
3074 \DirOfVect\@vPun to\@Dir\GetCoord(\@Dir)\@xnum\@ynum
3075 \put(\@pPunX,\@pPunY){\vector(\@xnum,\@ynum){0}}% starting point arrow tip
3076 \edef\@tempa{\if\Segno--\fi\DeltaGradi}%
3077 \DirFromAngle\@tempa to \@Dir
3078 \SubVect\@Cent from\@pPun to\@V
3079 \Multvect{\@V}{\@Dir}\@V
3080 \AddVect\@Cent and\@V to\@pPun
3081 \GetCoord(\@pPun)\@pPunX\@pPunY
3082 \@@Arc
3083 \strokepath\endgroup\ignorespaces}%
3084
3085 % \end{macrocode}
3086 %
3087 % It must be understood that the curved vectors,
3088 % i.e.~the above circular arcs terminated with an
3089 % arrow tips at one or both ends, have a nice
3090 % appearance only if the arc radius is not too
3091 % small, or, said in a different way, if the arrow
3092 % tip angular width does not exceed a maximum of a
3093 % dozen degrees (and this is probably already too
3094 % much); the tip does not get curved as the arc is,
3095 % therefore there is not a smooth transition from
3096 % the curved stem and the straight arrow tip if
3097 % this one is large in comparison to the arc
3098 % radius.
3099 %
3100 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3101 % \subsection{General curves}
3102 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3103 % The most used method to draw curved lines with
3104 % computer programs is to connect several simple
3105 % curved lines, general “arcs”, one to another
3106 % generally maintaining the same tangent at the
3107 % junction. If the direction changes we are dealing
3108 % with a cusp.
3109 %
3110 % The simple general arcs that are directly
3111 % implemented in every program that displays
3112 % typeset documents, are those drawn with the
3113 % parametric curves called \emph{Béźier splines};
3114 % given a sequence of points in the $x,y$ plane,
3115 % say $P_0, P_1, P_2, P_3, \dots$ (represented as
3116 % coordinate pairs, i.e. by complex numbers), the
3117 % most common Bézier splines are the
3118 % following ones:
3119 % \begin{align}
3120 % \mathcal{B}_1 &= P_0(1-t) + P_1t \label{equ:B-1} \\
3121 % \mathcal{B}_2 &= P_0(1-t)^2 + P_1 2(1-t)t + P_2t^2 \label{equ:B-2} \\
3122 % \mathcal{B}_3 &= P_0(1-t)^3 + P_1 3(1-t)^2t +P_2 3(1-t)t^2 +P_3t^3
3123 % \label{equ:B-3}
3124 % \end{align}
3125 %
3126 % All these splines depend on parameter $t$; they
3127 % have the property that for $t=0$ each line starts
3128 % at the first point, while for $t=1$ they reach
3129 % the last point; in each case the generic point
3130 % $P$ on each curve takes off with a direction
3131 % that points to the next point, while it lands on
3132 % the destination point with a direction coming
3133 % from the penultimate point; moreover, when $t$
3134 % varies from 0 to 1, the curve arc is completely
3135 % contained within the convex hull formed by the
3136 % polygon that has the spline points as vertices.
3137 %
3138 % Last but not least first order splines implement
3139 % just straight lines and they are out of question
3140 % for what concerns maxima, minima, inflection
3141 % points and the like. Quadratic splines draw
3142 % just parabolas, therefore they draw arcs that
3143 % have the concavity just on one side of the path;
3144 % therefore no inflection points. Cubic splines are
3145 % extremely versatile and can draw lines with
3146 % maxima, minima and inflection points.
3147 % Virtually a multi-arc curve may be drawn by a set
3148 % of cubic splines as well as a set of quadratic
3149 % splines (fonts are a good example: Adobe Type~1
3150 % fonts have their contours described by cubic
3151 % splines, while TrueType fonts have their contours
3152 % described with quadratic splines; at naked eye it
3153 % is impossible to notice the difference).
3154 %
3155 % Each program that processes the file to be
3156 % displayed is capable of drawing first order
3157 % Bézier splines (segments) and third order Bézier
3158 % splines, for no other reason, at least, because
3159 % they have to draw vector fonts whose contours are
3160 % described by Bézier splines; sometimes they have
3161 % also the program commands to draw second order
3162 % Bézier splines, but not always these machine code
3163 % routines are available to the user for general
3164 % use. For what concerns |pdftex|, |xetex| and
3165 % |luatex|, they have the user commands for
3166 % straight lines and cubic arcs. At least with
3167 % |pdftex|, quadratic arcs must be simulated with
3168 % a clever use of third order Bézier splines.
3169 %
3170 % Notice that the \LaTeXe\ environment |picture|
3171 % by itself is capable of drawing both cubic and
3172 % quadratic Bézier splines as single arcs; but it
3173 % resorts to “poor man” solutions. The |pict2e|
3174 % package removes all the old limitations and
3175 % implements the interface macros for sending the
3176 % driver the necessary drawing information,
3177 % including the transformation from typographical
3178 % points (72.27\,pt/inch) to PostScript big points
3179 % (72\,bp/inch). But for what concerns the
3180 % quadratic spline it resorts to the clever use of
3181 % a cubic spline.
3182 %
3183 % Therefore here we treat first the drawings that
3184 % can be made with cubic splines; then we describe
3185 % the approach to quadratic splines.
3186 %
3187 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3188 %\subsection{Cubic splines}
3189 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3190 % Now we define a macro for tracing a general, not
3191 % necessarily circular, arc. This macro resorts to
3192 % a general triplet of macros with which it is
3193 % possible to draw almost anything. It traces a
3194 % single Bézier spline from a first point where the
3195 % tangent direction is specified to a second point
3196 % where again it is specified the tangent
3197 % direction. Actually this is a special (possibly
3198 % useless) case where the general |\curveto| macro
3199 % of |pict2e| could do the same or a better
3200 % job. In any case\dots
3201 % \begin{macrocode}
3202 \def\CurveBetween#1and#2WithDirs#3and#4{%
3203 \StartCurveAt#1WithDir{#3}\relax
3204 \CurveTo#2WithDir{#4}\CurveFinish\ignorespaces
3205 }%
3206 % \end{macrocode}
3207 %
3208 % Actually the above macro is a special case of
3209 % concatenation of the triplet formed by macros
3210 % |\StartCurve|, |\CurveTo| and |\CurveFinish|; the
3211 % second macro can be repeated an arbitrary number
3212 % of times. In any case the directions specified
3213 % with the direction arguments the angle between
3214 % the indicated tangent and the arc chord may give
3215 % raise to some little problems when they are very
3216 % close to 90° in absolute value. Some control is
3217 % exercised on these values, but some tests might
3218 % fail if the angle derives from other
3219 % calculations; this is a good place to use polar
3220 % forms for the direction vectors. The same
3221 % comments apply also to the more general macro
3222 % |\Curve|,
3223 %
3224 % The first macro initialises the drawing and the
3225 % third one strokes it; the real work is done by
3226 % the second macro. The first macro initialises the
3227 % drawing but also memorises the starting
3228 % direction; the second macro traces the current
3229 % Bézier arc reaching the destination point with
3230 % the specified direction, but memorises this
3231 % direction as the one with which to start the next
3232 % arc. The overall curve is then always smooth
3233 % because the various Bézier arcs join with
3234 % continuous tangents.
3235 % If a cusp is desired it is necessary to change
3236 % the memorised direction at the end of the arc
3237 % before the cusp and before the start of the next
3238 % arc; this is better than stroking the curve
3239 % before the cusp and then starting another curve,
3240 % because the curve joining point at the cusp is
3241 % not stroked with the same command, therefore we
3242 % get two superimposed curve terminations.
3243 % To avoid this imperfection, we need another small
3244 % macro |\ChangeDir| to perform this task.
3245 %
3246 % It is necessary to recall that the direction
3247 % vectors point to the control points, but they do
3248 % not define the control points themselves; they
3249 % are just directions, or, even better, they are
3250 % simply vectors with the desired direction; the
3251 % macros themselves provide to the normalisation
3252 % and memorisation.
3253 %
3254 % The next desirable feature would be to design a
3255 % macro that accepts optional node directions and
3256 % computes the missing ones according to a suitable
3257 % strategy. We can think of many such strategies,
3258 % but none seems to be generally applicable, in the
3259 % sense that one strategy might give good results,
3260 % say, with sinusoids and another one, say, with
3261 % cardioids, but neither one is suitable for both
3262 % cases.
3263 %
3264 % For the moment we refrain from automatic
3265 % direction computation, but we design the general
3266 % macro as if directions were optional.
3267 %
3268 % Here we begin with the first initialising macro
3269 % that receives with the first argument the
3270 % starting point and with the second argument the
3271 % direction of the tangent (not necessarily
3272 % normalised to a unit vector)
3273 % \begin{macrocode}
3274 \def\StartCurveAt#1WithDir#2{%
3275 \begingroup
3276 \GetCoord(#1)\@tempa\@tempb
3277 \CopyVect\@tempa,\@tempb to\@Pzero
3278 \pIIe@moveto{\@tempa\unitlength}{\@tempb\unitlength}%
3279 \GetCoord(#2)\@tempa\@tempb
3280 \CopyVect\@tempa,\@tempb to\@Dzero
3281 \DirOfVect\@Dzero to\@Dzero
3282 \ignorespaces}
3283 % \end{macrocode}
3284 % And this re-initialises the direction to create
3285 % a cusp:
3286 % \begin{macrocode}
3287 \def\ChangeDir<#1>{%
3288 \GetCoord(#1)\@tempa\@tempb
3289 \CopyVect\@tempa,\@tempb to\@Dzero
3290 \DirOfVect\@Dzero to\@Dzero
3291 \ignorespaces}
3292 % \end{macrocode}
3293 %
3294 % The next macros are the finishing ones; the first
3295 % strokes the whole curve, while the second fills
3296 % the (closed) curve with the default color; both
3297 % close the group that was opened with
3298 % |\StartCurve|. The third macro is going to be
3299 % explained in a while; we anticipate it is
3300 % functional to chose between the first two macros
3301 % when a star is possibly used to switch between
3302 % stroking and filling.
3303 % \begin{macrocode}
3304 \def\CurveFinish{\strokepath\endgroup\ignorespaces}
3305 \def\FillCurve{\fillpath\endgroup\ignorespaces}
3306 \def\CurveEnd{\fillstroke\endgroup\ignorespaces}
3307 % \end{macrocode}
3308 %
3309 % In order to draw the internal arcs it would be
3310 % desirable to have a single macro that, given the
3311 % destination point, computes the control points
3312 % that produce a cubic Bézier spline that joins the
3313 % starting point with the destination point in the
3314 % best possible way. The problem is strongly ill
3315 % defined and has an infinity of solutions; here we
3316 % give two solutions: $(a)$ a supposedly smart one
3317 % that resorts to osculating circles and requires
3318 % only the direction at the destination point; and
3319 % $(b)$ a less smart solution that requires the
3320 % control points to be specified in a certain
3321 % format.
3322 %
3323 % We start with solution $(b)$, |\CbezierTo|, the
3324 % code of which is simpler than that of solution
3325 % $(a)$; then we will produce the solution $(a)$,
3326 % |\CurveTo|, that will become the main
3327 % building block for a general path construction
3328 % macro, |\Curve|.
3329 %
3330 % The “naïve” macro |\CBezierTo| simply uses the
3331 % previous point direction saved in |\@Dzero| as a
3332 % unit vector by the starting macro; specifies a
3333 % destination point, the distance of the first
3334 % control point from the starting point, the
3335 % destination point direction that will save also
3336 % for the next arc-drawing macro as a unit vector,
3337 % and the distance of the second control point from
3338 % the destination point along this last direction.
3339 % Both distances must be positive possibly
3340 % fractional numbers. The syntax therefore is the
3341 % following:
3342 %\begin{Sintassi}
3343 %\cs{CbezierTo}\meta{end point}|WithDir|\meta{direction}%
3344 %|AndDists|\meta{$K_0$}|And|\meta{$K_1$}
3345 %\end{Sintassi}
3346 % where \meta{end point} is a vector macro or a
3347 % comma separated pair of values; again
3348 % \meta{direction} is another vector macro or a
3349 % comma separated pair of values, that not
3350 % necessarily indicate a unit vector, since the
3351 % macro provides to normalise it to unity;
3352 % \meta{$K_0$} and \meta{$K_1$} are the distances
3353 % of the control points from their respective node
3354 % points; they must be integers or fractional
3355 % positive numbers. If \meta{$K_1$} is a number, it
3356 % must be enclosed in curly braces, while if it is
3357 % a macro name (containing the desired fractional
3358 % or integer value) there is no need for braces.
3359 %
3360 % This macro uses the input information in order to
3361 % activate the internal |pict2e| macro
3362 % |\pIIe@curveto| with the proper arguments, and to
3363 % save the final direction into the same |\@Dzero|
3364 % macro for successive use of other arc-drawing
3365 % macros.
3366 % \begin{macrocode}
3367 \def\CbezierTo#1WithDir#2AndDists#3And#4{%
3368 \GetCoord(#1)\@tX\@tY \MakeVectorFrom\@tX\@tY to\@Puno
3369 \GetCoord(#2)\@tX\@tY \MakeVectorFrom\@tX\@tY to \@Duno
3370 \DirOfVect\@Duno to\@Duno
3371 \ScaleVect\@Dzero by#3to\@Czero \AddVect\@Pzero and\@Czero to\@Czero
3372 \ScaleVect\@Duno by-#4to \@Cuno \AddVect\@Puno and\@Cuno to \@Cuno
3373 \GetCoord(\@Czero)\@XCzero\@YCzero
3374 \GetCoord(\@Cuno)\@XCuno\@YCuno
3375 \GetCoord(\@Puno)\@XPuno\@YPuno
3376 \pIIe@curveto{\@XCzero\unitlength}{\@YCzero\unitlength}%
3377 {\@XCuno\unitlength}%
3378 {\@YCuno\unitlength}%
3379 {\@XPuno\unitlength}%
3380 {\@YPuno\unitlength}%
3381 \CopyVect\@Puno to\@Pzero
3382 \CopyVect\@Duno to\@Dzero
3383 \ignorespaces}%
3384 % \end{macrocode}
3385 %
3386 % With this building block it is not difficult to
3387 % set up a macro that draws a Bézier arc between
3388 % two given points, similarly to the other macro
3389 % |\CurveBetween| previously described and
3390 % defined here:
3391 % \begin{macrocode}
3392 \def\CbezierBetween#1And#2WithDirs#3And#4UsingDists#5And#6{\StartCurveAt#1WithDir{#3}\relax
3393 \CbezierTo#2WithDir#4AndDists#5And{#6}\CurveFinish}
3394 % \end{macrocode}
3395
3396 %
3397 % An example of use is shown in figure~13 of the
3398 % |curve2e-manual.pdf| file; notice that the
3399 % tangents at the end points are the same for the
3400 % black curve drawn with |\CurveBetween| and the
3401 % five red curves drawn with |\CbezierBetween|; the
3402 % five red curves differ only for the distance of
3403 % their control point $C_0$ from the starting
3404 % point; the differences are remarkable and the
3405 % topmost curve even presents a slight inflection
3406 % close to the end point.
3407 % These effects cannot be obtained with the
3408 % “smarter” macro |\CurveBetween|. But certainly
3409 % this simpler macro is more difficult to use
3410 % because the distances of the control points
3411 % are difficult to estimate and require a number
3412 % of cut-and-try experiments.
3413 %
3414 % The “smarter” curve macro comes next; it is
3415 % supposed to determine the control points for
3416 % joining the previous point (initial node) with
3417 % the specified direction to the next point (final
3418 % node) with another specified direction.
3419 %
3420 % Since the control points are along the specified
3421 % directions, it is necessary to determine the
3422 % distances from the adjacent curve nodes. This
3423 % must work correctly even if nodes and directions
3424 % imply an inflection point somewhere along the
3425 % arc.
3426 %
3427 % The strategy we devised consists in determining
3428 % each control point as if it were the control
3429 % point of a circular arc, precisely an arc of an
3430 % osculating circle, i.e. a circle tangent to the
3431 % curve at that node. The ambiguity of the stated
3432 % problem may be solved by establishing that the
3433 % chord of the osculating circle has the same
3434 % direction as the chord of the arc being drawn,
3435 % and that the curve chord is divided into two
3436 % equal parts each of which should be interpreted
3437 % as half the chord of the osculating circle.
3438 %
3439 % This makes the algorithm a little rigid;
3440 % sometimes the path drawn is very pleasant, while
3441 % in other circumstances the determined curvatures
3442 % are too large or too small. We therefore add some
3443 % optional information that lets us have some
3444 % control over the curvatures; the idea is based on
3445 % the concept of \emph{tension}, similar but not
3446 % identical to the one used in the drawing programs
3447 % \MF\ and \MP. We add to the direction
3448 % information, with which the control nodes of the
3449 % osculating circle arcs are determined, a scaling
3450 % factor that should be intuitively related to the
3451 % tension of the arc (actually, since the tension
3452 % of the ‘rope’ is high when this parameter is low,
3453 % probably a name such as ‘looseness’ would be
3454 % better suited): the smaller this number, the
3455 % closer the arc resembles to a straight line as a
3456 % rope subjected to a high tension; value zero is
3457 % allowed, while a value of 4 is close to
3458 % “infinity” and turns a quarter circle into a line
3459 % with an unusual loop; a value of 2 turns a
3460 % quarter circle almost into a polygonal line with
3461 % rounded vertices.
3462 % Therefore these tension factors should be used
3463 % only for fine tuning the arcs, not when a path is
3464 % drawn for the first time.
3465 %
3466 % We devised a syntax for specifying direction and
3467 % tensions:
3468 %\begin{Sintassi}
3469 % \meta{direction\texttt{\upshape;}tension factors}
3470 %\end{Sintassi}
3471 % where \emph{direction} contains the complex
3472 % number that not necessarily refers to the
3473 % components of a unit vector direction, but simply
3474 % to a vector with the desired orientation (polar
3475 % form is OK); the information contained from the
3476 % semicolon (included) to the rest of the
3477 % specification is optional; if it is present, the
3478 % \emph{tension factor} is simply a comma separated
3479 % pair of fractional or integer numbers that
3480 % represent respectively the tension at the
3481 % starting or the ending node of a path arc.
3482 %
3483 % We therefore need a macro to extract the
3484 % mandatory and optional parts:
3485 % \begin{macrocode}
3486 \def\@isTension#1;#2!!{\def\@tempA{#1}%
3487 \def\@tempB{#2}\unless\ifx\@tempB\empty \strip@semicolon#2\fi}
3488
3489 \def\strip@semicolon#1;{\def\@tempB{#1}}
3490 % \end{macrocode}
3491 % By changing the tension values we can achieve
3492 % different results: see figure~14 in the user
3493 % manual |curve2e-manual.pdf|.
3494 %
3495 % We use the formula we got for
3496 % arcs~\eqref{equ:corda}, where the half chord is
3497 % indicated with $s$, and we derive the necessary
3498 % distances:
3499 %\begin{subequations}\label{equ:Kzero-Kuno}
3500 %\begin{align}
3501 %K_0 &= \frac{4}{3} s\frac{1-\cos\theta_0}{\sin^2\theta_0}\\
3502 %K_1 &=\frac{4}{3}s\frac{1-\cos\theta_1}{\sin^2\theta_1}
3503 %\end{align}
3504 %\end{subequations}
3505 %
3506 % We therefore start with getting the points and
3507 % directions and calculating the chord and its
3508 % direction:
3509 % \begin{macrocode}
3510 \def\CurveTo#1WithDir#2{%
3511 \def\@Tuno{1}\def\@Tzero{1}\relax
3512 \edef\@Puno{#1}\@isTension#2;!!%
3513 \expandafter\DirOfVect\@tempA to\@Duno
3514 \bgroup\unless\ifx\@tempB\empty\GetCoord(\@tempB)\@Tzero\@Tuno\fi
3515 \DistanceAndDirOfVect\@Puno minus\@Pzero to\@Chord and\@DirChord
3516 % \end{macrocode}
3517 % Then we rotate everything about the starting
3518 % point so as to bring the chord on the real axis
3519 % \begin{macrocode}
3520 \Multvect{\@Dzero}*{\@DirChord}\@Dpzero
3521 \Multvect{\@Duno}*{\@DirChord}\@Dpuno
3522 \GetCoord(\@Dpzero)\@DXpzero\@DYpzero
3523 \GetCoord(\@Dpuno)\@DXpuno\@DYpuno
3524 \DivideFN\@Chord by2 to\@semichord
3525 % \end{macrocode}
3526 % The chord needs not be actually rotated because
3527 % it suffices its length along the real axis; the
3528 % chord length is memorised in |\@Chord| and its
3529 % half is saved in |\@semichord|.
3530 %
3531 % We now examine the various degenerate cases, when
3532 % either tangent is perpendicular or parallel to
3533 % the chord. Notice that we are calculating the
3534 % distances of the control points from the adjacent
3535 % nodes using the half chord length, not the full
3536 % length. We also distinguish between the
3537 % computations relative to the arc starting point
3538 % and those relative to the end point.
3539 %
3540 % Notice that if the directions of two successive
3541 % nodes are identical, it is necessary to draw a
3542 % line, not a third order spline\footnote{Many
3543 % thanks to John Hillas who spotted this bug, that
3544 % passed unnoticed for a long time, because it is a
3545 % very unusual situation.}; therefore it is
3546 % necessary to make a suitable test that is more
3547 % comfortable to do after the chord has been
3548 % rotated to be horizontal; in facts, if the two
3549 % directions are equal, the vertical components of
3550 % the directions are both vanishing values;
3551 % probably, instead of testing with respect to
3552 % zero, it might be advisable to test the absolute
3553 % value with respect to a small number such as, for
3554 % example, “1.e-6.”
3555 %
3556 % \begin{macrocode}
3557 %
3558 \fptest{abs(\@DYpuno)<=0.01&& abs(\@DYpzero)<=0.01}
3559 {\GetCoord(\@Puno)\@tX\@tY
3560 \pIIe@lineto{\@tX\unitlength}%
3561 {\@tY\unitlength}%
3562 }{%
3563 \fptestT{abs(\@DXpzero)<=0.01}%
3564 {\@tdA=1.333333\p@
3565 \Numero\@KCzero{\@semichord\@tdA}}%
3566 \fptestT{abs(\@DYpzero)<=0.01}%
3567 {\@tdA=1.333333\p@
3568 \Numero\@Kpzero{\@semichord\@tdA}}%
3569 %
3570 % \end{macrocode}
3571 % The distances we are looking for are positive
3572 % generally fractional numbers; so if the
3573 % components are negative, we take the absolute
3574 % values. Eventually we determine the absolute
3575 % control point coordinates.
3576 % \begin{macrocode}
3577 \unless\ifdim\@DXpzero\p@=\z@
3578 \unless\ifdim\@DYpzero\p@=\z@
3579 \edef\@CosDzero{\ifdim\@DXpzero\p@<\z@ -\fi\@DXpzero}%
3580 \edef\@SinDzero{\ifdim\@DYpzero\p@<\z@ -\fi\@DYpzero}%
3581 \@tdA=\@semichord\p@ \@tdA=1.333333\@tdA
3582 \DividE\@tdA by\@SinDzero\p@ to \@KCzero
3583 \@tdA=\dimexpr(\p@-\@CosDzero\p@)\relax
3584 \DividE\@KCzero\@tdA by\@SinDzero\p@ to \@KCzero
3585 \fi
3586 \fi
3587 \MultiplyFN\@KCzero by \@Tzero to \@KCzero
3588 \ScaleVect\@Dzero by\@KCzero to\@CPzero
3589 \AddVect\@Pzero and\@CPzero to\@CPzero
3590 % \end{macrocode}
3591 % We now repeat the calculations for the arc end
3592 % point, taking into consideration that the end
3593 % point direction points outwards, so that in
3594 % computing the end point control point we have to
3595 % take this fact into consideration by using a
3596 % negative sign for the distance; in this way the
3597 % displacement of the control point from the end
3598 % point takes place in a backwards direction.
3599 % \begin{macrocode}
3600 \ifdim\@DXpuno\p@=\z@
3601 \@tdA=-1.333333\p@
3602 \Numero\@KCuno{\@semichord\@tdA}%
3603 \fi
3604 \ifdim\@DYpuno\p@=\z@
3605 \@tdA=-1.333333\p@
3606 \Numero\@KCuno{\@semichord\@tdA}%
3607 \fi
3608 \unless\ifdim\@DXpuno\p@=\z@
3609 \unless\ifdim\@DYpuno\p@=\z@
3610 \edef\@CosDuno{\ifdim\@DXpuno\p@<\z@ -\fi\@DXpuno}%
3611 \edef\@SinDuno{\ifdim\@DYpuno\p@<\z@ -\fi\@DYpuno}%
3612 \@tdA=\@semichord\p@ \@tdA=-1.333333\@tdA
3613 \DividE\@tdA by \@SinDuno\p@ to \@KCuno
3614 \@tdA=\dimexpr(\p@-\@CosDuno\p@)\relax
3615 \DividE\@KCuno\@tdA by\@SinDuno\p@ to \@KCuno
3616 \fi
3617 \fi
3618 \MultiplyFN\@KCuno by \@Tuno to \@KCuno
3619 \ScaleVect\@Duno by\@KCuno to\@CPuno
3620 \AddVect\@Puno and\@CPuno to\@CPuno
3621 % \end{macrocode}
3622 % Now we have the four points and we can instruct
3623 % the internal \texttt{pict2e} macros to do the
3624 % path drawing.
3625 % \begin{macrocode}
3626 \GetCoord(\@Puno)\@XPuno\@YPuno
3627 \GetCoord(\@CPzero)\@XCPzero\@YCPzero
3628 \GetCoord(\@CPuno)\@XCPuno\@YCPuno
3629 \pIIe@curveto{\@XCPzero\unitlength}%
3630 {\@YCPzero\unitlength}%
3631 {\@XCPuno\unitlength}%
3632 {\@YCPuno\unitlength}%
3633 {\@XPuno\unitlength}%
3634 {\@YPuno\unitlength}}\egroup
3635 % \end{macrocode}
3636 % It does not have to stroke the curve because
3637 % other Bézier splines might still be added to the
3638 % path. On the opposite it memorises the final
3639 % point to be used as the initial point of the next
3640 % spline
3641 % \begin{macrocode}
3642 \CopyVect\@Puno to\@Pzero
3643 \CopyVect\@Duno to\@Dzero
3644 \ignorespaces}%
3645 % \end{macrocode}
3646 %
3647 %
3648 % We finally define the overall |\Curve| macro that
3649 % has two flavours: starred and unstarred; the
3650 % former fills the curve path with the locally
3651 % selected color, while the latter just strokes the
3652 % path. Both recursively examine an arbitrary list
3653 % of nodes and directions; node coordinates are
3654 % grouped within round parentheses while direction
3655 % components are grouped within angle brackets.
3656 % Before testing for a possible star, this initial
3657 % command kills any space or glue that might
3658 % precede it\footnote{Thanks to John Hillas who
3659 % spotted the effects of this missing glue
3660 % elimination.} The first call of the macro
3661 % initialises the drawing process and checks for
3662 % the next node and direction; if a second node is
3663 % missing, it issues a warning message and does not
3664 % draw anything. It does not check for a change in
3665 % direction, because it would be meaningless at the
3666 % beginning of a curve. The second macro defines
3667 % the path to the next point and checks for another
3668 % node; if the next list item is a square bracket
3669 % delimited argument, it interprets it as a change
3670 % of direction, while if it is another parenthesis
3671 % delimited argument it interprets it as a new
3672 % node-direction specification; if the node and
3673 % direction list is terminated, it issues the
3674 % stroking or filling command through |\CurveEnd|,
3675 % and exits the recursive process. The |\CurveEnd|
3676 % control sequence has a different meaning
3677 % depending on the fact that the main macro was
3678 % starred or unstarred. The |@ChangeDir| macro is
3679 % just an interface to execute the regular
3680 % |\ChangeDir| macro, but also for recursing
3681 % again by recalling |\@Curve|.
3682 % \begin{macrocode}
3683 \def\Curve{\@killglue\@ifstar{\let\fillstroke\fillpath\Curve@}%
3684 {\let\fillstroke\strokepath\Curve@}}
3685
3686 \def\Curve@(#1)<#2>{%
3687 \StartCurveAt#1WithDir{#2}%
3688 \@ifnextchar\lp@r\@Curve{%
3689 \PackageWarning{curve2e}{%
3690 Curve specifications must contain at least
3691 two nodes!^^J
3692 Please, control your \string\Curve\space
3693 specifications^^J}}}
3694
3695 \def\@Curve(#1)<#2>{%
3696 \CurveTo#1WithDir{#2}%
3697 \@ifnextchar\lp@r\@Curve{%
3698 \@ifnextchar[\@ChangeDir\CurveEnd}}
3699 \def\@ChangeDir[#1]{\ChangeDir<#1>\@Curve}
3700 % \end{macrocode}
3701 %
3702 % As a concluding remark, please notice that the
3703 % |\Curve| macro is certainly the most comfortable
3704 % to use, but it is sort of frozen in its
3705 % possibilities. The user may certainly use the
3706 % |\StartCurve|, |\CurveTo|, |\ChangeDir|, and
3707 % |\CurveFinish| or |\FillCurve| for a more
3708 % versatile set of drawing macros; evidently nobody
3709 % forbids to exploit the full power of the
3710 % |\cbezier| original macro for cubic splines; we
3711 % made available macros |\CbezierTo| and the
3712 % isolated Bézier arc macro% |\CbezierBetween| in
3713 % order to use the general internal cubic Bézier
3714 % splines in a more comfortable way.
3715 %
3716 % As it can be seen in figure~15 of the
3717 % |curve2e-manual.pdf| file, the two diagrams
3718 % should approximately represent a sine
3719 % wave. With Bézier curves, that resort on
3720 % polynomials, it is impossible to represent a
3721 % transcendental function, but it is only possible
3722 % to approximate it. It is evident that the
3723 % approximation obtained with full control on the
3724 % control points requires less arcs and it is more
3725 % accurate than the approximation obtained with the
3726 % recursive |\Curve| macro; this macro requires
3727 % almost two times as many pieces of information
3728 % in order to minimise the effects of the lack of
3729 % control on the control points, and even with this
3730 % added information the macro approaches the sine
3731 % wave with less accuracy. At the same time for
3732 % many applications the |\Curve| recursive macro
3733 % proves to be much easier to use than single arcs
3734 % drawn with the |\CbezierBetween| macro.
3735 %
3736 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3737 % \subsection{Quadratic splines}
3738 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3739 %
3740 % We want to create a recursive macro with the same
3741 % properties as the above described |\Curve| macro,
3742 % but that uses quadratic splines; we call it
3743 % |\Qurve| so that the macro name initial letter
3744 % reminds us of the nature of the splines being
3745 % used. For the rest they have an almost identical
3746 % syntax; with quadratic splines it is not possible
3747 % to specify the distance of the control points
3748 % from the extrema, since quadratic splines have
3749 % just one control point that must lay at the
3750 % intersection of the two tangent directions;
3751 % therefore with quadratic splines the tangents at
3752 % each point cannot have the optional part that
3753 % starts with a semicolon. The syntax, therefore,
3754 % is just:
3755 %\begin{Sintassi}
3756 %\cs{Qurve}\parg{first point}\aarg{direction}...\parg{any point}\aarg{direction}...\parg{last point}\aarg{direction}
3757 %\end{Sintassi}
3758 % As with |\Curve|, also with |\Qurve| there is no
3759 % limitation on the number of points, except for
3760 % the computer memory size; it is advisable not to
3761 % use many arcs otherwise it might become very
3762 % difficult to find errors.
3763 %
3764 % The first macros that set up the recursion are
3765 % very similar to those we wrote for |\Curve|:
3766 % \begin{macrocode}
3767 \def\Qurve{%
3768 \@ifstar{\let\fillstroke\fillpath\Qurve@}%
3769 {\let\fillstroke\strokepath\Qurve@}%
3770 }%
3771
3772 \def\Qurve@(#1)<#2>{%
3773 \StartCurveAt#1WithDir{#2}%
3774 \@ifnextchar\lp@r\@Qurve{%
3775 \PackageWarning{curve2e}{%
3776 Quadratic curve specifications must contain
3777 at least two nodes!^^J
3778 Please, control your Qurve
3779 specifications^^J}}}%
3780
3781 \def\@Qurve(#1)<#2>{\QurveTo#1WithDir{#2}%
3782 \@ifnextchar\lp@r\@Qurve{%
3783 \@ifnextchar[\@ChangeQDir\CurveEnd}}%
3784
3785 \def\@ChangeQDir[#1]{\ChangeDir<#1>\@Qurve}%
3786 % \end{macrocode}
3787 %
3788 % Notice that in case of long paths it might be
3789 % better to use the single macros |\StartCurveAt|,
3790 % |\QurveTo|, |\ChangeDir| and |\CurveFinish| (or
3791 % |\FillCurve|), with their respective syntax, in
3792 % such a way that a long list of node-direction
3793 % specifications passed to |\Qurve| may be split
3794 % into shorter input lines in order to edit the
3795 % input data in a more comfortable way.
3796 %
3797 % The macro that does everything is |\QurveTo|. It
3798 % starts by reading its arguments received through
3799 % the calling macro |\@Qurve|
3800 % \begin{macrocode}
3801 \def\QurveTo#1WithDir#2{%
3802 \edef\@Puno{#1}\DirOfVect#2to\@Duno\bgroup
3803 \DistanceAndDirOfVect\@Puno minus\@Pzero to\@Chord and\@DirChord
3804 % \end{macrocode}
3805 % It verifies if |\@Dpzero| and |\@Dpuno|, the
3806 % directions at the two extrema of the arc, are
3807 % parallel or anti-parallel by taking their
3808 % “scalar” product (|\@Dpzero| times |\@Dpuno*|);
3809 % if the imaginary component of the scalar product
3810 % vanishes the two directions are parallel; in this
3811 % case we produce an error message, but we continue
3812 % by skipping this arc destination point; evidently
3813 % the drawing will not be the desired one, but
3814 % the job should not abort.
3815 % \begin{macrocode}
3816 \Multvect{\@Dzero}*{\@Duno}\@Scalar
3817 \YpartOfVect\@Scalar to \@YScalar
3818 \ifdim\@YScalar\p@=\z@
3819 \PackageWarning{curve2e}%
3820 {Quadratic Bezier arcs cannot have their
3821 starting^^J
3822 and ending directions parallel or antiparallel
3823 with each other.^^J
3824 This arc is skipped and replaced with
3825 a dotted line.^^J}%
3826 \Dotline(\@Pzero)(\@Puno){2}\relax
3827 \else
3828 % \end{macrocode}
3829 % Otherwise we rotate everything about the starting
3830 % point so as to bring the chord on the real axis;
3831 % we get also the components of the two directions
3832 % that, we should remember, are unit vectors, not
3833 % generic vectors, although users can use the
3834 % vector specifications that are more
3835 % understandable to them:
3836 % \begin{macrocode}
3837 \Multvect{\@Dzero}*{\@DirChord}\@Dpzero
3838 \Multvect{\@Duno}*{\@DirChord}\@Dpuno
3839 \GetCoord(\@Dpzero)\@DXpzero\@DYpzero
3840 \GetCoord(\@Dpuno)\@DXpuno\@DYpuno
3841 % \end{macrocode}
3842 % We check if the two directions point to the same
3843 % half plane; this implies that these rotated
3844 % directions point to different sides of the chord
3845 % vector; all this is equivalent to the fact that
3846 % the two direction Y components have opposite
3847 % signs, so that their product is strictly
3848 % negative, while the two X components product is
3849 % not negative.
3850 % \begin{macrocode}
3851 \MultiplyFN\@DXpzero by\@DXpuno to\@XXD
3852 \MultiplyFN\@DYpzero by\@DYpuno to\@YYD
3853 \unless\ifdim\@YYD\p@<\z@\ifdim\@XXD\p@<\z@
3854 \PackageWarning{curve2e}%
3855 {Quadratic Bezier arcs cannot have
3856 inflection points^^J
3857 Therefore the tangents to the
3858 starting and ending arc^^J
3859 points cannot be directed to the
3860 same half plane.^^J
3861 This arc is skipped and replaced by
3862 a dotted line^^J}%
3863 \Dotline(\@Pzero)(\@Puno){2}\fi
3864 \else
3865 % \end{macrocode}
3866 %
3867 % After these tests we should be in a “normal”
3868 % situation. We first copy the expanded input
3869 % information into new macros that have more
3870 % explicit names: macros starting with `S' denote
3871 % the sine of the direction angle, while those
3872 % starting with ‘C’ denote the cosine of that
3873 % angle. We will use these expanded definitions as
3874 % we know we are working with the actual values.
3875 % These directions are those relative to the arc
3876 % chord.
3877 % \begin{macrocode}
3878 \edef\@CDzero{\@DXpzero}\relax
3879 \edef\@SDzero{\@DYpzero}\relax
3880 \edef\@CDuno{\@DXpuno}\relax
3881 \edef\@SDuno{\@DYpuno}\relax
3882 % \end{macrocode}
3883 % Suppose we write the parametric equations of a
3884 % straight line that departs from the beginning of
3885 % the chord with direction angle $\phi_0$ and the
3886 % corresponding equation of the straight line
3887 % departing from the end of the chord (of length
3888 % $c$) with direction angle $\phi_1$. We have to
3889 % find the coordinates of the intersection point of
3890 % these two straight lines.
3891 %\begin{subequations}
3892 %\begin{align}
3893 % t \cos\phi_0 - s \cos\phi_1 &= c\\
3894 % t \sin\phi_0 - s \sin\phi_1 &= 0
3895 %\end{align}
3896 %\end{subequations}
3897 % The parameters $t$ and $s$ are just the running
3898 % parameters; we have to solve those simultaneous
3899 % equations in the unknown variables $t$ and $s$;
3900 % these values let us compute the coordinates of
3901 % the intersection point:
3902 %\begin{subequations}\begin{align}
3903 % X_C &=\dfrac{c\cos\phi_0\sin\phi_1}{\sin\phi_0\cos\phi_1 - \cos\phi_0\sin\phi_1} \\
3904 % Y_C &=\dfrac{c\sin\phi_0\sin\phi_1}{\sin\phi_0\cos\phi_1 - \cos\phi_0\sin\phi_1}
3905 %\end{align}\end{subequations}
3906 %
3907 % Having performed the previous tests we are sure
3908 % that the denominator is not vanishing (directionw
3909 % are not parallel or anti-parallel) and that the
3910 % intersection point lays at the same side as the
3911 % direction with angle $\phi_0$ with respect to the
3912 % chord.
3913 %
3914 % The coding then goes on like this:
3915 % \begin{macrocode}
3916 \MultiplY\@SDzero by\@CDuno to\@tempA
3917 \MultiplY\@SDuno by\@CDzero to\@tempB
3918 \edef\@tempA{\strip@pt\dimexpr\@tempA\p@-\@tempB\p@}\relax
3919 \@tdA=\@SDuno\p@ \@tdB=\@Chord\p@ \@tdC=\@tempA\p@
3920 \edef\@tempC{\strip@pt\dimexpr \@tdA*\@tdB/\@tdC}\relax
3921 \MultiplY\@tempC by\@CDzero to \@XC
3922 \MultiplY\@tempC by\@SDzero to \@YC
3923 \ModOfVect\@XC,\@YC to\@KC
3924 % \end{macrocode}
3925 % Now we have the coordinates and the module of the
3926 % intersection point vector taking into account the
3927 % rotation of the real axis; getting back to the
3928 % original coordinates before rotation, we get:
3929 % \begin{macrocode}
3930 \ScaleVect\@Dzero by\@KC to\@CP
3931 \AddVect\@Pzero and\@CP to\@CP
3932 \GetCoord(\@Pzero)\@XPzero\@YPzero
3933 \GetCoord(\@Puno)\@XPuno\@YPuno
3934 \GetCoord(\@CP)\@XCP\@YCP
3935 % \end{macrocode}
3936 % We have now the coordinates of the two end points
3937 % of the quadratic arc and of the single control
3938 % point. Keeping in mind that the symbols $P_0$,
3939 % $P_1$ and $C$ denote geometrical points but also
3940 % their coordinates as ordered pairs of real
3941 % numbers (i.e. they are complex numbers) we have
3942 % to determine the parameters of a cubic spline
3943 % that with suitable values gets simplifications in
3944 % its parametric equation so that it becomes a
3945 % second degree function instead of a third degree
3946 % one. It is possible, even if it appears
3947 % impossible that a cubic form becomes a quadratic
3948 % one; we should determine the values of $P_a$ and
3949 % $P_b$ such that:
3950 %\[
3951 % P_0(1-t)^3 +3P_a(1-t)^2t +3P_b(1-t)t^2 +P_1t^3
3952 %\]
3953 % is equivalent to
3954 %\[
3955 % P_0(1-t)^2 + 2C(1-t)t + P_1t^2
3956 %\]
3957 % It turns out that the solution is given by
3958 %\begin{equation}
3959 % P_a= C+(P_0-C)/3 \qquad \text{and}\qquad P_b = C+(P_1- C)/3
3960 %\label{equ:spline3}
3961 %\end{equation}
3962 %
3963 % The transformations implied by
3964 % equations~\eqref{equ:spline3}
3965 % are performed by the following macros already
3966 % available from the |pict2e| package; we use them
3967 % here with the actual arguments used for this
3968 % task:
3969 % \begin{macrocode}
3970 \@ovxx=\@XPzero\unitlength \@ovyy=\@YPzero\unitlength
3971 \@ovdx=\@XCP\unitlength \@ovdy=\@YCP\unitlength
3972 \@xdim=\@XPuno\unitlength \@ydim=\@YPuno\unitlength
3973 \pIIe@bezier@QtoC\@ovxx\@ovdx\@ovro
3974 \pIIe@bezier@QtoC\@ovyy\@ovdy\@ovri
3975 \pIIe@bezier@QtoC\@xdim\@ovdx\@clnwd
3976 \pIIe@bezier@QtoC\@ydim\@ovdy\@clnht
3977 % \end{macrocode}
3978 %
3979 % We call the basic |pict2e| macro to draw a cubic
3980 % spline and we finish the conditional statements
3981 % with which we started these calculations;
3982 % eventually we close the group we opened at the
3983 % beginning and we copy the terminal node
3984 % information (position and direction) into the
3985 % zero-labelled macros that indicate the starting
3986 % point of the next arc.
3987 % \begin{macrocode}
3988 \pIIe@curveto\@ovro\@ovri\@clnwd\@clnht\@xdim\@ydim
3989 \fi\fi\egroup
3990 \CopyVect\@Puno to\@Pzero
3991 \CopyVect\@Duno to\@Dzero
3992 \ignorespaces}
3993 % \end{macrocode}
3994 %
3995 % An example of usage is shown at the left in
3996 % figure~16 of the |curve2e-manual.pdf|
3997 % file\footnote{%
3998 % The commands \cs{legenda}, \cs{Pall} and
3999 % \cs{Zbox} are specifically defined in the
4000 % preamble of this document; they must be used
4001 % within a \texttt{picture} environment.
4002 % \cs{legenda} draws a framed legend made up of a
4003 % single (short) math formula; \cs{Pall} is just a
4004 % shorthand to put a sized dot at a specified
4005 % position; \cs{Zbox} puts a symbol in math mode a
4006 % little displaced in the proper direction relative
4007 % to a specified position. They are just handy to
4008 % label certain objects in a \texttt{picture}
4009 % diagram. They have been defined at the beginning
4010 % of the \texttt{curve2e.sty} code.} created with
4011 % the code shown in the same page as the figure.
4012 %
4013 % Notice also that the inflexed line is made with
4014 % two arcs that meet at the inflection point; the
4015 % same is true for the line that resembles a sine
4016 % wave. The cusps of the inner border of the green
4017 % area are obtained with the usual optional
4018 % argument already used also with the |\Curve|
4019 % recursive macro.
4020 %
4021 % The “circle” inside the square frame is visibly
4022 % different from a real circle, in spite of the
4023 % fact that the maximum deviation from the true
4024 % circle is just about 6\% relative to the radius;
4025 % a quarter circle obtained with a single parabola
4026 % is definitely a poor approximation of a real
4027 % quarter circle; possibly by splitting each
4028 % quarter circle in three or four partial arcs the
4029 % approximation of a real quarter circle would be
4030 % much better. On the right of figure~16 of the
4031 % user manual it is possible to compare a “circle”
4032 % obtained with quadratic arcs with the the
4033 % internal circle obtained with cubic arcs; the
4034 % difference is easily seen even without using
4035 % measuring instruments.
4036 %
4037 % With quadratic arcs we decided to avoid defining
4038 % specific macros similar to |\CurveBetween| and
4039 % |\CbezierBetween|; the first macro would not save
4040 % any typing to the user; furthermore it may be
4041 % questionable if it was really useful even with
4042 % cubic splines; the second macro with quadratic
4043 % arcs is meaningless, since with quadratic arcs
4044 % there is just one control point and there is no
4045 % choice on its position.
4046 %
4047 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4048 % \section{Conclusion}
4049 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4050 % I believe that the set of new macros provided by
4051 % this package can really help users to draw their
4052 % diagrams with more agility; it will be the
4053 % accumulated experience to decide if this is true.
4054 %
4055 % As a personal experience I found very comfortable
4056 % to draw ellipses and to define macros to draw not
4057 % only such shapes or filled elliptical areas, but
4058 % also to create “legends” with coloured
4059 % backgrounds and borders. But this is just an
4060 % application of the functionality implemented in
4061 % this package. In 2020 I added to CTAN another
4062 % specialised package,
4063 % |euclideangeometry.sty| with its manual
4064 % |euclideangeometry-man.pdf| that uses the
4065 % facilities of |curve2e| to draw complex diagrams
4066 % that plot curves, and other facilities that solve
4067 % some geometrical problems dealing with ellipses.
4068 %
4069 %\iffalse
4070 %</package>
4071 %\fi
4072 %
4073 %
4074 %\iffalse
4075 %<*readme>
4076 %\fi
4077 % \section{The \texttt{README.txt} file}
4078 % The following is the text that forms the contents
4079 % of the |README.txt| file that accompanies the
4080 % package. We found it handy to have it in the
4081 % documented source, because in this way certain
4082 % pieces of information don't need to be repeated
4083 % again and again in different files.
4084 % \begin{macrocode}
4085 The package bundle curve2e is composed of the following files
4086
4087 curve2e.dtx
4088 curve2e-manual.tex
4089
4090 The derived files are
4091
4092 curve2e.sty
4093 curve2e-v161.sty
4094 curve2e.pdf
4095 curve2e-manual.pdf
4096 README.txt
4097
4098 If you install curve2e without using your TeX system package handler,
4099 Compile curve2e.dtx and curve2e-manual.tex two or three times until
4100 all labels and citation keys are completely resolved. Then move the
4101 primary and derived files as follows:
4102
4103 Move curve2e.dtx and curve2e-manual.tex to ROOT/source/latex/curve2e/
4104 Move curve2e.pdf and curve2e-manual.pdf to ROOT/doc/latex/curve2e/
4105 Move curve2e.sty and curve2e-v161.sty to ROOT/tex/latex/curve2e/
4106 Move README.txt to ROOT/doc/latex/curve2e/
4107
4108 curve2e.dtx is the documented TeX source file of the derived files
4109 curve2e.sty, curve2e.pdf, curve2e-v161.sty and README.txt.
4110
4111 You get curve2e.sty, curve2e.pdf, curve2e-v161.sty, and README.txt
4112 by running pdflatex on curve2e.dtx.
4113
4114 The curve2e-manual files contains the user manual; in
4115 this way the long preliminary descriptive part of the previous versions
4116 curve2e.pdf file has been transferred to a shorter dedicated file, and the
4117 "normal" user should have enough information to use the package. The
4118 curve2e.pdf file, extracted from the .dtx one, contains the code
4119 documentation and is intended for the developers, or for the curious
4120 advanced users. For what concerns curve2e-v161.sty, it is a previous
4121 version of this package; see below why the older version might become
4122 necessary to the end user.
4123
4124 README.txt, this file, contains general information.
4125
4126 This bundle contains also package curve2e-v161.sty, a roll-back
4127 version needed in certain rare cases.
4128
4129 Curve2e.sty is an extension of the package pict2e.sty which extends the
4130 standard picture LaTeX environment according to what Leslie Lamport
4131 specified in the second edition of his LaTeX manual (1994).
4132
4133 This further extension curve2e.sty to pict2e.sty allows to draw lines
4134 and vectors with any non integer slope parameters, to draw dashed and
4135 dotted lines of any slope, to draw arcs and curved vectors, to draw
4136 curves where just the interpolating nodes are specified together with
4137 the tangent directions at such nodes; closed paths of any shape can be
4138 filled with color; all coordinates are treated as ordered pairs, i.e. "complex
4139 numbers"; coordinates may be expressed also in polar form. Coordinates
4140 may be specified with macros, so that editing any drawing is rendered
4141 much simpler: any point specified with a macro is modified only once
4142 in its macro definition.
4143 Some of these features have been incorporated in the 2009 version of
4144 pict2e; therefore this package avoids any modification to the original
4145 pict2e commands. In any case the version of curve2e is compatible with
4146 later versions of pict2e; see below.
4147
4148 Curve2e now accepts polar coordinates in addition to the usual cartesian
4149 ones; several macros have been upgraded; a new macro for tracing cubic
4150 Bezier splines with their control nodes specified in polar form is
4151 available. The same applies to quadratic Bezier splines. The multiput
4152 command has been completely modified in a backwards compatible way; the
4153 new version allows to manipulate the increment components in a configurable
4154 way. A new xmultiput command has been defined that is more configurable
4155 than the original one; both commands multiput and xmultiput are backwards
4156 compatible with the original picture environment definition.
4157
4158 Curve2e solves a conflict with package eso-pic.
4159
4160 This version of curve2e is almost fully compatible with pict2e version 0.4z and later.
4161
4162 If you specify
4163
4164 \usepackage[<pict2e options>]{curve2e}
4165
4166 the package pict2e is automatically invoked with the specified options.
4167
4168 The -almost fully compatible- phrase is necessary to explain that this
4169 version of curve2e uses some "functions" of the LaTeX3 language that were
4170 made available to the LaTeX developers by mid October 2018. Should the user
4171 have an older or a basic/incomplete installation of the TeX system,
4172 such L3 functions might not be available. This is why this
4173 package checks the presence of the developer interface; in case
4174 such interface is not available it rolls back to the previous version
4175 renamed curve2e-v161.sty, which is part of this bundle; this roll-back
4176 file name must not be modified in any way. The compatibility mentioned
4177 above implies that the user macros remain the same, but their
4178 implementation requires the L3 interface. Some macros and environments
4179 rely totally on the xfp package functionalities, but legacy documents
4180 source files should compile correctly.
4181
4182 The package has the LPPL status of maintained.
4183
4184 According to the LPPL licence, you are entitled to modify this package,
4185 as long as you fulfil the few conditions set forth by the Licence.
4186
4187 Nevertheless this package is an extension to the standard LaTeX
4188 pict2e (2014) package. Therefore any change must be controlled on the
4189 parent package pict2e, so as to avoid redefining or interfering with
4190 what is already contained in that package.
4191
4192 If you prefer sending me your modifications, as long as I will maintain
4193 this package, I will possibly include every (documented) suggestion or
4194 modification into this package and, of course, I will acknowledge your
4195 contribution.
4196
4197 Claudio Beccari
4198
4199 claudio dot beccari at gmail dot com
4200 % \end{macrocode}
4201 %\iffalse
4202 %</readme>
4203 %\fi
4204 %\iffalse
4205 %<*v161>
4206 %\fi
4207 % \section{The roll-back package version \texttt{curve2e-v161}}
4208 % This is the fall-back version of |curve2e-v161.sty| to which
4209 % the main file |curve2e.sty| falls back in case the interface
4210 % packages |xfp| and |xparse| are not available.
4211 % \begin{macrocode}
4212 \NeedsTeXFormat{LaTeX2e}[2016/01/01]
4213 \ProvidesPackage{curve2e-v161}%
4214 [2019/02/07 v.1.61 Extension package for pict2e]
4215
4216 \RequirePackage{color}
4217 \RequirePackageWithOptions{pict2e}[2014/01/01]
4218 \RequirePackage{xparse}
4219 \def\TRON{\tracingcommands\tw@ \tracingmacros\tw@}%
4220 \def\TROF{\tracingcommands\z@ \tracingmacros\z@}%
4221 \ifx\undefined\@tdA \newdimen\@tdA \fi
4222 \ifx\undefined\@tdB \newdimen\@tdB \fi
4223 \ifx\undefined\@tdC \newdimen\@tdC \fi
4224 \ifx\undefined\@tdD \newdimen\@tdD \fi
4225 \ifx\undefined\@tdE \newdimen\@tdE \fi
4226 \ifx\undefined\@tdF \newdimen\@tdF \fi
4227 \ifx\undefined\defaultlinewidth \newdimen\defaultlinewidth \fi
4228 \gdef\linethickness#1{\@wholewidth#1\@halfwidth.5\@wholewidth\ignorespaces}%
4229 \newcommand\defaultlinethickness[1]{\defaultlinewidth=#1\relax
4230 \def\thicklines{\linethickness{\defaultlinewidth}}%
4231 \def\thinlines{\linethickness{.5\defaultlinewidth}}%
4232 \thinlines\ignorespaces}
4233 \def\LIne(#1){{\GetCoord(#1)\@tX\@tY
4234 \moveto(0,0)
4235 \pIIe@lineto{\@tX\unitlength}{\@tY\unitlength}\strokepath}\ignorespaces}%
4236 \def\segment(#1)(#2){\@killglue\polyline(#1)(#2)}%
4237 \def\line(#1)#2{\begingroup
4238 \@linelen #2\unitlength
4239 \ifdim\@linelen<\z@\@badlinearg\else
4240 \expandafter\DirOfVect#1to\Dir@line
4241 \GetCoord(\Dir@line)\d@mX\d@mY
4242 \ifdim\d@mX\p@=\z@\else
4243 \DividE\ifdim\d@mX\p@<\z@-\fi\p@ by\d@mX\p@ to\sc@lelen
4244 \@linelen=\sc@lelen\@linelen
4245 \fi
4246 \moveto(0,0)
4247 \pIIe@lineto{\d@mX\@linelen}{\d@mY\@linelen}%
4248 \strokepath
4249 \fi
4250 \endgroup\ignorespaces}%
4251 \ifx\Dashline\undefined
4252 \def\Dashline{\@ifstar{\Dashline@@}{\Dashline@}}
4253 \def\Dashline@(#1)(#2)#3{%
4254 \bgroup
4255 \countdef\NumA3254\countdef\NumB3252\relax
4256 \GetCoord(#1)\@tA\@tB \MakeVectorFrom\@tA\@tB to\V@ttA
4257 \GetCoord(#2)\@tA\@tB \MakeVectorFrom\@tA\@tB to\V@ttB
4258 \SubVect\V@ttA from\V@ttB to\V@ttC
4259 \ModOfVect\V@ttC to\DlineMod
4260 \DivideFN\DlineMod by#3 to\NumD
4261 \NumA\expandafter\Integer\NumD.??
4262 \ifodd\NumA\else\advance\NumA\@ne\fi
4263 \NumB=\NumA \divide\NumB\tw@
4264 \DividE\DlineMod\p@ by\NumA\p@ to\D@shMod
4265 \DividE\p@ by\NumA\p@ to \@tempa
4266 \MultVect\V@ttC by\@tempa,0 to\V@ttB
4267 \MultVect\V@ttB by 2,0 to\V@ttC
4268 \advance\NumB\@ne
4269 \edef\@mpt{\noexpand\egroup
4270 \noexpand\multiput(\V@ttA)(\V@ttC){\number\NumB}%
4271 {\noexpand\LIne(\V@ttB)}}%
4272 \@mpt\ignorespaces}%
4273 \let\Dline\Dashline
4274
4275 \def\Dashline@@(#1)(#2)#3{\put(#1){\Dashline@(0,0)(#2){#3}}}
4276 \fi
4277 \ifx\Dotline\undefined
4278 \def\Dotline{\@ifstar{\Dotline@@}{\Dotline@}}
4279 \def\Dotline@(#1)(#2)#3{%
4280 \bgroup
4281 \countdef\NumA 3254\relax \countdef\NumB 3255\relax
4282 \GetCoord(#1)\@tA\@tB \MakeVectorFrom\@tA\@tB to\V@ttA
4283 \GetCoord(#2)\@tA\@tB \MakeVectorFrom\@tA\@tB to\V@ttB
4284 \SubVect\V@ttA from\V@ttB to\V@ttC
4285 \ModOfVect\V@ttC to\DotlineMod
4286 \DivideFN\DotlineMod by#3 to\NumD
4287 \NumA=\expandafter\Integer\NumD.??
4288 \DivVect\V@ttC by\NumA,0 to\V@ttB
4289 \advance\NumA\@ne
4290 \edef\@mpt{\noexpand\egroup
4291 \noexpand\multiput(\V@ttA)(\V@ttB){\number\NumA}%
4292 {\noexpand\makebox(0,0){\noexpand\circle*{0.5}}}}%
4293 \@mpt\ignorespaces}%
4294
4295 \def\Dotline@@(#1)(#2)#3{\put(#1){\Dotline@(0,0)(#2){#3}}}
4296 \fi
4297 \AtBeginDocument{\@ifpackageloaded{eso-pic}{%
4298 \renewcommand\LenToUnit[1]{\strip@pt\dimexpr#1*\p@/\unitlength}}{}}
4299
4300 \def\GetCoord(#1)#2#3{%
4301 \expandafter\SplitNod@\expandafter(#1)#2#3\ignorespaces}
4302 \def\isnot@polar#1:#2!!{\def\@tempOne{#2}\ifx\@tempOne\empty
4303 \expandafter\@firstoftwo\else
4304 \expandafter\@secondoftwo\fi
4305 {\SplitNod@@}{\SplitPolar@@}}
4306
4307 \def\SplitNod@(#1)#2#3{\isnot@polar#1:!!(#1)#2#3}%
4308 \def\SplitNod@@(#1,#2)#3#4{\edef#3{#1}\edef#4{#2}}%
4309 \def\SplitPolar@@(#1:#2)#3#4{\DirFromAngle#1to\@DirA
4310 \ScaleVect\@DirA by#2to\@DirA
4311 \expandafter\SplitNod@@\expandafter(\@DirA)#3#4}
4312
4313 \let\originalput\put
4314 \def\put(#1){\bgroup\GetCoord(#1)\@tX\@tY
4315 \edef\x{\noexpand\egroup\noexpand\originalput(\@tX,\@tY)}\x}
4316
4317 \let\originalmultiput\multiput
4318 \let\original@multiput\@multiput
4319
4320 \long\def\@multiput(#1)#2#3{\bgroup\GetCoord(#1)\@mptX\@mptY
4321 \edef\x{\noexpand\egroup\noexpand\original@multiput(\@mptX,\@mptY)}%
4322 \x{#2}{#3}\ignorespaces}
4323
4324 \gdef\multiput(#1)#2{\bgroup\GetCoord(#1)\@mptX\@mptY
4325 \edef\x{\noexpand\egroup\noexpand\originalmultiput(\@mptX,\@mptY)}\x(}%)
4326 \def\vector(#1)#2{%
4327 \begingroup
4328 \GetCoord(#1)\d@mX\d@mY
4329 \@linelen#2\unitlength
4330 \ifdim\d@mX\p@=\z@\ifdim\d@mY\p@=\z@\@badlinearg\fi\fi
4331 \ifdim\@linelen<\z@ \@linelen=-\@linelen\fi
4332 \MakeVectorFrom\d@mX\d@mY to\@Vect
4333 \DirOfVect\@Vect to\Dir@Vect
4334 \YpartOfVect\Dir@Vect to\@ynum \@ydim=\@ynum\p@
4335 \XpartOfVect\Dir@Vect to\@xnum \@xdim=\@xnum\p@
4336 \ifdim\d@mX\p@=\z@
4337 \else\ifdim\d@mY\p@=\z@
4338 \else
4339 \DividE\ifdim\@xnum\p@<\z@-\fi\p@ by\@xnum\p@ to\sc@lelen
4340 \@linelen=\sc@lelen\@linelen
4341 \fi
4342 \fi
4343 \@tdB=\@linelen
4344 \pIIe@concat\@xdim\@ydim{-\@ydim}\@xdim{\@xnum\@linelen}{\@ynum\@linelen}%
4345 \@linelen\z@
4346 \pIIe@vector
4347 \fillpath
4348 \@linelen=\@tdB
4349 \@tdA=\pIIe@FAW\@wholewidth
4350 \@tdA=\pIIe@FAL\@tdA
4351 \advance\@linelen-\@tdA
4352 \ifdim\@linelen>\z@
4353 \moveto(0,0)
4354 \pIIe@lineto{\@xnum\@linelen}{\@ynum\@linelen}%
4355 \strokepath\fi
4356 \endgroup}
4357 \def\Vector(#1){{%
4358 \GetCoord(#1)\@tX\@tY
4359 \ifdim\@tX\p@=\z@\vector(\@tX,\@tY){\@tY}
4360 \else
4361 \vector(\@tX,\@tY){\@tX}\fi}}
4362 \def\VECTOR(#1)(#2){\begingroup
4363 \SubVect#1from#2to\@tempa
4364 \expandafter\put\expandafter(#1){\expandafter\Vector\expandafter(\@tempa)}%
4365 \endgroup\ignorespaces}
4366 \let\lp@r( \let\rp@r)
4367 \renewcommand*\polyline[1][\beveljoin]{\p@lylin@[#1]}
4368
4369 \def\p@lylin@[#1](#2){\@killglue#1\GetCoord(#2)\d@mX\d@mY
4370 \pIIe@moveto{\d@mX\unitlength}{\d@mY\unitlength}%
4371 \@ifnextchar\lp@r{\p@lyline}{%
4372 \PackageWarning{curve2e}%
4373 {Polylines require at least two vertices!\MessageBreak
4374 Control your polyline specification\MessageBreak}%
4375 \ignorespaces}}
4376
4377 \def\p@lyline(#1){\GetCoord(#1)\d@mX\d@mY
4378 \pIIe@lineto{\d@mX\unitlength}{\d@mY\unitlength}%
4379 \@ifnextchar\lp@r{\p@lyline}{\strokepath\ignorespaces}}
4380 \providecommand\polygon{}
4381 \RenewDocumentCommand\polygon{s O{\beveljoin} }{\@killglue\begingroup
4382 \IfBooleanTF{#1}{\@tempswatrue}{\@tempswafalse}%
4383 \@polygon[#2]}
4384
4385 \def\@polygon[#1](#2){\@killglue#1\GetCoord(#2)\d@mX\d@mY
4386 \pIIe@moveto{\d@mX\unitlength}{\d@mY\unitlength}%
4387 \@ifnextchar\lp@r{\@@polygon}{%
4388 \PackageWarning{curve2e}%
4389 {Polygons require at least two vertices!\MessageBreak
4390 Control your polygon specification\MessageBreak}%
4391 \ignorespaces}}
4392
4393 \def\@@polygon(#1){\GetCoord(#1)\d@mX\d@mY
4394 \pIIe@lineto{\d@mX\unitlength}{\d@mY\unitlength}%
4395 \@ifnextchar\lp@r{\@@polygon}{\pIIe@closepath
4396 \if@tempswa\pIIe@fillGraph\else\pIIe@strokeGraph\fi
4397 \endgroup
4398 \ignorespaces}}
4399 \def\GraphGrid(#1,#2){\bgroup\textcolor{red}{\linethickness{.1\p@}%
4400 \RoundUp#1modulo10to\@GridWd \RoundUp#2modulo10to\@GridHt
4401 \@tempcnta=\@GridWd \divide\@tempcnta10\relax \advance\@tempcnta\@ne
4402 \multiput(0,0)(10,0){\@tempcnta}{\line(0,1){\@GridHt}}%
4403 \@tempcnta=\@GridHt \divide\@tempcnta10\advance\@tempcnta\@ne
4404 \multiput(0,0)(0,10){\@tempcnta}{\line(1,0){\@GridWd}}\thinlines}%
4405 \egroup\ignorespaces}
4406 \def\RoundUp#1modulo#2to#3{\expandafter\@tempcnta\Integer#1.??%
4407 \count254\@tempcnta\divide\count254by#2\relax
4408 \multiply\count254by#2\relax
4409 \count252\@tempcnta\advance\count252-\count254
4410 \ifnum\count252>0\advance\count252-#2\relax
4411 \advance\@tempcnta-\count252\fi\edef#3{\number\@tempcnta}\ignorespaces}%
4412 \def\Integer#1.#2??{#1}%
4413 \ifdefined\dimexpr
4414 \unless\ifdefined\DividE
4415 \def\DividE#1by#2to#3{\bgroup
4416 \dimendef\Num2254\relax \dimendef\Den2252\relax
4417 \dimendef\@DimA 2250
4418 \Num=\p@ \Den=#2\relax
4419 \ifdim\Den=\z@
4420 \edef\x{\noexpand\endgroup\noexpand\def\noexpand#3{\strip@pt\maxdimen}}%
4421 \else
4422 \@DimA=#1\relax
4423 \edef\x{%
4424 \noexpand\egroup\noexpand\def\noexpand#3{%
4425 \strip@pt\dimexpr\@DimA*\Num/\Den\relax}}%
4426 \fi
4427 \x\ignorespaces}%
4428 \fi
4429 \unless\ifdefined\DivideFN
4430 \def\DivideFN#1by#2to#3{\DividE#1\p@ by#2\p@ to{#3}}%
4431 \fi
4432 \unless\ifdefined\MultiplY
4433 \def\MultiplY#1by#2to#3{\bgroup
4434 \dimendef\@DimA 2254 \dimendef\@DimB2255
4435 \@DimA=#1\p@\relax \@DimB=#2\p@\relax
4436 \edef\x{%
4437 \noexpand\egroup\noexpand\def\noexpand#3{%
4438 \strip@pt\dimexpr\@DimA*\@DimB/\p@\relax}}%
4439 \x\ignorespaces}%
4440 \let\MultiplyFN\MultiplY
4441 \fi
4442 \fi
4443
4444 \unless\ifdefined\Numero
4445 \def\Numero#1#2{\bgroup\dimen3254=#2\relax
4446 \edef\x{\noexpand\egroup\noexpand\edef\noexpand#1{%
4447 \strip@pt\dimen3254}}\x\ignorespaces}%
4448 \fi
4449 \def\g@tTanCotanFrom#1to#2and#3{%
4450 \DividE 114.591559\p@ by#1to\X@ \@tdB=\X@\p@
4451 \countdef\I=2546\def\Tan{0}\I=11\relax
4452 \@whilenum\I>\z@\do{%
4453 \@tdC=\Tan\p@ \@tdD=\I\@tdB
4454 \advance\@tdD-\@tdC \DividE\p@ by\@tdD to\Tan
4455 \advance\I-2\relax}%
4456 \def#2{\Tan}\DividE\p@ by\Tan\p@ to\Cot \def#3{\Cot}\ignorespaces}%
4457 \def\SinOf#1to#2{\bgroup%
4458 \@tdA=#1\p@%
4459 \ifdim\@tdA>\z@%
4460 \@whiledim\@tdA>180\p@\do{\advance\@tdA -360\p@}%
4461 \else%
4462 \@whiledim\@tdA<-180\p@\do{\advance\@tdA 360\p@}%
4463 \fi \ifdim\@tdA=\z@
4464 \def\@tempA{0}%
4465 \else
4466 \ifdim\@tdA>\z@
4467 \def\Segno{+}%
4468 \else
4469 \def\Segno{-}%
4470 \@tdA=-\@tdA
4471 \fi
4472 \ifdim\@tdA>90\p@
4473 \@tdA=-\@tdA \advance\@tdA 180\p@
4474 \fi
4475 \ifdim\@tdA=90\p@
4476 \def\@tempA{\Segno1}%
4477 \else
4478 \ifdim\@tdA=180\p@
4479 \def\@tempA{0}%
4480 \else
4481 \ifdim\@tdA<\p@
4482 \@tdA=\Segno0.0174533\@tdA
4483 \DividE\@tdA by\p@ to \@tempA%
4484 \else
4485 \g@tTanCotanFrom\@tdA to\T and\Tp
4486 \@tdA=\T\p@ \advance\@tdA \Tp\p@
4487 \DividE \Segno2\p@ by\@tdA to \@tempA%
4488 \fi
4489 \fi
4490 \fi
4491 \fi
4492 \edef\endSinOf{\noexpand\egroup
4493 \noexpand\def\noexpand#2{\@tempA}\noexpand\ignorespaces}%
4494 \endSinOf}%
4495 \def\CosOf#1to#2{\bgroup%
4496 \@tdA=#1\p@%
4497 \ifdim\@tdA>\z@%
4498 \@whiledim\@tdA>360\p@\do{\advance\@tdA -360\p@}%
4499 \else%
4500 \@whiledim\@tdA<\z@\do{\advance\@tdA 360\p@}%
4501 \fi
4502 \ifdim\@tdA>180\p@
4503 \@tdA=-\@tdA \advance\@tdA 360\p@
4504 \fi
4505 \ifdim\@tdA<90\p@
4506 \def\Segno{+}%
4507 \else
4508 \def\Segno{-}%
4509 \@tdA=-\@tdA \advance\@tdA 180\p@
4510 \fi
4511 \ifdim\@tdA=\z@
4512 \def\@tempA{\Segno1}%
4513 \else
4514 \ifdim\@tdA<\p@
4515 \@tdA=0.0174533\@tdA \Numero\@tempA\@tdA
4516 \@tdA=\@tempA\@tdA \@tdA=-.5\@tdA
4517 \advance\@tdA \p@
4518 \DividE\@tdA by\p@ to\@tempA%
4519 \else
4520 \ifdim\@tdA=90\p@
4521 \def\@tempA{0}%
4522 \else
4523 \g@tTanCotanFrom\@tdA to\T and\Tp
4524 \@tdA=\Tp\p@ \advance\@tdA-\T\p@
4525 \@tdB=\Tp\p@ \advance\@tdB\T\p@
4526 \DividE\Segno\@tdA by\@tdB to\@tempA%
4527 \fi
4528 \fi
4529 \fi
4530 \edef\endCosOf{\noexpand\egroup
4531 \noexpand\def\noexpand#2{\@tempA}\noexpand\ignorespaces}%
4532 \endCosOf}%
4533 \def\TanOf#1to#2{\bgroup%
4534 \@tdA=#1\p@%
4535 \ifdim\@tdA>90\p@%
4536 \@whiledim\@tdA>90\p@\do{\advance\@tdA -180\p@}%
4537 \else%
4538 \@whiledim\@tdA<-90\p@\do{\advance\@tdA 180\p@}%
4539 \fi%
4540 \ifdim\@tdA=\z@%
4541 \def\@tempA{0}%
4542 \else
4543 \ifdim\@tdA>\z@
4544 \def\Segno{+}%
4545 \else
4546 \def\Segno{-}%
4547 \@tdA=-\@tdA
4548 \fi
4549 \ifdim\@tdA=90\p@
4550 \def\@tempA{\Segno16383.99999}%
4551 \else
4552 \ifdim\@tdA<\p@
4553 \@tdA=\Segno0.0174533\@tdA
4554 \DividE\@tdA by\p@ to\@tempA%
4555 \else
4556 \g@tTanCotanFrom\@tdA to\T and\Tp
4557 \@tdA\Tp\p@ \advance\@tdA -\T\p@
4558 \DividE\Segno2\p@ by\@tdA to\@tempA%
4559 \fi
4560 \fi
4561 \fi
4562 \edef\endTanOf{\noexpand\egroup
4563 \noexpand\def\noexpand#2{\@tempA}\noexpand\ignorespaces}%
4564 \endTanOf}%
4565 \def\ArcTanOf#1to#2{\bgroup
4566 \countdef\Inverti 4444\Inverti=0
4567 \def\Segno{}
4568 \edef\@tF{#1}\@tdF=\@tF\p@ \@tdE=57.295778\p@
4569 \@tdD=\ifdim\@tdF<\z@ -\@tdF\def\Segno{-}\else\@tdF\fi
4570 \ifdim\@tdD>\p@
4571 \Inverti=\@ne
4572 \@tdD=\dimexpr\p@*\p@/\@tdD\relax
4573 \fi
4574 \unless\ifdim\@tdD>0.02\p@
4575 \def\@tX{\strip@pt\dimexpr57.295778\@tdD\relax}%
4576 \else
4577 \edef\@tX{45}\relax
4578 \countdef\I 2523 \I=9\relax
4579 \@whilenum\I>0\do{\TanOf\@tX to\@tG
4580 \edef\@tG{\strip@pt\dimexpr\@tG\p@-\@tdD\relax}\relax
4581 \MultiplY\@tG by57.295778to\@tG
4582 \CosOf\@tX to\@tH
4583 \MultiplY\@tH by\@tH to\@tH
4584 \MultiplY\@tH by\@tG to \@tH
4585 \edef\@tX{\strip@pt\dimexpr\@tX\p@ - \@tH\p@\relax}\relax
4586 \advance\I\m@ne}%
4587 \fi
4588 \ifnum\Inverti=\@ne
4589 \edef\@tX{\strip@pt\dimexpr90\p@-\@tX\p@\relax}
4590 \fi
4591 \edef\x{\egroup\noexpand\edef\noexpand#2{\Segno\@tX}}\x\ignorespaces}%
4592 \def\MakeVectorFrom#1#2to#3{\edef#3{#1,#2}\ignorespaces}%
4593 \def\CopyVect#1to#2{\edef#2{#1}\ignorespaces}%
4594 \def\ModOfVect#1to#2{\GetCoord(#1)\t@X\t@Y
4595 \@tempdima=\t@X\p@ \ifdim\@tempdima<\z@ \@tempdima=-\@tempdima\fi
4596 \@tempdimb=\t@Y\p@ \ifdim\@tempdimb<\z@ \@tempdimb=-\@tempdimb\fi
4597 \ifdim\@tempdima=\z@
4598 \ifdim\@tempdimb=\z@
4599 \def\@T{0}\@tempdimc=\z@
4600 \else
4601 \def\@T{0}\@tempdimc=\@tempdimb
4602 \fi
4603 \else
4604 \ifdim\@tempdima>\@tempdimb
4605 \DividE\@tempdimb by\@tempdima to\@T
4606 \@tempdimc=\@tempdima
4607 \else
4608 \DividE\@tempdima by\@tempdimb to\@T
4609 \@tempdimc=\@tempdimb
4610 \fi
4611 \fi
4612 \unless\ifdim\@tempdimc=\z@
4613 \unless\ifdim\@T\p@=\z@
4614 \@tempdima=\@T\p@ \@tempdima=\@T\@tempdima
4615 \advance\@tempdima\p@%
4616 \@tempdimb=\p@%
4617 \@tempcnta=5\relax
4618 \@whilenum\@tempcnta>\z@\do{\DividE\@tempdima by\@tempdimb to\@T
4619 \advance\@tempdimb \@T\p@ \@tempdimb=.5\@tempdimb
4620 \advance\@tempcnta\m@ne}%
4621 \@tempdimc=\@T\@tempdimc
4622 \fi
4623 \fi
4624 \Numero#2\@tempdimc
4625 \ignorespaces}%
4626 \def\DirOfVect#1to#2{\GetCoord(#1)\t@X\t@Y
4627 \ModOfVect#1to\@tempa
4628 \unless\ifdim\@tempdimc=\z@
4629 \DividE\t@X\p@ by\@tempdimc to\t@X
4630 \DividE\t@Y\p@ by\@tempdimc to\t@Y
4631 \fi
4632 \MakeVectorFrom\t@X\t@Y to#2\ignorespaces}%
4633 \def\ModAndDirOfVect#1to#2and#3{%
4634 \GetCoord(#1)\t@X\t@Y
4635 \ModOfVect#1to#2%
4636 \ifdim\@tempdimc=\z@\else
4637 \DividE\t@X\p@ by\@tempdimc to\t@X
4638 \DividE\t@Y\p@ by\@tempdimc to\t@Y
4639 \fi
4640 \MakeVectorFrom\t@X\t@Y to#3\ignorespaces}%
4641 \def\DistanceAndDirOfVect#1minus#2to#3and#4{%
4642 \SubVect#2from#1to\@tempa
4643 \ModAndDirOfVect\@tempa to#3and#4\ignorespaces}%
4644 \def\XpartOfVect#1to#2{%
4645 \GetCoord(#1)#2\@tempa\ignorespaces}%
4646 \def\YpartOfVect#1to#2{%
4647 \GetCoord(#1)\@tempa#2\ignorespaces}%
4648 \def\DirFromAngle#1to#2{%
4649 \CosOf#1to\t@X
4650 \SinOf#1to\t@Y
4651 \MakeVectorFrom\t@X\t@Y to#2\ignorespaces}%
4652 \def\ArgOfVect#1to#2{\bgroup\GetCoord(#1){\t@X}{\t@Y}%
4653 \def\s@gno{}\def\addflatt@ngle{0}
4654 \ifdim\t@X\p@=\z@
4655 \ifdim\t@Y\p@=\z@
4656 \def\ArcTan{0}%
4657 \else
4658 \def\ArcTan{90}%
4659 \ifdim\t@Y\p@<\z@\def\s@gno{-}\fi
4660 \fi
4661 \else
4662 \ifdim\t@Y\p@=\z@
4663 \ifdim\t@X\p@<\z@
4664 \def\ArcTan{180}%
4665 \else
4666 \def\ArcTan{0}%
4667 \fi
4668 \else
4669 \ifdim\t@X\p@<\z@%
4670 \def\addflatt@ngle{180}%
4671 \edef\t@X{\strip@pt\dimexpr-\t@X\p@}%
4672 \edef\t@Y{\strip@pt\dimexpr-\t@Y\p@}%
4673 \ifdim\t@Y\p@<\z@
4674 \def\s@gno{-}%
4675 \edef\t@Y{-\t@Y}%
4676 \fi
4677 \fi
4678 \DivideFN\t@Y by\t@X to \t@A
4679 \ArcTanOf\t@A to\ArcTan
4680 \fi
4681 \fi
4682 \edef\ArcTan{\unless\ifx\s@gno\empty\s@gno\fi\ArcTan}%
4683 \unless\ifnum\addflatt@ngle=0\relax
4684 \edef\ArcTan{%
4685 \strip@pt\dimexpr\ArcTan\p@\ifx\s@gno\empty-\else+\fi
4686 \addflatt@ngle\p@\relax}%
4687 \fi
4688 \edef\x{\noexpand\egroup\noexpand\edef\noexpand#2{\ArcTan}}%
4689 \x\ignorespaces}
4690 \def\ScaleVect#1by#2to#3{\GetCoord(#1)\t@X\t@Y
4691 \@tempdima=\t@X\p@ \@tempdima=#2\@tempdima\Numero\t@X\@tempdima
4692 \@tempdima=\t@Y\p@ \@tempdima=#2\@tempdima\Numero\t@Y\@tempdima
4693 \MakeVectorFrom\t@X\t@Y to#3\ignorespaces}%
4694 \def\ConjVect#1to#2{\GetCoord(#1)\t@X\t@Y
4695 \@tempdima=-\t@Y\p@\Numero\t@Y\@tempdima
4696 \MakeVectorFrom\t@X\t@Y to#2\ignorespaces}%
4697 \def\AddVect#1and#2to#3{\GetCoord(#1)\tu@X\tu@Y
4698 \GetCoord(#2)\td@X\td@Y
4699 \@tempdima\tu@X\p@\advance\@tempdima\td@X\p@ \Numero\t@X\@tempdima
4700 \@tempdima\tu@Y\p@\advance\@tempdima\td@Y\p@ \Numero\t@Y\@tempdima
4701 \MakeVectorFrom\t@X\t@Y to#3\ignorespaces}%
4702 \def\SubVect#1from#2to#3{\GetCoord(#1)\tu@X\tu@Y
4703 \GetCoord(#2)\td@X\td@Y
4704 \@tempdima\td@X\p@\advance\@tempdima-\tu@X\p@ \Numero\t@X\@tempdima
4705 \@tempdima\td@Y\p@\advance\@tempdima-\tu@Y\p@ \Numero\t@Y\@tempdima
4706 \MakeVectorFrom\t@X\t@Y to#3\ignorespaces}%
4707 \def\MultVect#1by{\@ifstar{\@ConjMultVect#1by}{\@MultVect#1by}}%
4708 \def\@MultVect#1by#2to#3{\GetCoord(#1)\tu@X\tu@Y
4709 \GetCoord(#2)\td@X\td@Y
4710 \@tempdima\tu@X\p@ \@tempdimb\tu@Y\p@
4711 \@tempdimc=\td@X\@tempdima\advance\@tempdimc-\td@Y\@tempdimb
4712 \Numero\t@X\@tempdimc
4713 \@tempdimc=\td@Y\@tempdima\advance\@tempdimc\td@X\@tempdimb
4714 \Numero\t@Y\@tempdimc
4715 \MakeVectorFrom\t@X\t@Y to#3\ignorespaces}%
4716 \def\@ConjMultVect#1by#2to#3{\GetCoord(#1)\tu@X\tu@Y
4717 \GetCoord(#2)\td@X\td@Y \@tempdima\tu@X\p@ \@tempdimb\tu@Y\p@
4718 \@tempdimc=\td@X\@tempdima\advance\@tempdimc+\td@Y\@tempdimb
4719 \Numero\t@X\@tempdimc
4720 \@tempdimc=\td@X\@tempdimb\advance\@tempdimc-\td@Y\@tempdima
4721 \Numero\t@Y\@tempdimc
4722 \MakeVectorFrom\t@X\t@Y to#3\ignorespaces}
4723 \def\DivVect#1by#2to#3{\ModAndDirOfVect#2to\@Mod and\@Dir
4724 \DividE\p@ by\@Mod\p@ to\@Mod \ConjVect\@Dir to\@Dir
4725 \ScaleVect#1by\@Mod to\@tempa
4726 \MultVect\@tempa by\@Dir to#3\ignorespaces}%
4727 \def\Arc(#1)(#2)#3{\begingroup
4728 \@tdA=#3\p@
4729 \unless\ifdim\@tdA=\z@
4730 \@Arc(#1)(#2)%
4731 \fi
4732 \endgroup\ignorespaces}%
4733 \def\@Arc(#1)(#2){%
4734 \ifdim\@tdA>\z@
4735 \let\Segno+%
4736 \else
4737 \@tdA=-\@tdA \let\Segno-%
4738 \fi
4739 \Numero\@gradi\@tdA
4740 \ifdim\@tdA>360\p@
4741 \PackageWarning{curve2e}{The arc aperture is \@gradi\space degrees
4742 and gets reduced\MessageBreak%
4743 to the range 0--360 taking the sign into consideration}%
4744 \@whiledim\@tdA>360\p@\do{\advance\@tdA-360\p@}%
4745 \fi
4746 \SubVect#2from#1to\@V \ModOfVect\@V to\@Raggio \CopyVect#2to\@pPun
4747 \CopyVect#1to\@Cent \GetCoord(\@pPun)\@pPunX\@pPunY
4748 \@@Arc
4749 \strokepath\ignorespaces}%
4750 \def\@@Arc{%
4751 \pIIe@moveto{\@pPunX\unitlength}{\@pPunY\unitlength}%
4752 \ifdim\@tdA>180\p@
4753 \advance\@tdA-180\p@
4754 \Numero\@gradi\@tdA
4755 \SubVect\@pPun from\@Cent to\@V
4756 \AddVect\@V and\@Cent to\@sPun
4757 \MultVect\@V by0,-1.3333333to\@V \if\Segno-\ScaleVect\@V by-1to\@V\fi
4758 \AddVect\@pPun and\@V to\@pcPun
4759 \AddVect\@sPun and\@V to\@scPun
4760 \GetCoord(\@pcPun)\@pcPunX\@pcPunY
4761 \GetCoord(\@scPun)\@scPunX\@scPunY
4762 \GetCoord(\@sPun)\@sPunX\@sPunY
4763 \pIIe@curveto{\@pcPunX\unitlength}{\@pcPunY\unitlength}%
4764 {\@scPunX\unitlength}{\@scPunY\unitlength}%
4765 {\@sPunX\unitlength}{\@sPunY\unitlength}%
4766 \CopyVect\@sPun to\@pPun
4767 \fi
4768 \ifdim\@tdA>\z@
4769 \DirFromAngle\@gradi to\@Dir \if\Segno-\ConjVect\@Dir to\@Dir \fi
4770 \SubVect\@Cent from\@pPun to\@V
4771 \MultVect\@V by\@Dir to\@V
4772 \AddVect\@Cent and\@V to\@sPun
4773 \@tdA=.5\@tdA \Numero\@gradi\@tdA
4774 \DirFromAngle\@gradi to\@Phimezzi
4775 \GetCoord(\@Phimezzi)\@cosphimezzi\@sinphimezzi
4776 \@tdB=1.3333333\p@ \@tdB=\@Raggio\@tdB
4777 \@tdC=\p@ \advance\@tdC -\@cosphimezzi\p@ \Numero\@tempa\@tdC
4778 \@tdB=\@tempa\@tdB
4779 \DividE\@tdB by\@sinphimezzi\p@ to\@cZ
4780 \ScaleVect\@Phimezzi by\@cZ to\@Phimezzi
4781 \ConjVect\@Phimezzi to\@mPhimezzi
4782 \if\Segno-%
4783 \let\@tempa\@Phimezzi
4784 \let\@Phimezzi\@mPhimezzi
4785 \let\@mPhimezzi\@tempa
4786 \fi
4787 \SubVect\@sPun from\@pPun to\@V
4788 \DirOfVect\@V to\@V
4789 \MultVect\@Phimezzi by\@V to\@Phimezzi
4790 \AddVect\@sPun and\@Phimezzi to\@scPun
4791 \ScaleVect\@V by-1to\@V
4792 \MultVect\@mPhimezzi by\@V to\@mPhimezzi
4793 \AddVect\@pPun and\@mPhimezzi to\@pcPun
4794 \GetCoord(\@pcPun)\@pcPunX\@pcPunY
4795 \GetCoord(\@scPun)\@scPunX\@scPunY
4796 \GetCoord(\@sPun)\@sPunX\@sPunY
4797 \pIIe@curveto{\@pcPunX\unitlength}{\@pcPunY\unitlength}%
4798 {\@scPunX\unitlength}{\@scPunY\unitlength}%
4799 {\@sPunX\unitlength}{\@sPunY\unitlength}%
4800 \fi}
4801 \def\VectorArc(#1)(#2)#3{\begingroup
4802 \edef\tempG{#3}\@tdA=#3\p@
4803 \fptestF{#3=0}{\@VArc(#1)(#2)}}%
4804
4805 \def\VectorARC(#1)(#2)#3{\begingroup
4806 \edef\tempG{#3}\@tdA=#3\p@
4807 \fptestF{#3=0}{\@VArc(#1)(#2)}}%
4808
4809 \def\@VArc(#1)(#2){%
4810 \fptest{\tempG>\z@}{\let\Segno+}%
4811 {\edef\tempG={-\tempG}\let\Segno-}%
4812 \fptestT{\tempG>360}{%
4813 \PackageWarning{curve2e}{The arc aperture is \tempG\space degrees
4814 and gets reduced^^J%
4815 to the range 0--360 taking the sign into
4816 consideration}%
4817 \edef\tempG{\Modulo{\tempG}{360}}}%
4818 \@tdA=\tempG\p@
4819 \Numero\@gradi\@tdA
4820 \SubVect#1from#2to\@V \ModOfVect\@V to\@Raggio \CopyVect#2to\@pPun
4821 \@tdE=\pIIe@FAW\@wholewidth \@tdE=\pIIe@FAL\@tdE
4822 \DividE\@tdE by \@Raggio\unitlength to\DeltaGradi
4823 \@tdD=\DeltaGradi\p@
4824 \@tdD=57.29578\@tdD \Numero\DeltaGradi\@tdD
4825 \@tdD=\ifx\Segno--\fi\@gradi\p@ \Numero\@tempa\@tdD
4826 \DirFromAngle\@tempa to\@Dir
4827 \MultVect\@V by\@Dir to\@sPun
4828 \edef\@tempA{\ifx\Segno--\@ne\fi}%
4829 \MultVect\@sPun by 0,\@tempA to\@vPun
4830 \DirOfVect\@vPun to\@Dir
4831 \AddVect\@sPun and #1 to \@sPun
4832 \GetCoord(\@sPun)\@tdX\@tdY
4833 \@tdD\ifx\Segno--\fi\DeltaGradi\p@
4834 \@tdD=0.5\@tdD \Numero\DeltaGradi\@tdD
4835 \DirFromAngle\DeltaGradi to\@Dird
4836 \MultVect\@Dir by*\@Dird to\@Dir
4837 \GetCoord(\@Dir)\@xnum\@ynum
4838 \put(\@tdX,\@tdY){\vector(\@xnum,\@ynum){0}}%
4839 \@tdE =\ifx\Segno--\fi\DeltaGradi\p@
4840 \advance\@tdA -\@tdE \Numero\@gradi\@tdA
4841 \CopyVect#1to\@Cent \GetCoord(\@pPun)\@pPunX\@pPunY
4842 \@@Arc\strokepath\endgroup\ignorespaces}%
4843
4844 \def\@VARC(#1)(#2){%
4845 \fptest{\tempG>\z@}{\let\Segno+}%
4846 {\edef\tempG={-\tempG}\let\Segno-}%
4847 \@tdA=\tempG\p@
4848 \Numero\@gradi\@tdA
4849 \fptestT{\tempG>360}{%
4850 \PackageWarning{curve2e}{The arc aperture is \tempG\space degrees
4851 and gets reduced^^J%
4852 to the range 0--360 taking the sign into
4853 consideration}%
4854 \edef\tempG{\Modulo{\tempG}{360}}%
4855 }
4856 \SubVect#1from#2to\@V \ModOfVect\@V to\@Raggio \CopyVect#2to\@pPun
4857 \@tdE=\pIIe@FAW\@wholewidth \@tdE=0.8\@tdE
4858 \DividE\@tdE by \@Raggio\unitlength to\DeltaGradi
4859 \@tdD=\DeltaGradi\p@ \@tdD=57.29578\@tdD \Numero\DeltaGradi\@tdD
4860 \@tdD=\if\Segno--\fi\@gradi\p@ \Numero\@tempa\@tdD
4861 \DirFromAngle\@tempa to\@Dir
4862 \MultVect\@V by\@Dir to\@sPun% corrects the end point
4863 \edef\@tempA{\if\Segno--\fi1}%
4864 \MultVect\@sPun by 0,\@tempA to\@vPun
4865 \DirOfVect\@vPun to\@Dir
4866 \AddVect\@sPun and #1 to \@sPun
4867 \GetCoord(\@sPun)\@tdX\@tdY
4868 \@tdD\if\Segno--\fi\DeltaGradi\p@
4869 \@tdD=.5\@tdD \Numero\@tempB\@tdD
4870 \DirFromAngle\@tempB to\@Dird
4871 \MultVect\@Dir by*\@Dird to\@Dir
4872 \GetCoord(\@Dir)\@xnum\@ynum
4873 \put(\@tdX,\@tdY){\vector(\@xnum,\@ynum){0}}% end point arrowt ip
4874 \@tdE =\DeltaGradi\p@
4875 \advance\@tdA -2\@tdE \Numero\@gradi\@tdA
4876 \CopyVect#1to\@Cent \GetCoord(\@pPun)\@pPunX\@pPunY
4877 \SubVect\@Cent from\@pPun to \@V
4878 \edef\@tempa{\if\Segno-\else-\fi\@ne}%
4879 \MultVect\@V by0,\@tempa to\@vPun
4880 \@tdE\if\Segno--\fi\DeltaGradi\p@
4881 \Numero\@tempB{0.5\@tdE}%
4882 \DirFromAngle\@tempB to\@Dird
4883 \MultVect\@vPun by\@Dird to\@vPun% corrects the starting point
4884 \DirOfVect\@vPun to\@Dir\GetCoord(\@Dir)\@xnum\@ynum
4885 \put(\@pPunX,\@pPunY){\vector(\@xnum,\@ynum){0}}% starting point arrow tip
4886 \edef\@tempa{\if\Segno--\fi\DeltaGradi}%
4887 \DirFromAngle\@tempa to \@Dir
4888 \SubVect\@Cent from\@pPun to\@V
4889 \MultVect\@V by\@Dir to\@V
4890 \AddVect\@Cent and\@V to\@pPun
4891 \GetCoord(\@pPun)\@pPunX\@pPunY
4892 \@@Arc
4893 \strokepath\ignorespaces}%
4894 \def\CurveBetween#1and#2WithDirs#3and#4{%
4895 \StartCurveAt#1WithDir{#3}\relax
4896 \CurveTo#2WithDir{#4}\CurveFinish\ignorespaces}%
4897 \def\StartCurveAt#1WithDir#2{%
4898 \begingroup
4899 \GetCoord(#1)\@tempa\@tempb
4900 \CopyVect\@tempa,\@tempb to\@Pzero
4901 \pIIe@moveto{\@tempa\unitlength}{\@tempb\unitlength}%
4902 \GetCoord(#2)\@tempa\@tempb
4903 \CopyVect\@tempa,\@tempb to\@Dzero
4904 \DirOfVect\@Dzero to\@Dzero
4905 \ignorespaces}
4906 \def\ChangeDir<#1>{%
4907 \GetCoord(#1)\@tempa\@tempb
4908 \CopyVect\@tempa,\@tempb to\@Dzero
4909 \DirOfVect\@Dzero to\@Dzero
4910 \ignorespaces}
4911 \def\CurveFinish{\strokepath\endgroup\ignorespaces}%
4912 \def\FillCurve{\fillpath\endgroup\ignorespaces}
4913 \def\CurveEnd{\fillstroke\endgroup\ignorespaces}
4914 \def\CbezierTo#1WithDir#2AndDists#3And#4{%
4915 \GetCoord(#1)\@tX\@tY \MakeVectorFrom\@tX\@tY to\@Puno
4916 \GetCoord(#2)\@tX\@tY \MakeVectorFrom\@tX\@tY to \@Duno
4917 \DirOfVect\@Duno to\@Duno
4918 \ScaleVect\@Dzero by#3to\@Czero \AddVect\@Pzero and\@Czero to\@Czero
4919 \ScaleVect\@Duno by-#4to \@Cuno \AddVect\@Puno and\@Cuno to \@Cuno
4920 \GetCoord(\@Czero)\@XCzero\@YCzero
4921 \GetCoord(\@Cuno)\@XCuno\@YCuno
4922 \GetCoord(\@Puno)\@XPuno\@YPuno
4923 \pIIe@curveto{\@XCzero\unitlength}{\@YCzero\unitlength}%
4924 {\@XCuno\unitlength}{\@YCuno\unitlength}%
4925 {\@XPuno\unitlength}{\@YPuno\unitlength}%
4926 \CopyVect\@Puno to\@Pzero
4927 \CopyVect\@Duno to\@Dzero
4928 \ignorespaces}%
4929 \def\CbezierBetween#1And#2WithDirs#3And#4UsingDists#5And#6{%
4930 \StartCurveAt#1WithDir{#3}\relax
4931 \CbezierTo#2WithDir#4AndDists#5And{#6}\CurveFinish}
4932
4933 \def\@isTension#1;#2!!{\def\@tempA{#1}%
4934 \def\@tempB{#2}\unless\ifx\@tempB\empty\strip@semicolon#2\fi}
4935 \def\strip@semicolon#1;{\def\@tempB{#1}}
4936 \def\CurveTo#1WithDir#2{%
4937 \def\@Tuno{1}\def\@Tzero{1}\relax
4938 \edef\@Puno{#1}\@isTension#2;!!%
4939 \expandafter\DirOfVect\@tempA to\@Duno
4940 \bgroup\unless\ifx\@tempB\empty\GetCoord(\@tempB)\@Tzero\@Tuno\fi
4941 \DistanceAndDirOfVect\@Puno minus\@Pzero to\@Chord and\@DirChord
4942 \MultVect\@Dzero by*\@DirChord to \@Dpzero
4943 \MultVect\@Duno by*\@DirChord to \@Dpuno
4944 \GetCoord(\@Dpzero)\@DXpzero\@DYpzero
4945 \GetCoord(\@Dpuno)\@DXpuno\@DYpuno
4946 \DivideFN\@Chord by2 to\@semichord
4947 \ifdim\@DXpzero\p@=\z@
4948 \@tdA=1.333333\p@
4949 \Numero\@KCzero{\@semichord\@tdA}%
4950 \fi
4951 \ifdim\@DYpzero\p@=\z@
4952 \@tdA=1.333333\p@
4953 \Numero\@Kpzero{\@semichord\@tdA}%
4954 \fi
4955 \unless\ifdim\@DXpzero\p@=\z@
4956 \unless\ifdim\@DYpzero\p@=\z@
4957 \edef\@CosDzero{\ifdim\@DXpzero\p@<\z@ -\fi\@DXpzero}%
4958 \edef\@SinDzero{\ifdim\@DYpzero\p@<\z@ -\fi\@DYpzero}%
4959 \@tdA=\@semichord\p@ \@tdA=1.333333\@tdA
4960 \DividE\@tdA by\@SinDzero\p@ to \@KCzero
4961 \@tdA=\dimexpr(\p@-\@CosDzero\p@)\relax
4962 \DividE\@KCzero\@tdA by\@SinDzero\p@ to \@KCzero
4963 \fi
4964 \fi
4965 \MultiplyFN\@KCzero by \@Tzero to \@KCzero
4966 \ScaleVect\@Dzero by\@KCzero to\@CPzero
4967 \AddVect\@Pzero and\@CPzero to\@CPzero
4968 \ifdim\@DXpuno\p@=\z@
4969 \@tdA=-1.333333\p@
4970 \Numero\@KCuno{\@semichord\@tdA}%
4971 \fi
4972 \ifdim\@DYpuno\p@=\z@
4973 \@tdA=-1.333333\p@
4974 \Numero\@KCuno{\@semichord\@tdA}%
4975 \fi
4976 \unless\ifdim\@DXpuno\p@=\z@
4977 \unless\ifdim\@DYpuno\p@=\z@
4978 \edef\@CosDuno{\ifdim\@DXpuno\p@<\z@ -\fi\@DXpuno}%
4979 \edef\@SinDuno{\ifdim\@DYpuno\p@<\z@ -\fi\@DYpuno}%
4980 \@tdA=\@semichord\p@ \@tdA=-1.333333\@tdA
4981 \DividE\@tdA by \@SinDuno\p@ to \@KCuno
4982 \@tdA=\dimexpr(\p@-\@CosDuno\p@)\relax
4983 \DividE\@KCuno\@tdA by\@SinDuno\p@ to \@KCuno
4984 \fi
4985 \fi
4986 \MultiplyFN\@KCuno by \@Tuno to \@KCuno
4987 \ScaleVect\@Duno by\@KCuno to\@CPuno
4988 \AddVect\@Puno and\@CPuno to\@CPuno
4989 \GetCoord(\@Puno)\@XPuno\@YPuno
4990 \GetCoord(\@CPzero)\@XCPzero\@YCPzero
4991 \GetCoord(\@CPuno)\@XCPuno\@YCPuno
4992 \pIIe@curveto{\@XCPzero\unitlength}{\@YCPzero\unitlength}%
4993 {\@XCPuno\unitlength}{\@YCPuno\unitlength}%
4994 {\@XPuno\unitlength}{\@YPuno\unitlength}\egroup
4995 \CopyVect\@Puno to\@Pzero
4996 \CopyVect\@Duno to\@Dzero
4997 \ignorespaces}%
4998 \def\Curve{\@ifstar{\let\fillstroke\fillpath\Curve@}%
4999 {\let\fillstroke\strokepath\Curve@}}
5000 \def\Curve@(#1)<#2>{%
5001 \StartCurveAt#1WithDir{#2}%
5002 \@ifnextchar\lp@r\@Curve{%
5003 \PackageWarning{curve2e}{%
5004 Curve specifications must contain at least two nodes!\MessageBreak
5005 Please, control your Curve specifications\MessageBreak}}}
5006
5007 \def\@Curve(#1)<#2>{%
5008 \CurveTo#1WithDir{#2}%
5009 \@ifnextchar\lp@r\@Curve{%
5010 \@ifnextchar[\@ChangeDir\CurveEnd}}
5011 \def\@ChangeDir[#1]{\ChangeDir<#1>\@Curve}
5012 \def\Qurve{\@ifstar{\let\fillstroke\fillpath\Qurve@}%
5013 {\let\fillstroke\strokepath\Qurve@}}
5014
5015 \def\Qurve@(#1)<#2>{%
5016 \StartCurveAt#1WithDir{#2}%
5017 \@ifnextchar\lp@r\@Qurve{%
5018 \PackageWarning{curve2e}{%
5019 Quadratic curve specifications must contain at least
5020 two nodes!\MessageBreak
5021 Please, control your Qurve specifications\MessageBreak}}}%
5022 \def\@Qurve(#1)<#2>{\QurveTo#1WithDir{#2}%
5023 \@ifnextchar\lp@r\@Qurve{%
5024 \@ifnextchar[\@ChangeQDir\CurveEnd}}%
5025 \def\@ChangeQDir[#1]{\ChangeDir<#1>\@Qurve}%
5026 \def\QurveTo#1WithDir#2{%
5027 \edef\@Puno{#1}\DirOfVect#2to\@Duno\bgroup
5028 \DistanceAndDirOfVect\@Puno minus\@Pzero to\@Chord and\@DirChord
5029 \MultVect\@Dzero by*\@Duno to \@Scalar
5030 \YpartOfVect\@Scalar to \@YScalar
5031 \ifdim\@YScalar\p@=\z@
5032 \PackageWarning{curve2e}%
5033 {Quadratic Bezier arcs cannot have their starting\MessageBreak
5034 and ending directions parallel or antiparallel with\MessageBreak
5035 each other. This arc is skipped and replaced with
5036 a dotted line.\MessageBreak}%
5037 \Dotline(\@Pzero)(\@Puno){2}\relax
5038 \else
5039 \MultVect\@Dzero by*\@DirChord to \@Dpzero
5040 \MultVect\@Duno by*\@DirChord to \@Dpuno
5041 \GetCoord(\@Dpzero)\@DXpzero\@DYpzero
5042 \GetCoord(\@Dpuno)\@DXpuno\@DYpuno
5043 \MultiplyFN\@DXpzero by\@DXpuno to\@XXD
5044 \MultiplyFN\@DYpzero by\@DYpuno to\@YYD
5045 \unless\ifdim\@YYD\p@<\z@\ifdim\@XXD\p@<\z@
5046 \PackageWarning{curve2e}%
5047 {Quadratic Bezier arcs cannot have inflection points\MessageBreak
5048 Therefore the tangents to the starting and ending arc\MessageBreak
5049 points cannot be directed to the same half plane.\MessageBreak
5050 This arc is skipped and replaced by a dotted line\MessageBreak}%
5051 \Dotline(\@Pzero)(\@Puno){2}\fi
5052 \else
5053 \edef\@CDzero{\@DXpzero}\relax
5054 \edef\@SDzero{\@DYpzero}\relax
5055 \edef\@CDuno{\@DXpuno}\relax
5056 \edef\@SDuno{\@DYpuno}\relax
5057 \MultiplyFN\@SDzero by\@CDuno to\@tempA
5058 \MultiplyFN\@SDuno by\@CDzero to\@tempB
5059 \edef\@tempA{\strip@pt\dimexpr\@tempA\p@-\@tempB\p@}\relax
5060 \@tdA=\@SDuno\p@ \@tdB=\@Chord\p@ \@tdC=\@tempA\p@
5061 \edef\@tempC{\strip@pt\dimexpr \@tdA*\@tdB/\@tdC}\relax
5062 \MultiplyFN\@tempC by\@CDzero to \@XC
5063 \MultiplyFN\@tempC by\@SDzero to \@YC
5064 \ModOfVect\@XC,\@YC to\@KC
5065 \ScaleVect\@Dzero by\@KC to\@CP
5066 \AddVect\@Pzero and\@CP to\@CP
5067 \GetCoord(\@Pzero)\@XPzero\@YPzero
5068 \GetCoord(\@Puno)\@XPuno\@YPuno
5069 \GetCoord(\@CP)\@XCP\@YCP
5070 \@ovxx=\@XPzero\unitlength \@ovyy=\@YPzero\unitlength
5071 \@ovdx=\@XCP\unitlength \@ovdy=\@YCP\unitlength
5072 \@xdim=\@XPuno\unitlength \@ydim=\@YPuno\unitlength
5073 \pIIe@bezier@QtoC\@ovxx\@ovdx\@ovro
5074 \pIIe@bezier@QtoC\@ovyy\@ovdy\@ovri
5075 \pIIe@bezier@QtoC\@xdim\@ovdx\@clnwd
5076 \pIIe@bezier@QtoC\@ydim\@ovdy\@clnht
5077 \pIIe@moveto\@ovxx\@ovyy
5078 \pIIe@curveto\@ovro\@ovri\@clnwd\@clnht\@xdim\@ydim
5079 \fi\fi\egroup
5080 \CopyVect\@Puno to\@Pzero
5081 \CopyVect\@Duno to\@Dzero
5082 \ignorespaces}
5083
5084 % \end{macrocode}
5085 %\iffalse
5086 %</v161>
5087 %\fi
5088 % \Finale
5089 % \endinput
5090
5091 %^^A%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%