| 1 |
<!-- this file was generated automatically by noweave; better not edit it--> |
| 2 |
<html><head><title>mathsPIC.nw</title></head><body><center><h1> <tt>mathspic</tt> in Perl </h1></center> |
| 3 |
<center><h2> |
| 4 |
<table> |
| 5 |
<tr><td><address> |
| 6 |
<b>Apostolos Syropoulos</b><br> |
| 7 |
366, 28th October Str.<br> |
| 8 |
GR-671 00 Xanthi<br> |
| 9 |
Greece<br> |
| 10 |
email: <tt>[email protected]</tt> |
| 11 |
</address></td> |
| 12 |
<td><address> |
| 13 |
<b>R.W.D. Nickalls</b><br/> |
| 14 |
Consultant in Anaesthesia & Intensive Care (retired)<br/> |
| 15 |
c/o Department of Anaesthesia<br/> |
| 16 |
Nottingham University Hospitals<br/> |
| 17 |
<a name="NWDCUvTi-1">City Hospital Campus</a><br/> |
| 18 |
Hucknall Road<br/> |
| 19 |
Nottingham NG5 1PB, UK<br/> |
| 20 |
email:<tt>[email protected]</tt> |
| 21 |
</address></td> |
| 22 |
</table></h2> |
| 23 |
version 1.13 Apr 26, 2010 |
| 24 |
</center> |
| 25 |
|
| 26 |
<h3><b>Introduction</b></h3><p> |
| 27 |
<tt>mathspic</tt> is a graphics program which implements a simple |
| 28 |
programming notation, <i>mathspic</i>, suitable for the |
| 29 |
creation of diagrams or mathematical figures. |
| 30 |
<tt>mathspic</tt>'s input is a LaTeX file containing |
| 31 |
<tt>mathspic</tt> plotting commands. |
| 32 |
<tt>mathspic</tt>'s output is the equivalent LaTeX file |
| 33 |
containing PiCTeX plotting commands. |
| 34 |
Technically, therefore, <tt>mathspic</tt> |
| 35 |
is a preprocessor or `filter' for use with the PiCTeX drawing engine. |
| 36 |
<tt>mathspic</tt> was originally written in PowerBASIC 3.5, a |
| 37 |
DOS-based programming language. Since, many |
| 38 |
potential users are working in rather different programming environments, |
| 39 |
the authors thought of porting <tt>mathspic</tt> into another programming |
| 40 |
cross-platform language which would be widely available. |
| 41 |
The authors decided to rewrite <tt>mathspic</tt> in Perl |
| 42 |
since not only is Perl pretty stable, but it has |
| 43 |
extensive mathematical support.<p> |
| 44 |
|
| 45 |
<h3><b>Program Structure</b></h3><p> |
| 46 |
<a name="NWDCUvTi-2">Initially, we define a little package that is used to implement the </a><code>loop</code> |
| 47 |
command. Then, we must do is to check the possible command line arguments. |
| 48 |
Next, we process the input file. |
| 49 |
If the user has used the <code>-b</code> (see below), the program will `beep' |
| 50 |
if any errors are found during processing. |
| 51 |
We need some auxiliary subroutines in order to properly parse the input |
| 52 |
file and of course to handle the various commands. We also need a |
| 53 |
few global variables. |
| 54 |
|
| 55 |
<pre><a name="NWCUvTi-1p0Y9w-1" href="#NWDCUvTi-2"><dfn><*>=</dfn></a> |
| 56 |
#!/usr/bin/perl |
| 57 |
# |
| 58 |
#(c) Copyright 2005-2010 |
| 59 |
# Apostolos Syropoulos & R.W.D. Nickalls |
| 60 |
# [email protected] [email protected] |
| 61 |
# |
| 62 |
# This program can be redistributed and/or modified under the terms |
| 63 |
# of the LaTeX Project Public License Distributed from CTAN |
| 64 |
# archives in directory macros/latex/base/lppl.txt; either |
| 65 |
# version 1 of the License, or any later version. |
| 66 |
# |
| 67 |
<a name="NWCUvTi-1p0Y9w-1-u1" href="#NWDCUvTi-3"><i><package <tt>DummyFH</tt> ></i></a> |
| 68 |
package main; |
| 69 |
use Math::Trig; |
| 70 |
<a name="NWCUvTi-1p0Y9w-1-u2" href="#NWDCUvTi-8"><i><Define global variables></i></a> |
| 71 |
<a name="NWCUvTi-1p0Y9w-1-u3" href="#NWDCUvTi-9"><i><subroutine definitions></i></a> |
| 72 |
<a name="NWCUvTi-1p0Y9w-1-u4" href="#NWDCUvTi-4"><i><Check for command line arguments></i></a> |
| 73 |
<a name="NWCUvTi-1p0Y9w-1-u5" href="#NWDCUvTi-7"><i><process file></i></a> |
| 74 |
print $alarm if $no_errors > 0; |
| 75 |
__END__ |
| 76 |
|
| 77 |
</pre><p><a name="NWDCUvTi-3">The package </a><code>DummyFH</code> is used in the implementation of the <code>loop</code> command. |
| 78 |
It creates a dummy filehandle that is associated with an array of strings. Since |
| 79 |
we only read data from this dummy filehandle, we implement the <code>READLINE</code> subroutine. |
| 80 |
When we read a line from this dummy filehandle, we actually requesting the next entry |
| 81 |
of the array (if any). That is why we use the package variable <code>$index</code>. When there |
| 82 |
are no more entries in the array, subroutine <code>READLINE</code> returns the value <code>undef</code> |
| 83 |
so to falsify loop that controls the consumption of input from this dummy filehandle. |
| 84 |
|
| 85 |
<pre><a name="NWCUvTi-2YwRNH-1" href="#NWDCUvTi-3"><dfn><package <tt>DummyFH</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-2"><-U</a>)</b> |
| 86 |
package DummyFH; |
| 87 |
my $index = 0; |
| 88 |
sub TIEHANDLE { |
| 89 |
my $class = shift; |
| 90 |
my $self= shift; |
| 91 |
bless $self, $class; |
| 92 |
} |
| 93 |
sub READLINE { |
| 94 |
my $self = shift; |
| 95 |
#shift @$self; |
| 96 |
if ($index > $#$self) { |
| 97 |
$index = 0; |
| 98 |
return undef; |
| 99 |
} |
| 100 |
else { |
| 101 |
return $self->[$index++]; |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
</pre><p><tt>mathspic</tt> accepts at most four command-line switches, namely |
| 106 |
<tt>-b</tt> for enabling the beep, <tt>-s</tt> for automatic |
| 107 |
screen viewing of the output-file, |
| 108 |
<tt>-c</tt> for cleaning out all comment-lines, |
| 109 |
and <tt>-o</tt> with a following file-name |
| 110 |
for specifying the output file-name. |
| 111 |
<tt><a name="NWDCUvTi-4">mathspic</a></tt> requires the name of an existing input-file |
| 112 |
(the so-called <tt>mathspic</tt>-file) containing |
| 113 |
<tt>mathspic</tt>commands. |
| 114 |
If no command-line arguments are supplied, we print a |
| 115 |
suitable usage message indicating the syntax. |
| 116 |
For each command-line argument we set a global |
| 117 |
variable. The default behavior is that the `bell' does not beep |
| 118 |
and comment-lines are not removed from the output-file. |
| 119 |
|
| 120 |
<pre><a name="NWCUvTi-122Dzz-1" href="#NWDCUvTi-4"><dfn><Check for command line arguments>=</dfn></a> <b>(<a href="#NWDCUvTi-2"><-U</a>)</b> |
| 121 |
our $alarm=""; |
| 122 |
our $comments_on=1; |
| 123 |
our $out_file="default"; |
| 124 |
our $argc=@ARGV; |
| 125 |
if ($argc == 0 || $argc > 5 ){ # no command line arguments or more than 4 |
| 126 |
# arguments |
| 127 |
die "\nmathspic version $version_number\n" . |
| 128 |
"Usage: mathspic [-h] [-b] [-c] [-o <out file>] <in file>\n\n"; |
| 129 |
} |
| 130 |
else { |
| 131 |
<a name="NWCUvTi-122Dzz-1-u1" href="#NWDCUvTi-5"><i><Process command line arguments></i></a> |
| 132 |
print "This is mathspic version $version_number\n"; |
| 133 |
} |
| 134 |
<a name="NWCUvTi-122Dzz-1-u2" href="#NWDCUvTi-6"><i><Check if .m file exists></i></a> |
| 135 |
|
| 136 |
</pre><p><a name="NWDCUvTi-5">In order to get the various command-line arguments we use a simple</a> |
| 137 |
<code>while</code> loop that checks each element of the array <code>@ARGV</code>. We check |
| 138 |
for all the switches, and we get the name of the input-file. |
| 139 |
|
| 140 |
<pre><a name="NWCUvTi-LnOV9-1" href="#NWDCUvTi-5"><dfn><Process command line arguments>=</dfn></a> <b>(<a href="#NWDCUvTi-4"><-U</a>)</b> |
| 141 |
our $file = ""; |
| 142 |
SWITCHES: |
| 143 |
while($_ = $ARGV[0]) { |
| 144 |
shift; |
| 145 |
if (/^-h$/) { |
| 146 |
die "\nThis is mathspic version $version_number\n" . |
| 147 |
"Type \"man mathspic\" for detailed help\n". |
| 148 |
"Usage:\tmathspic [-h] [-b] [-c] [-o <out file>] <in file>\n" . |
| 149 |
"\twhere,\n" . |
| 150 |
"\t[-b]\tenables bell sound if error exists\n" . |
| 151 |
"\t[-c]\tdisables comments in ouput file\n" . |
| 152 |
"\t[-h]\tgives this help listing\n" . |
| 153 |
"\t[-o]\tcreates specified output file\n\n"; |
| 154 |
} |
| 155 |
elsif (/^-b$/) { |
| 156 |
$alarm = chr(7); |
| 157 |
} |
| 158 |
elsif (/^-c$/) { |
| 159 |
$comments_on = 0; |
| 160 |
} |
| 161 |
elsif (/^-o$/) { |
| 162 |
die "No output file specified!\n" if !@ARGV; |
| 163 |
$out_file = $ARGV[0]; |
| 164 |
shift; |
| 165 |
} |
| 166 |
elsif (/^-\w+/) { |
| 167 |
die "$_: Illegal command line switch!\n"; |
| 168 |
} |
| 169 |
else { |
| 170 |
$file = $_; |
| 171 |
} |
| 172 |
}my ($xA, $yA, $xB, $yB, $dist)=@_; |
| 173 |
die "No input file specified!\n" if $file eq ""; |
| 174 |
|
| 175 |
</pre><p><a name="NWDCUvTi-6">In order to check whether the input-file exists, we simply use the</a> |
| 176 |
<code>-e</code> operator. First we check to see if <code>$file</code> exits. |
| 177 |
If the input-file does exist then the variable <code>$file</code> contains |
| 178 |
the file name. In case the user has not specified an output |
| 179 |
file, the default output file name is the name of the input file with |
| 180 |
extension <code>.mt</code>. Finally, the program outputs all error messages to |
| 181 |
the screen and to a log file. The name of the log file consists of |
| 182 |
the contents of the variable <code>$file</code> and the extension <code>.mlg</code>. |
| 183 |
|
| 184 |
<pre><a name="NWCUvTi-2K3CIm-1" href="#NWDCUvTi-6"><dfn><Check if .m file exists>=</dfn></a> <b>(<a href="#NWDCUvTi-4"><-U</a>)</b> |
| 185 |
our ($source_file, $log_file); |
| 186 |
if (! -e $file) { |
| 187 |
die "$file: no such file!\n" if (! (-e "$file.m")); |
| 188 |
$source_file = "$file.m"; |
| 189 |
} |
| 190 |
else { |
| 191 |
$source_file = $file; |
| 192 |
$file = $1 if $file =~ /(\w[\w-\.]+)\.\w+/; |
| 193 |
} |
| 194 |
$out_file= "$file.mt" if $out_file eq "default"; |
| 195 |
$log_file= "$file.mlg"; |
| 196 |
|
| 197 |
</pre><p><a name="NWDCUvTi-7">Now that we have all the command line arguments, we can start processing</a> |
| 198 |
the input file. This is done by calling the subroutine <code>process_input</code>. |
| 199 |
Before that we must open all necessary files. Next, |
| 200 |
we print some `header' information to the output file and to the log file. |
| 201 |
|
| 202 |
<pre><a name="NWCUvTi-EP1QE-1" href="#NWDCUvTi-7"><dfn><process file>=</dfn></a> <b>(<a href="#NWDCUvTi-2"><-U</a>)</b> |
| 203 |
open(IN,"$source_file")||die "Can't open source file: $source_file\n"; |
| 204 |
open(OUT,">$out_file")||die "Can't open output file: $out_file\n"; |
| 205 |
open(LOG,">$log_file")||die "Can't open log file: $log_file\n"; |
| 206 |
print_headers; |
| 207 |
process_input(IN,""); |
| 208 |
|
| 209 |
</pre><p>In this section we define a few global variables. More specifically: |
| 210 |
the variable <code>$version_number</code> contains the current version number of the |
| 211 |
program, the variable <code>$commandLineArgs</code> contains the command line arguments. |
| 212 |
These two variables are used in the <code>print_headers</code> subroutine. |
| 213 |
The variable <code>$command</code> will contain the whole current input line. |
| 214 |
Hash <code>%PointTable</code> is used to store point names and related |
| 215 |
information. Hash <code>%VarTable</code> is used to store mathspic variable names |
| 216 |
and related information, while the associative array <code>%ConstTable</code> contains the |
| 217 |
names of constants. Note that the values of both constants and variables are |
| 218 |
kept in <code>%VarTable</code>. |
| 219 |
The variable <code>$no_errors</code> is incremented whenever the |
| 220 |
program encounters an error in the input file. The variables <code>$xunits</code>, |
| 221 |
<code>$yunits</code> and <code>$units</code> are related to the <code>paper</code> command. |
| 222 |
In particular, the variable <code>$units</code> is used to parse the unit part of the |
| 223 |
<code>unit</code> part of the <code>paper</code> command. The variable <code>$defaultsymbol</code> is used to |
| 224 |
set the point shape. The constant <code>PI</code> holds the value of the mathematical |
| 225 |
constant pi. |
| 226 |
The constant <code>R2D</code> holds the transformation factor to transform radians to |
| 227 |
degrees. The constant <code>D2R</code> holds the transformation factor |
| 228 |
to transform degrees to radians, i.e., the value <code>1/R2D</code>. The global variables |
| 229 |
<code>$arrowLength</code>, <code>$arrowAngleB</code> and <code>$arrowAngleC</code> are actually parameters that |
| 230 |
<a name="NWDCUvTi-8">are used by the subroutines that draw arrows. Since </a><code>$arrowLength</code> is actually |
| 231 |
a length, variable <code>$arrowLenghtUnits</code> holds the units of measure in which |
| 232 |
this length is expressed. The hash table <code>%DimOfPoint</code> contains the side or the |
| 233 |
radius of a point whose plot-symbol is a square or a circle, respectively. In case the |
| 234 |
default point symbol is a circle or a square, variable <code>$GlobalDimOfPoints</code> is used |
| 235 |
to store the length of the radius or the length of the side of default point symbol, |
| 236 |
respectively. Variable <code>$LineThickness</code> holds the current line thickness (the |
| 237 |
default value is 0.4 pt). |
| 238 |
|
| 239 |
<pre><a name="NWCUvTi-xIn58-1" href="#NWDCUvTi-8"><dfn><Define global variables>=</dfn></a> <b>(<a href="#NWDCUvTi-2"><-U</a>)</b> |
| 240 |
our $version_number = "1.13 Apr 26, 2010"; |
| 241 |
our $commandLineArgs = join(" ", @ARGV); |
| 242 |
our $command = ""; |
| 243 |
our $curr_in_file = ""; |
| 244 |
our %PointTable = (); |
| 245 |
our %VarTable = (); |
| 246 |
our %ConstTable = (); |
| 247 |
our $no_errors = 0; |
| 248 |
our $xunits = "1pt"; |
| 249 |
our $yunits = "1pt"; |
| 250 |
our $units = "pt|pc|in|bp|cm|mm|dd|cc|sp"; |
| 251 |
our $defaultsymbol = "\$\\bullet\$"; |
| 252 |
our $defaultLFradius = 0; |
| 253 |
use constant PI => atan2(1,1)*4; |
| 254 |
use constant R2D => 180 / PI; |
| 255 |
use constant D2R => PI / 180; |
| 256 |
our $arrowLength = 2; |
| 257 |
our $arrowLengthUnits = "mm"; |
| 258 |
our $arrowAngleB = 30; |
| 259 |
our $arrowAngleC = 40; |
| 260 |
our %DimOfPoint = (); |
| 261 |
our $GlobalDimOfPoints = 0; |
| 262 |
our @Macros = (); |
| 263 |
our $LineThickness = 0.4; |
| 264 |
|
| 265 |
</pre><p>In this section we define the various subroutines that are needed in order |
| 266 |
to process the input file. |
| 267 |
|
| 268 |
<p> Subroutine <tt>mpp</tt> is a mathspic preprocessor that allows the definition |
| 269 |
and use of macros with or without arguments. For the moment it is an experimental |
| 270 |
feature and it should be used with care. |
| 271 |
|
| 272 |
<p> Subroutine <tt>PrintErrorMessage</tt> is used to print error messages |
| 273 |
to the screen, to the output file and to the log file. |
| 274 |
|
| 275 |
<p> Subroutine <tt>PrintWarningMessage</tt> is used to print warning messages |
| 276 |
to the screen, to the output file and to the log file. |
| 277 |
|
| 278 |
<p> Subroutine <tt>PrintFatalError</tt> is used to print an error message |
| 279 |
to the screen and to abort execution, where the error is considered fatal |
| 280 |
and not recoverable. |
| 281 |
|
| 282 |
<p>Subroutine <tt>chk_lparen</tt> checks whether the next input |
| 283 |
character is a left parenthesis. Subroutine <tt>chk_rparen</tt> |
| 284 |
checks whether the next input character is a right parenthesis. Subroutine |
| 285 |
<tt>chk_comment</tt> checks whether a given command is followed by a trailing |
| 286 |
comment. In the same spirit, we define the subroutines <tt>chk_lcb</tt>, |
| 287 |
<tt>chk_rcb</tt>, <tt>chk_lsb</tt>, and <tt>chk_rsb</tt> which check for |
| 288 |
opening and closing curly and square brackets respectively. |
| 289 |
The subroutine <code>chk_comma</code> checks whether the next token is a comma. |
| 290 |
|
| 291 |
<p> Subroutine <code>print_headers</code> is used to print a header to the output file, |
| 292 |
so a user knows that the file has been generated by <tt>mathspic</tt>. |
| 293 |
|
| 294 |
<p> Subroutine <code>get_point</code> is used to parse a point name and to |
| 295 |
check whether the point exists (i.e whether the point has been defined). |
| 296 |
|
| 297 |
<p> Subroutine <code>perpendicular</code> is used to compute the coordinates of the |
| 298 |
foot of perpendicular line from some point P to a line AB. |
| 299 |
|
| 300 |
<p> Subroutine <code>Length</code> is used to compute the distance between two |
| 301 |
points A and B. |
| 302 |
|
| 303 |
<p> Subroutine <code>triangleArea</code> computes the area of a triangle defined |
| 304 |
by three points. |
| 305 |
|
| 306 |
<p> Subroutine <code>PointOnLine</code> is used to compute the coordinates of |
| 307 |
a point on a line segment AB and a distance d units from A towards B. |
| 308 |
|
| 309 |
<p> Subroutine <code>circumCircleCenter</code> takes six arguments that are the |
| 310 |
coordinates of three points and computes the center of the circle that |
| 311 |
passes through the three points which define the triangle. |
| 312 |
|
| 313 |
<p> Subroutine <code>ComputeDist</code> is used to compute a numeric value that is |
| 314 |
specified by either a variable name, a pair of points, or just a number. |
| 315 |
|
| 316 |
<p> Subroutine <code>intersection4points</code> is used to compute the coordinates |
| 317 |
of the point of intersection of two lines specified by the four arguments |
| 318 |
(i.e. two arguments for each point). |
| 319 |
|
| 320 |
<p> Subroutine <code>IncircleCenter</code> is used to compute the center and |
| 321 |
the radius of a circle that touches internally the sides of a triangle, |
| 322 |
the coordinates of the three points which define the triangle |
| 323 |
being the arguments of the subroutine. |
| 324 |
|
| 325 |
<p> Subroutine <code>Angle</code> determines the opening in degrees of an angle |
| 326 |
defined by three points which are the arguments of this subroutine. |
| 327 |
|
| 328 |
<p> Subroutine <code>excircle</code> computes the center and the radius of |
| 329 |
a circle that externally touches a given side (4th and 5th arguments) of |
| 330 |
triangle (determined by the 1st, the 2nd and the 3rd argument). |
| 331 |
|
| 332 |
<p> Subroutine <code>DrawLineOrArrow</code> is used to parse the arguments of the commands |
| 333 |
<code>drawline</code>, <code>drawthickline</code>, <code>drawarrow</code>, <code>drawthickarrow</code> and |
| 334 |
<code>drawCurve</code>. |
| 335 |
|
| 336 |
<p> Subroutine <code>drawarrows</code> is used to draw one or more arrows between points. |
| 337 |
|
| 338 |
<p> Subroutine <code>drawlines</code> is used to draw one or more lines between points. |
| 339 |
|
| 340 |
<p> Subroutine <code>drawCurve</code> is used to draw a curve between an odd number of points. |
| 341 |
|
| 342 |
<p> Subroutine <code>drawpoints</code> is used to draw the point symbol of one or more points. |
| 343 |
|
| 344 |
<p> Subroutine <code>drawAngleArc</code> is used to draw an arc line within an angle. |
| 345 |
|
| 346 |
<p> Subroutine <code>drawAngleArrow</code> is used to draw an arc line with an arrow on the end, |
| 347 |
within an angle. |
| 348 |
|
| 349 |
<p> Subroutine <code>expr</code> and subroutines <code>term</code>, <code>factor</code> and |
| 350 |
<code>primitive</code> are used to parse an expression that follows a variable |
| 351 |
declaration. |
| 352 |
|
| 353 |
<p> Subroutine <code>memberOf</code> is used to determine whether a string is a |
| 354 |
member of a list of strings. |
| 355 |
|
| 356 |
<p> Subroutine <code>midpoint</code> computes the midpoint of two points. |
| 357 |
|
| 358 |
<p> Subroutine <code>tand</code> computes the tangent of an angle, where the |
| 359 |
angle is expressed in degrees. |
| 360 |
|
| 361 |
<p> Subroutine <code>get_string</code> scans a string in order to extract a |
| 362 |
valid mathspic string. |
| 363 |
|
| 364 |
<p> Subroutine <code>is_tainted</code> checks whether a string contains data that |
| 365 |
may be proved harmful if used as arguments to a shell escape. |
| 366 |
|
| 367 |
<p> Subroutine <code>noOfDigits</code> has one argument which is a number and |
| 368 |
returns the number of decimal digits it has. |
| 369 |
|
| 370 |
<p> Subroutine <code>drawsquare</code> has one argument which is the radius of point |
| 371 |
and yields LaTeX code that draws a square. |
| 372 |
|
| 373 |
<p> Subroutine <code>X2sp</code> can be used to transform a length to sp units. |
| 374 |
|
| 375 |
<p> <a name="NWDCUvTi-9">Subroutine </a><code>sp2X</code> can be used to transform a length expressed in sp units |
| 376 |
to any other acceptable unit. |
| 377 |
|
| 378 |
<p> Subroutine <code>setLineThickness</code> is used to determine the length of the |
| 379 |
linethickness in the current paper units. |
| 380 |
|
| 381 |
<p> Subroutine <code>process_input</code> parses the input file and any other file |
| 382 |
being included in the main file, and generates output. |
| 383 |
|
| 384 |
<pre><a name="NWCUvTi-2AA3uL-1" href="#NWDCUvTi-9"><dfn><subroutine definitions>=</dfn></a> <b>(<a href="#NWDCUvTi-2"><-U</a>)</b> |
| 385 |
<a name="NWCUvTi-2AA3uL-1-u1" href="#NWDCUvTi-A"><i><subroutine <tt>mpp</tt> ></i></a> |
| 386 |
<a name="NWCUvTi-2AA3uL-1-u2" href="#NWDCUvTi-B"><i><subroutine <tt>PrintErrorMessage</tt> ></i></a> |
| 387 |
<a name="NWCUvTi-2AA3uL-1-u3" href="#NWDCUvTi-C"><i><subroutine <tt>PrintWarningMessage</tt> ></i></a> |
| 388 |
<a name="NWCUvTi-2AA3uL-1-u4" href="#NWDCUvTi-D"><i><subroutine <tt>PrintFatalError</tt> ></i></a> |
| 389 |
<a name="NWCUvTi-2AA3uL-1-u5" href="#NWDCUvTi-E"><i><subroutine <tt>chk_lparen</tt> ></i></a> |
| 390 |
<a name="NWCUvTi-2AA3uL-1-u6" href="#NWDCUvTi-F"><i><subroutine <tt>chk_rparen</tt> ></i></a> |
| 391 |
<a name="NWCUvTi-2AA3uL-1-u7" href="#NWDCUvTi-G"><i><subroutine <tt>chk_lcb</tt> ></i></a> |
| 392 |
<a name="NWCUvTi-2AA3uL-1-u8" href="#NWDCUvTi-H"><i><subroutine <tt>chk_rcb</tt> ></i></a> |
| 393 |
<a name="NWCUvTi-2AA3uL-1-u9" href="#NWDCUvTi-I"><i><subroutine <tt>chk_lsb</tt> ></i></a> |
| 394 |
<a name="NWCUvTi-2AA3uL-1-u10" href="#NWDCUvTi-J"><i><subroutine <tt>chk_rsb</tt> ></i></a> |
| 395 |
<a name="NWCUvTi-2AA3uL-1-u11" href="#NWDCUvTi-K"><i><subroutine <tt>chk_comma</tt> ></i></a> |
| 396 |
<a name="NWCUvTi-2AA3uL-1-u12" href="#NWDCUvTi-L"><i><subroutine <tt>chk_comment</tt> ></i></a> |
| 397 |
<a name="NWCUvTi-2AA3uL-1-u13" href="#NWDCUvTi-M"><i><subroutine <tt>print_headers</tt> ></i></a> |
| 398 |
<a name="NWCUvTi-2AA3uL-1-u14" href="#NWDCUvTi-N"><i><subroutine <tt>get_point</tt> ></i></a> |
| 399 |
<a name="NWCUvTi-2AA3uL-1-u15" href="#NWDCUvTi-O"><i><subroutine <tt>perpendicular</tt> ></i></a> |
| 400 |
<a name="NWCUvTi-2AA3uL-1-u16" href="#NWDCUvTi-P"><i><subroutine <tt>Length</tt> ></i></a> |
| 401 |
<a name="NWCUvTi-2AA3uL-1-u17" href="#NWDCUvTi-Q"><i><subroutine <tt>triangleArea</tt> ></i></a> |
| 402 |
<a name="NWCUvTi-2AA3uL-1-u18" href="#NWDCUvTi-R"><i><subroutine <tt>pointOnLine</tt> ></i></a> |
| 403 |
<a name="NWCUvTi-2AA3uL-1-u19" href="#NWDCUvTi-S"><i><subroutine <tt>circumCircleCenter</tt> ></i></a> |
| 404 |
<a name="NWCUvTi-2AA3uL-1-u20" href="#NWDCUvTi-T"><i><subroutine <tt>ComputeDist</tt> ></i></a> |
| 405 |
<a name="NWCUvTi-2AA3uL-1-u21" href="#NWDCUvTi-U"><i><subroutine <tt>intersection4points</tt> ></i></a> |
| 406 |
<a name="NWCUvTi-2AA3uL-1-u22" href="#NWDCUvTi-V"><i><subroutine <tt>IncircleCenter</tt> ></i></a> |
| 407 |
<a name="NWCUvTi-2AA3uL-1-u23" href="#NWDCUvTi-W"><i><subroutine <tt>Angle</tt> ></i></a> |
| 408 |
<a name="NWCUvTi-2AA3uL-1-u24" href="#NWDCUvTi-X"><i><subroutine <tt>excircle</tt> ></i></a> |
| 409 |
<a name="NWCUvTi-2AA3uL-1-u25" href="#NWDCUvTi-Y"><i><subroutine <tt>DrawLineOrArrow</tt> ></i></a> |
| 410 |
<a name="NWCUvTi-2AA3uL-1-u26" href="#NWDCUvTi-Z"><i><subroutine <tt>drawarrows</tt> ></i></a> |
| 411 |
<a name="NWCUvTi-2AA3uL-1-u27" href="#NWDCUvTi-a"><i><subroutine <tt>drawlines</tt> ></i></a> |
| 412 |
<a name="NWCUvTi-2AA3uL-1-u28" href="#NWDCUvTi-b"><i><subroutine <tt>drawCurve</tt> ></i></a> |
| 413 |
<a name="NWCUvTi-2AA3uL-1-u29" href="#NWDCUvTi-c"><i><subroutine <tt>drawpoints</tt> ></i></a> |
| 414 |
<a name="NWCUvTi-2AA3uL-1-u30" href="#NWDCUvTi-d"><i><subroutine <tt>drawAngleArc</tt> ></i></a> |
| 415 |
<a name="NWCUvTi-2AA3uL-1-u31" href="#NWDCUvTi-e"><i><subroutine <tt>drawAngleArrow</tt> ></i></a> |
| 416 |
<a name="NWCUvTi-2AA3uL-1-u32" href="#NWDCUvTi-f"><i><subroutine <tt>expr</tt> ></i></a> |
| 417 |
<a name="NWCUvTi-2AA3uL-1-u33" href="#NWDCUvTi-g"><i><subroutine <tt>memberOf</tt> ></i></a> |
| 418 |
<a name="NWCUvTi-2AA3uL-1-u34" href="#NWDCUvTi-h"><i><subroutine <tt>midpoint</tt> ></i></a> |
| 419 |
<a name="NWCUvTi-2AA3uL-1-u35" href="#NWDCUvTi-i"><i><subroutine <tt>tand</tt> ></i></a> |
| 420 |
<a name="NWCUvTi-2AA3uL-1-u36" href="#NWDCUvTi-j"><i><subroutine <tt>get_string</tt> ></i></a> |
| 421 |
<a name="NWCUvTi-2AA3uL-1-u37" href="#NWDCUvTi-k"><i><subroutine <tt>is_tainted</tt> ></i></a> |
| 422 |
<a name="NWCUvTi-2AA3uL-1-u38" href="#NWDCUvTi-l"><i><subroutine <tt>noOfDigits</tt> ></i></a> |
| 423 |
<a name="NWCUvTi-2AA3uL-1-u39" href="#NWDCUvTi-m"><i><subroutine <tt>drawsquare</tt> ></i></a> |
| 424 |
<a name="NWCUvTi-2AA3uL-1-u40" href="#NWDCUvTi-n"><i><subroutine <tt>X2sp</tt> ></i></a> |
| 425 |
<a name="NWCUvTi-2AA3uL-1-u41" href="#NWDCUvTi-o"><i><subroutine <tt>sp2X</tt> ></i></a> |
| 426 |
<a name="NWCUvTi-2AA3uL-1-u42" href="#NWDCUvTi-p"><i><subroutine <tt>setLineThickness</tt> ></i></a> |
| 427 |
<a name="NWCUvTi-2AA3uL-1-u43" href="#NWDCUvTi-q"><i><subroutine <tt>process_input</tt> ></i></a> |
| 428 |
|
| 429 |
</pre><p>Subroutine <tt>mpp</tt> is an implementation of a mathspic preprocessor that allows |
| 430 |
the definition of one-line macros with or without arguments. Macro definition has the |
| 431 |
following syntax: |
| 432 |
<center> |
| 433 |
<tt>"%def" macro_name "(" [ parameters ] ")" macro_code |
| 434 |
</center> |
| 435 |
where parameters is a list of comma separated strings (e.g., x,y,z). Once a macro is |
| 436 |
defined it can be used or it can be undefined. To undefine a macro one has to use |
| 437 |
the following command: |
| 438 |
<center> |
| 439 |
<tt>"%undef" [ macro_name ] |
| 440 |
</center |
| 441 |
This means that an undef command without an accompanying macro name has no effect |
| 442 |
at all. In order to use a macro we simply type its name and its arguments in |
| 443 |
parentheses. Note that macro arguments should not contain spaces. If a macro has no |
| 444 |
argument, there is no need to type any parentheses. We will now describe briefly how |
| 445 |
the macro processor operates. |
| 446 |
<p> If the current input line starts with <tt>%def</tt>, then we assume that we have |
| 447 |
a macro definition. We parse each component of the macro definition and finally we |
| 448 |
store the macro name, the macro code and the macro parameters (if any) in an anonymous |
| 449 |
hash that eventually becomes part of an array. If we encounter any error, we simply |
| 450 |
<a name="NWDCUvTi-A">skip to the next line after printing a suitable error message. Now, if the first tokens</a> |
| 451 |
of an input line are <tt>%undef</tt>, we assume the user wants to delete a macro. |
| 452 |
In case these tokens are not followed by a macro name or the macro name has not been |
| 453 |
defined we simply go on. Otherwise, we delete the corresponding macro data from the |
| 454 |
global array <code>@Macros</code> that contains all the macro information. Macro expansion is |
| 455 |
more difficult and it will be described in detail in a separate document. At this point |
| 456 |
we would like to thank Joachim Schneider <joachim at hal dot rhein-necker dot de> |
| 457 |
for a suggestion on improving macro expansion. |
| 458 |
|
| 459 |
<pre><a name="NWCUvTi-2rq75n-1" href="#NWDCUvTi-A"><dfn><subroutine <tt>mpp</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 460 |
sub mpp { |
| 461 |
my $in_line; |
| 462 |
chomp($in_line = shift); |
| 463 |
my $LC = shift; |
| 464 |
my $out_line = $in_line; |
| 465 |
my $macro_name = ""; |
| 466 |
my @macro_param = (); |
| 467 |
my $macro_code = ""; |
| 468 |
if ($in_line =~ s/^%def\s*//) { |
| 469 |
if ($in_line =~ s/^(\w+)\s*//){ |
| 470 |
$macro_name = $1; |
| 471 |
} |
| 472 |
else { |
| 473 |
PrintErrorMessage("No macro name has been found",$LC); |
| 474 |
return "" |
| 475 |
} |
| 476 |
if ($in_line =~ s/^\(\s*//) { |
| 477 |
# do nothing |
| 478 |
} |
| 479 |
else { |
| 480 |
PrintErrorMessage("No left parenthesis after macro name has been found",$LC); |
| 481 |
return ""; |
| 482 |
} |
| 483 |
if ($in_line =~ s/^\)//) { |
| 484 |
# Macro has no parameters! |
| 485 |
} |
| 486 |
else { |
| 487 |
MACROS: while (1) { |
| 488 |
if ($in_line =~ s/^(\w+)\s*//) { |
| 489 |
push (@macro_param, $1); |
| 490 |
} |
| 491 |
else { |
| 492 |
PrintErrorMessage("No macro parameter name has been found",$LC); |
| 493 |
return ""; |
| 494 |
} |
| 495 |
if ($in_line =~ s/^,\s*//) { |
| 496 |
next MACROS; |
| 497 |
} |
| 498 |
else { |
| 499 |
last MACROS; |
| 500 |
} |
| 501 |
} |
| 502 |
if ($in_line =~ s/^\)//) { |
| 503 |
# do nothing! |
| 504 |
} |
| 505 |
else { |
| 506 |
PrintErrorMessage("No closing parenthesis after macro parameters",$LC); |
| 507 |
return ""; |
| 508 |
} |
| 509 |
} |
| 510 |
$in_line =~ s/([^%]+)(%.*)/$1/; |
| 511 |
$macro_code = $in_line; |
| 512 |
push ( @Macros , { 'macro_name' => $macro_name, |
| 513 |
'macro_code' => $macro_code, |
| 514 |
'macro_param' => \@macro_param }); |
| 515 |
return $out_line; |
| 516 |
} |
| 517 |
elsif ($in_line =~ s/^%undef\s*//) { |
| 518 |
if ($in_line =~ s/^(\w+)//) { |
| 519 |
my $undef_macro = $1; |
| 520 |
for(my $i = $#Macros; $i >= 0; $i--) { |
| 521 |
if ($Macros[$i]->{'macro_name'} eq $undef_macro) { |
| 522 |
splice(@Macros,$i,1); |
| 523 |
} |
| 524 |
} |
| 525 |
} |
| 526 |
return $out_line; |
| 527 |
} |
| 528 |
elsif ($in_line =~ s/^\s*%//) { |
| 529 |
return $out_line; |
| 530 |
} |
| 531 |
else { |
| 532 |
my $comment = $2 if $in_line =~ s/([^%]+)(%.+)/$1/; |
| 533 |
EXPANSIONLOOP: while () { |
| 534 |
my $org_in_line = $in_line; |
| 535 |
for(my $i = $#Macros; $i >= 0; $i--) { |
| 536 |
my $macro_name = $Macros[$i]->{'macro_name'}; |
| 537 |
if ($in_line =~ /&$macro_name\b/) { ############################ |
| 538 |
my $num_of_macro_args = @{$Macros[$i]->{'macro_param'}}; |
| 539 |
if ( $num_of_macro_args > 0 ) { |
| 540 |
# Macro with parameters |
| 541 |
my $pattern = "&$macro_name\\("; |
| 542 |
foreach my $p ( 1..$num_of_macro_args ) { |
| 543 |
my $comma = ($p == $num_of_macro_args) ? "\\s*" : "\\s*,\\s*"; |
| 544 |
$pattern .= "\\s*[^\\s\\)]+$comma"; |
| 545 |
} |
| 546 |
$pattern .= "\\)"; |
| 547 |
while($in_line =~ /&$macro_name\b/) { |
| 548 |
if ($in_line =~ /$pattern/) { |
| 549 |
my $before = $`; |
| 550 |
my $after = $'; |
| 551 |
my $match = $&; |
| 552 |
my $new_code = $Macros[$i]->{'macro_code'}; |
| 553 |
$match =~ s/^&$macro_name\(\s*//; |
| 554 |
$match =~ s/\)$//; |
| 555 |
foreach my $arg ( 0..($num_of_macro_args - 1) ) { |
| 556 |
my $old = $Macros[$i]->{'macro_param'}->[$arg]; |
| 557 |
my $comma = ($arg == ($num_of_macro_args - 1)) ? "" : ","; |
| 558 |
$match =~ s/^\s*([^\s,]+)\s*$comma//; |
| 559 |
my $new = $1; |
| 560 |
# 'g': Parameter may occur several times |
| 561 |
# in $new_code. |
| 562 |
# '\b': Substitute only whole words |
| 563 |
# not x in xA |
| 564 |
$new_code =~ s/\b$old\b/$new/g; |
| 565 |
} |
| 566 |
$in_line = "$before$new_code$after"; |
| 567 |
} |
| 568 |
else { |
| 569 |
PrintErrorMessage("Usage of macro &$macro_name does not " . |
| 570 |
"match its definition", $LC); |
| 571 |
return ""; |
| 572 |
} |
| 573 |
} |
| 574 |
} |
| 575 |
else { |
| 576 |
# Macro without parameters |
| 577 |
my $replacement = $Macros[$i]->{'macro_code'}; |
| 578 |
# '\b': Substitute only whole words |
| 579 |
# not x in xA |
| 580 |
$in_line =~ s/&$macro_name\b/$replacement/g; |
| 581 |
} |
| 582 |
} |
| 583 |
} |
| 584 |
last EXPANSIONLOOP if ( $org_in_line eq $in_line ); |
| 585 |
} |
| 586 |
return "$in_line$comment"; |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
</pre><p>Subroutine <tt>PrintErrorMessage</tt> has two parameters: the |
| 591 |
error message that will be printed on the screen, the log file and |
| 592 |
the output file, and the line number of the line containing the |
| 593 |
error was detected. |
| 594 |
The general form of the error message is the following: |
| 595 |
<pre> |
| 596 |
line X: paper{units( |
| 597 |
,mm)xrange(0,20)yrange(0,30)axes(B)ticks(10,10)} |
| 598 |
|
| 599 |
***Error: Error_Message |
| 600 |
</pre> |
| 601 |
where <code>X</code> denotes the line number and <code>Error_Message</code> is the |
| 602 |
actual error message. Note, that we print the tokens processed so far |
| 603 |
and on the text line the unprocessed tokens, so that the user knows |
| 604 |
<a name="NWDCUvTi-B">exactly where the error is. In the variable </a><code>$A</code> we store the processed |
| 605 |
tokens, while the variable <code>$l</code> holds the length of <code>$A</code> plus the |
| 606 |
length of the <code>$error_line</code> (that is the number of the input line where |
| 607 |
the error occurred) plus 7, i.e., 4 (the length of the word |
| 608 |
<code>line</code>) plus 2 (the two blank spaces) plus 1 (the symbol <code>:</code>). |
| 609 |
Finally, we increment the error counter (variable <code>$no_errors</code>). Note, that |
| 610 |
in case the user has specified the <code>-c</code> command line switch, we will not |
| 611 |
print any messages to the output file. |
| 612 |
|
| 613 |
<pre><a name="NWCUvTi-1m1522-1" href="#NWDCUvTi-B"><dfn><subroutine <tt>PrintErrorMessage</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 614 |
sub PrintErrorMessage { |
| 615 |
my $errormessage = shift; |
| 616 |
my $error_line = shift; |
| 617 |
my ($l,$A); |
| 618 |
$l = 1+length($command)-length; |
| 619 |
$A = substr($command,0,$l); |
| 620 |
$l += 7 +length($error_line); |
| 621 |
|
| 622 |
for my $fh (STDOUT, LOG) { |
| 623 |
print $fh "$curr_in_file", "Line $error_line: $A\n"; |
| 624 |
print $fh " " x $l ,$_,"***Error: $errormessage\n"; |
| 625 |
} |
| 626 |
if ($comments_on) { #print to output file file |
| 627 |
print OUT "%% *** $curr_in_file", "Line $error_line: $A\n"; |
| 628 |
print OUT "%% *** "," " x $l ,$_,"%% ... Error: $errormessage\n"; |
| 629 |
} |
| 630 |
$no_errors++; |
| 631 |
} |
| 632 |
|
| 633 |
</pre><p><a name="NWDCUvTi-C">Subroutine </a><tt>PrintWarningMessage</tt> behaves exactly like the subroutine |
| 634 |
<tt>PrintErrorMessage</tt>. The only difference is that the second |
| 635 |
subroutine prints only a warning message. A warning is issued when |
| 636 |
the system detects parameters that do nothing. |
| 637 |
|
| 638 |
<pre><a name="NWCUvTi-3Lpu7M-1" href="#NWDCUvTi-C"><dfn><subroutine <tt>PrintWarningMessage</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 639 |
sub PrintWarningMessage { |
| 640 |
my $warningMessage = shift; |
| 641 |
my $warning_line = shift; |
| 642 |
my ($l,$A); |
| 643 |
$l = 1+length($command)-length; |
| 644 |
$A = substr($command,0,$l); |
| 645 |
$l += 7 +length($warning_line); |
| 646 |
|
| 647 |
for my $fh (STDOUT, LOG) { |
| 648 |
print $fh "$curr_in_file", "Line $warning_line: $A\n"; |
| 649 |
print $fh " " x $l ,$_,"***Warning: $warningMessage\n"; |
| 650 |
} |
| 651 |
if ($comments_on) { #print to output file file |
| 652 |
print OUT "%% *** $curr_in_file", "Line $warning_line: $A\n"; |
| 653 |
print OUT "%% *** "," " x $l ,$_,"%% ... Warning: $warningMessage\n"; |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
</pre><p><a name="NWDCUvTi-D">The subroutine </a><tt>PrintFatalError</tt> behaves similarly to the subroutine |
| 658 |
<tt>PrintErrorMessage</tt>. It prints an error message to the |
| 659 |
screen and aborts execution. |
| 660 |
|
| 661 |
<pre><a name="NWCUvTi-4RPeBe-1" href="#NWDCUvTi-D"><dfn><subroutine <tt>PrintFatalError</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 662 |
sub PrintFatalError { |
| 663 |
my $FatalMessage = shift; |
| 664 |
my $fatal_line = shift; |
| 665 |
my ($l,$A); |
| 666 |
$l = 1+length($command)-length; |
| 667 |
$A = substr($command,0,$l); |
| 668 |
$l += 7 +length($fatal_line); |
| 669 |
|
| 670 |
die "$curr_in_file", "Line $fatal_line: $A\n" . |
| 671 |
(" " x $l) . $_ . "***Fatal Error: $FatalMessage\n"; |
| 672 |
} |
| 673 |
|
| 674 |
</pre><p><a name="NWDCUvTi-E">The subroutine </a><tt>chk_lparen</tt> accepts two arguments: the name |
| 675 |
of the token that should be immediately before the left parenthesis (variable |
| 676 |
<code>$token</code>), and the current line number (variable <code>$lc</code>). First we |
| 677 |
skip any leading white space and then check whether the next |
| 678 |
input character is a left parenthesis, then the subroutine skips any |
| 679 |
trailing white space; otherwise it prints an error message. |
| 680 |
|
| 681 |
<pre><a name="NWCUvTi-4Y5BUt-1" href="#NWDCUvTi-E"><dfn><subroutine <tt>chk_lparen</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 682 |
sub chk_lparen { |
| 683 |
my $token = $_[0]; |
| 684 |
my $lc = $_[1]; |
| 685 |
s/\s*//; |
| 686 |
if (/^[^\(]/) { |
| 687 |
PrintErrorMessage("Missing ( after $token",$lc); |
| 688 |
} |
| 689 |
else { |
| 690 |
s/^\(\s*//; |
| 691 |
} |
| 692 |
} |
| 693 |
|
| 694 |
</pre><p><a name="NWDCUvTi-F">The subroutine </a><tt>chk_rparen</tt> accepts two parameters: the name |
| 695 |
of the token that should be immediately after a right parenthesis (variable |
| 696 |
<code>$token</code>), and the current line number (variable <code>$lc</code>). Initially, we |
| 697 |
skip any leading white space and then we check whether the next input |
| 698 |
token is a right parenthesis. If it is not we issue a error message and |
| 699 |
return, otherwise we skip the parenthesis and any trailing white space. |
| 700 |
|
| 701 |
<pre><a name="NWCUvTi-3fTYkz-1" href="#NWDCUvTi-F"><dfn><subroutine <tt>chk_rparen</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 702 |
sub chk_rparen { |
| 703 |
my $token = $_[0]; |
| 704 |
my $lc = $_[1]; |
| 705 |
s/\s*//; |
| 706 |
if (s/^\)//) { |
| 707 |
s/\s*//; |
| 708 |
} |
| 709 |
else { |
| 710 |
PrintErrorMessage("Missing ) after $token",$lc); |
| 711 |
} |
| 712 |
} |
| 713 |
|
| 714 |
|
| 715 |
</pre><p><a name="NWDCUvTi-G">The subroutine </a><tt>chk_lcb</tt> behaves in a similar way to the subroutine |
| 716 |
<tt>chk_lparen</tt>. |
| 717 |
|
| 718 |
<pre><a name="NWCUvTi-2vMx6j-1" href="#NWDCUvTi-G"><dfn><subroutine <tt>chk_lcb</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 719 |
sub chk_lcb { |
| 720 |
my $token = $_[0]; |
| 721 |
my $lc = $_[1]; |
| 722 |
s/\s*//; |
| 723 |
if ($_ !~ /^\{/) { |
| 724 |
PrintErrorMessage("Missing { after $token",$lc); |
| 725 |
} |
| 726 |
else { |
| 727 |
s/^{\s*//; |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
</pre><p><a name="NWDCUvTi-H">Subroutine </a><tt>chk_rcb</tt> behaves in a similar way to the subroutine |
| 732 |
<tt>chk_rparen</tt>. |
| 733 |
|
| 734 |
<pre><a name="NWCUvTi-FE9Ax-1" href="#NWDCUvTi-H"><dfn><subroutine <tt>chk_rcb</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 735 |
sub chk_rcb { |
| 736 |
my $token = $_[0]; |
| 737 |
my $lc = $_[1]; |
| 738 |
if ($_ !~ /^\s*\}/) { |
| 739 |
PrintErrorMessage("Missing } after $token",$lc); |
| 740 |
} |
| 741 |
else { |
| 742 |
s/^\s*}\s*//; |
| 743 |
} |
| 744 |
} |
| 745 |
|
| 746 |
</pre><p><a name="NWDCUvTi-I">Subroutine </a><tt>chk_lsb</tt> behaves in a similar way to the subroutine |
| 747 |
<tt>chk_lparen</tt>. |
| 748 |
|
| 749 |
<pre><a name="NWCUvTi-3N30ZF-1" href="#NWDCUvTi-I"><dfn><subroutine <tt>chk_lsb</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 750 |
sub chk_lsb { |
| 751 |
my $token = $_[0]; |
| 752 |
my $lc = $_[1]; |
| 753 |
|
| 754 |
s/\s*//; |
| 755 |
if ($_ !~ /^\[/) { |
| 756 |
PrintErrorMessage("Missing [ after $token",$lc); |
| 757 |
} |
| 758 |
else { |
| 759 |
s/^\[\s*//; |
| 760 |
} |
| 761 |
} |
| 762 |
|
| 763 |
</pre><p><a name="NWDCUvTi-J">Subroutine </a><tt>chk_rsb</tt> behaves in a similar way to the subroutine |
| 764 |
<tt>chk_rparen</tt>. |
| 765 |
|
| 766 |
<pre><a name="NWCUvTi-ma6zf-1" href="#NWDCUvTi-J"><dfn><subroutine <tt>chk_rsb</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 767 |
sub chk_rsb { |
| 768 |
my $token = $_[0]; |
| 769 |
my $lc = $_[1]; |
| 770 |
|
| 771 |
s/\s*//; |
| 772 |
if ($_ !~ /^\]/) { |
| 773 |
PrintErrorMessage("Missing ] after $token",$lc); |
| 774 |
} |
| 775 |
else { |
| 776 |
s/^\]\s*//; |
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
</pre><p><a name="NWDCUvTi-K">The subroutine </a><code>chk_comma</code> checks whether the next token is a comma. |
| 781 |
If it is not then it prints an error message, otherwise it consumes the |
| 782 |
comma and any white space that follows the comma. |
| 783 |
|
| 784 |
<pre><a name="NWCUvTi-UyyUp-1" href="#NWDCUvTi-K"><dfn><subroutine <tt>chk_comma</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 785 |
sub chk_comma { |
| 786 |
my $lc = $_[0]; |
| 787 |
|
| 788 |
s/\s*//; |
| 789 |
if (/^[^,]/) { |
| 790 |
PrintErrorMessage("Did not find expected comma",$lc); |
| 791 |
} |
| 792 |
else { |
| 793 |
s/^,\s*//; |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
</pre><p><a name="NWDCUvTi-L">The subroutine </a><code>chk_comment</code> has only one parameter which is the current |
| 798 |
line number. It checks whether the next input character is a comment |
| 799 |
character and in this case it does nothing!. Otherwise, if there is some trailing text |
| 800 |
it simply prints a warning to the screen. |
| 801 |
|
| 802 |
<pre><a name="NWCUvTi-wLKY1-1" href="#NWDCUvTi-L"><dfn><subroutine <tt>chk_comment</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 803 |
sub chk_comment { |
| 804 |
my $lc = $_[0]; |
| 805 |
|
| 806 |
s/\s*//; |
| 807 |
if (/^%/) { |
| 808 |
# do nothing! |
| 809 |
} |
| 810 |
elsif (/^[^%]/) { |
| 811 |
PrintWarningMessage("Trailing text is ignored",$lc); |
| 812 |
} |
| 813 |
} |
| 814 |
|
| 815 |
</pre><p><a name="NWDCUvTi-M">The subroutine </a><code>print_headers</code> prints a header to the output file, as |
| 816 |
well as a header to the LOG file. |
| 817 |
The header contains information regarding the version of the |
| 818 |
program, a copyright notice, the command line, date and time information, |
| 819 |
and the names of the various files processed/generated. |
| 820 |
|
| 821 |
<pre><a name="NWCUvTi-3iVliS-1" href="#NWDCUvTi-M"><dfn><subroutine <tt>print_headers</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 822 |
sub print_headers |
| 823 |
{ |
| 824 |
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; |
| 825 |
$year+=1900; |
| 826 |
$mon+=1; |
| 827 |
$now_string = "$year/" . ($mon>9 ? "$mon/" : "0$mon/") . |
| 828 |
($mday>9 ? "$mday " : "0$mday ") . |
| 829 |
($hour>9 ? "$hour:" : "0$hour:") . |
| 830 |
($min>9 ? "$min:" : "0$min:") . |
| 831 |
($sec>9 ? "$sec" : "0$sec"); |
| 832 |
print OUT "%* -----------------------------------------------\n"; |
| 833 |
print OUT "%* mathspic (Perl version $version_number)\n"; |
| 834 |
print OUT "%* A filter program for use with PiCTeX\n"; |
| 835 |
print OUT "%* Copyright (c) 2005-2010 A Syropoulos & RWD Nickalls \n"; |
| 836 |
print OUT "%* Command line: $0 $commandLineArgs\n"; |
| 837 |
print OUT "%* Input filename : $source_file\n"; |
| 838 |
print OUT "%* Output filename: $out_file\n"; |
| 839 |
print OUT "%* Date & time: $now_string\n"; |
| 840 |
print OUT "%* -----------------------------------------------\n"; |
| 841 |
# |
| 842 |
print LOG "----\n"; |
| 843 |
print LOG "$now_string\n"; |
| 844 |
print LOG "mathspic (Perl version $version_number)\n"; |
| 845 |
print LOG "Copyright (c) 2005-2010 A Syropoulos & RWD Nickalls \n"; |
| 846 |
print LOG "Input file = $source_file\n"; |
| 847 |
print LOG "Output file = $out_file\n"; |
| 848 |
print LOG "Log file = $log_file\n"; |
| 849 |
print LOG "----\n"; |
| 850 |
} |
| 851 |
|
| 852 |
</pre><p><a name="NWDCUvTi-N">The subroutine </a><code>get_point</code> parses an individual point name. |
| 853 |
If the next token is also a point name then it returns the point name |
| 854 |
(but only if the only if |
| 855 |
the point name exists in the PointTable). In all other cases it returns |
| 856 |
the string <code>_undef_</code> to indicate that something is wrong. |
| 857 |
|
| 858 |
<pre><a name="NWCUvTi-1h5ef9-1" href="#NWDCUvTi-N"><dfn><subroutine <tt>get_point</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 859 |
sub get_point { |
| 860 |
|
| 861 |
my ($lc) = $_[0]; |
| 862 |
my ($PointName); |
| 863 |
|
| 864 |
if (s/^([^\W\d_]\d{0,4})\s*//i) { #point name |
| 865 |
$PointName = $1; |
| 866 |
if (!exists($PointTable{lc($PointName)})) { |
| 867 |
PrintErrorMessage("Undefined point $PointName",$lc); |
| 868 |
return "_undef_"; |
| 869 |
} |
| 870 |
else { |
| 871 |
return lc($PointName); |
| 872 |
} |
| 873 |
} |
| 874 |
else { |
| 875 |
PrintErrorMessage("Point name expected",$lc); |
| 876 |
return "_undef_"; |
| 877 |
} |
| 878 |
} |
| 879 |
|
| 880 |
</pre><p>The subroutine <code>perpendicular</code> has 6 parameters that correspond to the |
| 881 |
coordinates of some point P and to the coordinates of two points A and |
| 882 |
B that define a line. The subroutine returns |
| 883 |
a pair of numbers that correspond to the coordinates of a point that lies |
| 884 |
at the foot of the perpendicular to the line AB that passes through point P. |
| 885 |
The slope of line AB is m<sub>1</sub> and so its equation is |
| 886 |
y=m<sub>1</sub>x+c<sub>1</sub>. Similarly, the slope of the line PF is |
| 887 |
m<sub>2</sub>=-1/m<sub>1</sub> and its equation is |
| 888 |
y=m<sub>2</sub>x+c<sub>2</sub>. Since the line AB passes through A, then |
| 889 |
c<sub>1</sub>=y<sub>A</sub>-m<sub>1</sub>x<sub>A</sub>. Similarly, as P is |
| 890 |
on line PF, then c<sub>2</sub>=y<sub>P</sub>-m<sub>2</sub>x<sub>P</sub>. |
| 891 |
Now point F is on both lines, therefore |
| 892 |
<a name="NWDCUvTi-O">y</a><sub>F</sub>=m<sub>2</sub>x<sub>F</sub>+c<sub>2</sub> and |
| 893 |
y<sub>F</sub>=m<sub>1</sub>x<sub>F</sub>+c<sub>1</sub>. Solving these |
| 894 |
equations for x<sub>F</sub> and y<sub>F</sub> gives: |
| 895 |
<center> |
| 896 |
x<sub>F</sub>=(c<sub>2</sub>-c<sub>1</sub>)/(m<sub>1</sub>-m<sub>2</sub>)<br> |
| 897 |
y<sub>F</sub>=(m<sub>1</sub>c<sub>2</sub>-m<sub>2</sub>c<sub>1</sub>)/ |
| 898 |
(m<sub>1</sub>-m<sub>2</sub>) |
| 899 |
</center> |
| 900 |
|
| 901 |
<pre><a name="NWCUvTi-1GxwYt-1" href="#NWDCUvTi-O"><dfn><subroutine <tt>perpendicular</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 902 |
sub perpendicular { |
| 903 |
my ($xP, $yP, $xA, $yA, $xB, $yB) = @_; |
| 904 |
my ($xF, $yF, $deltax, $deltay, $m1, $m2, $c1, $c2, $factor); |
| 905 |
|
| 906 |
$deltax = $xA - $xB; |
| 907 |
return ($xA, $yP) if abs($deltax) < 0.0000001; |
| 908 |
$deltay = $yA - $yB; |
| 909 |
return ($xP, $yA) if abs($deltay) < 0.0000001; |
| 910 |
$m1 = $deltay / $deltax; |
| 911 |
eval { $m2 = (-1) / $m1;}; |
| 912 |
PrintFatalError("Division by zero",$lc) if $@; |
| 913 |
$c1 = $yA - $m1 * $xA; |
| 914 |
$c2 = $yP - $m2 * $xP; |
| 915 |
eval { $factor = 1 / ($m1 - $m2)}; |
| 916 |
PrintFatalError("Division by zero",$lc) if $@; |
| 917 |
return (($c2 - $c1) * $factor, ($m1 * $c2 - $m2 * $c1) * $factor); |
| 918 |
} |
| 919 |
|
| 920 |
</pre><p> <a name="NWDCUvTi-P">The subroutine </a><code>Length</code> computes the distance between two points A and B. |
| 921 |
Notice, that the name of the subroutine starts with a capital L, just |
| 922 |
to avoid conflict with the predefined Perl function. The subroutine |
| 923 |
requires four parameters which are the coordinates of the two points. |
| 924 |
|
| 925 |
<pre><a name="NWCUvTi-4XEuZg-1" href="#NWDCUvTi-P"><dfn><subroutine <tt>Length</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 926 |
sub Length { |
| 927 |
my ($xA, $yA, $xB, $yB)=@_; |
| 928 |
return sqrt(($xB - $xA)**2 + ($yB - $yA)**2); |
| 929 |
} |
| 930 |
|
| 931 |
</pre><p><a name="NWDCUvTi-Q">The subroutine </a><code>triangleArea</code> computes the area of a triangle by using |
| 932 |
Heron's formula, i.e., given a triangle ABC, we first compute |
| 933 |
s=(AB+BC+CA)/2 and then the area of the triangle is equal to the |
| 934 |
square root of s times (s-AB) times (s-BC) times (s-BA), where AB, BC, and CA |
| 935 |
are the lengths of the three sides of the triangle. The subroutine accepts 6 |
| 936 |
parameters, which correspond to the coordinates of three points that define |
| 937 |
the triangle. |
| 938 |
|
| 939 |
<pre><a name="NWCUvTi-4DwBs6-1" href="#NWDCUvTi-Q"><dfn><subroutine <tt>triangleArea</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 940 |
sub triangleArea { |
| 941 |
my ($xA, $yA, $xB, $yB, $xC, $yC)=@_; |
| 942 |
my ($lenAB, $lenBC, $lenCA, $s); |
| 943 |
|
| 944 |
$lenAB = Length($xA,$yA,$xB,$yB); |
| 945 |
$lenBC = Length($xB,$yB,$xC,$yC); |
| 946 |
$lenCA = Length($xC,$yC,$xA,$yA); |
| 947 |
$s = ($lenAB + $lenBC + $lenCA) / 2; |
| 948 |
return sqrt($s * ($s - $lenAB)*($s - $lenBC)*($s - $lenCA)); |
| 949 |
} |
| 950 |
|
| 951 |
</pre><p><a name="NWDCUvTi-R">The subroutine </a><code>poinOnLine</code> accepts five arguments: the coordinates of two |
| 952 |
points and the decimal number which corresponds to the distance from the |
| 953 |
first point towards the second one. The way we compute the coordinates of |
| 954 |
the point is fairly simple. |
| 955 |
|
| 956 |
<pre><a name="NWCUvTi-VFnEE-1" href="#NWDCUvTi-R"><dfn><subroutine <tt>pointOnLine</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 957 |
sub pointOnLine { |
| 958 |
my ($xA, $yA, $xB, $yB, $dist)=@_; |
| 959 |
my ($deltax, $deltay, $xPol, $yPol); |
| 960 |
|
| 961 |
$deltax = $xB - $xA; |
| 962 |
$deltay = $yB - $yA; |
| 963 |
$xPol = $xA + ($dist * $deltax / &Length($xA,$yA,$xB,$yB)); |
| 964 |
$yPol = $yA + ($dist * $deltay / &Length($xA,$yA,$xB,$yB)); |
| 965 |
return ($xPol, $yPol); |
| 966 |
} |
| 967 |
|
| 968 |
|
| 969 |
</pre><p>As we have mentioned above the subroutine <code>circumCircleCenter</code> takes six |
| 970 |
arguments that correspond to the coordinates of three points that |
| 971 |
define a triangle. The subroutine computes the coordinates of |
| 972 |
the center of a circle that passes through these three points, and the radius of |
| 973 |
the circle. We now describe how the subroutine computes the center |
| 974 |
of the circle and its radius. Let the triangle points be <code>t1</code>, <code>t2</code> |
| 975 |
and <code>t3</code>. We use the two pairs of points to define two sides, |
| 976 |
i.e., <code>t1t2</code> and <code>t2t3</code>. For each |
| 977 |
<a name="NWDCUvTi-S">side we locate the midpoints and get the their coordinates. We check</a> |
| 978 |
whether either of these two lines is either vertical or horizontal. If this |
| 979 |
is true, we know that one of the coordinates of the center of the circumcircle |
| 980 |
is the same as that of the midpoints of the horizontal or vertical line. |
| 981 |
Next, we determine the slopes of the lines <code>t1t2</code> and <code>t2t3</code>. |
| 982 |
We now determine the slope of lines at right-angles to these lines. We solve the |
| 983 |
resulting equations and obtain the center of the circumcircle. Now we get the |
| 984 |
radius, and then we are done. |
| 985 |
|
| 986 |
<pre><a name="NWCUvTi-lKNKf-1" href="#NWDCUvTi-S"><dfn><subroutine <tt>circumCircleCenter</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 987 |
|
| 988 |
sub circumCircleCenter { |
| 989 |
my ($xA, $yA, $xB, $yB, $xC, $yC, $lc)=@_; |
| 990 |
my ($deltay12, $deltax12, $xs12, $ys12); |
| 991 |
my ($deltay23, $deltax23, $xs23, $ys23); |
| 992 |
my ($xcc, $ycc); |
| 993 |
my ($m23, $mr23, $c23, $m12, $mr12, $c12); |
| 994 |
my ($sideA, $sideB, $sideC, $a, $radius); |
| 995 |
|
| 996 |
if (abs(triangleArea($xA, $yA, $xB, $yB, $xC, $yC)) < 0.0000001) |
| 997 |
{ |
| 998 |
PrintErrorMessage("Area of triangle is zero!",$lc); |
| 999 |
return (0,0,0); |
| 1000 |
} |
| 1001 |
$deltay12 = $yB - $yA; |
| 1002 |
$deltax12 = $xB - $xA; |
| 1003 |
$xs12 = $xA + $deltax12 / 2; |
| 1004 |
$ys12 = $yA + $deltay12 / 2; |
| 1005 |
# |
| 1006 |
$deltay23 = $yC - $yB; |
| 1007 |
$deltax23 = $xC - $xB; |
| 1008 |
$xs23 = $xB + $deltax23 / 2; |
| 1009 |
$ys23 = $yB + $deltay23 / 2; |
| 1010 |
# |
| 1011 |
CCXYLINE:{ |
| 1012 |
if (abs($deltay12) < 0.0000001) |
| 1013 |
{ |
| 1014 |
$xcc = $xs12; |
| 1015 |
if (abs($deltax23) < 0.0000001) |
| 1016 |
{ |
| 1017 |
$ycc = $ys23; |
| 1018 |
last CCXYLINE; |
| 1019 |
} |
| 1020 |
else |
| 1021 |
{ |
| 1022 |
$m23 = $deltay23 / $deltax23; |
| 1023 |
$mr23 = -1 / $m23; |
| 1024 |
$c23 = $ys23 - $mr23 * $xs23; |
| 1025 |
$ycc = $mr23 * $xs12 + $c23; |
| 1026 |
last CCXYLINE; |
| 1027 |
} |
| 1028 |
} |
| 1029 |
if (abs($deltax12) < 0.0000001) |
| 1030 |
{ |
| 1031 |
$ycc = $ys12; |
| 1032 |
if (abs($deltay23) < 0.0000001) |
| 1033 |
{ |
| 1034 |
$xcc = $xs23; |
| 1035 |
last CCXYLINE; |
| 1036 |
} |
| 1037 |
else |
| 1038 |
{ |
| 1039 |
$m23 = $deltay23 / $deltax23; |
| 1040 |
$mr23 = -1 / $m23; |
| 1041 |
$c23 = $ys23 - $mr23 * $xs23; |
| 1042 |
$xcc = ($ys12 - $c23) / $mr23; |
| 1043 |
last CCXYLINE; |
| 1044 |
} |
| 1045 |
} |
| 1046 |
if (abs($deltay23) < 0.0000001) |
| 1047 |
{ |
| 1048 |
$xcc = $xs23; |
| 1049 |
if (abs($deltax12) < 0.0000001) |
| 1050 |
{ |
| 1051 |
$ycc = $ys12; |
| 1052 |
last CCXYLINE; |
| 1053 |
} |
| 1054 |
else |
| 1055 |
{ |
| 1056 |
$m12 = $deltay12 / $deltax12; |
| 1057 |
$mr12 = -1 / $m12; |
| 1058 |
$c12 = $ys12 - $mr12 * $xs12; |
| 1059 |
$ycc = $mr12 * $xcc + $c12; |
| 1060 |
last CCXYLINE; |
| 1061 |
} |
| 1062 |
} |
| 1063 |
if (abs($deltax23) < 0.0000001) |
| 1064 |
{ |
| 1065 |
$ycc = $ys23; |
| 1066 |
if (abs($deltay12) < 0.0000001) |
| 1067 |
{ |
| 1068 |
$xcc = $xs12; |
| 1069 |
last CCXYLINE; |
| 1070 |
} |
| 1071 |
else |
| 1072 |
{ |
| 1073 |
$m12 = $deltay12 / $deltax12; |
| 1074 |
$mr12 = -1 / $m12; |
| 1075 |
$c12 = $ys12 - $mr12 * $xs12; |
| 1076 |
$xcc = ($ycc - $c12) / $mr12; |
| 1077 |
last CCXYLINE; |
| 1078 |
} |
| 1079 |
} |
| 1080 |
$m12 = $deltay12 / $deltax12; |
| 1081 |
$mr12 = -1 / $m12; |
| 1082 |
$c12 = $ys12 - $mr12 * $xs12; |
| 1083 |
#----- |
| 1084 |
$m23 = $deltay23 / $deltax23; |
| 1085 |
$mr23 = -1 / $m23; |
| 1086 |
$c23 = $ys23 - $mr23 * $xs23; |
| 1087 |
$xcc = ($c23 - $c12) / ($mr12 - $mr23); |
| 1088 |
$ycc = ($c23 * $mr12 - $c12 * $mr23) / ($mr12 - $mr23); |
| 1089 |
} |
| 1090 |
# |
| 1091 |
$sideA = &Length($xA,$yA,$xB,$yB); |
| 1092 |
$sideB = &Length($xB,$yB,$xC,$yC); |
| 1093 |
$sideC = &Length($xC,$yC,$xA,$yA); |
| 1094 |
$a = triangleArea($xA, $yA, $xB, $yB, $xC, $yC); |
| 1095 |
$radius = ($sideA * $sideB * $sideC) / (4 * $a); |
| 1096 |
# |
| 1097 |
return ($xcc, $ycc, $radius); |
| 1098 |
} |
| 1099 |
|
| 1100 |
</pre><p>The subroutine <code>ComputeDist</code> is used to compute a distance that is |
| 1101 |
specified by either a float number, a pair of points, or a variable |
| 1102 |
name. In case we have a pair of identifiers, we check whether the first |
| 1103 |
one is a point. If it isn't a point we assume we have a variable followed |
| 1104 |
by a keyword. Otherwise, i.e., if it is a point name, we check whether |
| 1105 |
the second identifier is also a point name. If it is, we simply return |
| 1106 |
the distance between them, otherwise we issue an error message. |
| 1107 |
<a name="NWDCUvTi-T">If we have only a single identifier, we check whether it is a</a> |
| 1108 |
variable that has already been defined, and if so we return its value. |
| 1109 |
Since, this |
| 1110 |
subroutine is heavily used, it actually returns a pair of numbers: |
| 1111 |
the first one being the computed distance and the second one being an |
| 1112 |
error indicator. If the value of this indicator is 0, then there is no |
| 1113 |
error. If its value is 1, then there is an error. Moreover, in case there |
| 1114 |
is an error the distance is assumed to be equal to zero. |
| 1115 |
|
| 1116 |
<pre><a name="NWCUvTi-3GSnCT-1" href="#NWDCUvTi-T"><dfn><subroutine <tt>ComputeDist</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1117 |
sub ComputeDist { |
| 1118 |
my ($lc) = $_[0]; |
| 1119 |
my ($v1, $v2); |
| 1120 |
|
| 1121 |
if (s/^((\+|-)?\d+(\.\d+)?([eE](\+|-)?\d+)?)//) #is it a number? |
| 1122 |
{ |
| 1123 |
return ($1, 1); |
| 1124 |
} |
| 1125 |
elsif (/^[^\W\d_]\d{0,4}[^\W\d_]\d{0,4}/) #it is a pair of IDs? |
| 1126 |
{ |
| 1127 |
s/^([^\W\d_]\d{0,4})//i; |
| 1128 |
$v1 = $1; |
| 1129 |
if (!exists($PointTable{lc($v1)})) { |
| 1130 |
if (exists($VarTable{lc($v1)})) { |
| 1131 |
return ($VarTable{lc($v1)}, 1); |
| 1132 |
} |
| 1133 |
PrintErrorMessage("Point $v1 has not been defined", $lc); |
| 1134 |
s/^\s*[^\W\d_]\d{0,4}//i; |
| 1135 |
return (0,0); |
| 1136 |
} |
| 1137 |
$v1 = lc($v1); |
| 1138 |
s/^\s*([^\W\d_]\d{0,4})//i; |
| 1139 |
$v2 = $1; |
| 1140 |
if (!exists($PointTable{lc($v2)})) |
| 1141 |
{ |
| 1142 |
PrintErrorMessage("Point $v2 has not been defined", $lc); |
| 1143 |
return (0,0); |
| 1144 |
} |
| 1145 |
$v2 = lc($v2); |
| 1146 |
my ($x1,$y1,$pSV1,$pS1) = unpack("d3A*",$PointTable{$v1}); |
| 1147 |
my ($x2,$y2,$pSV2,$pS2) = unpack("d3A*",$PointTable{$v2}); |
| 1148 |
return (Length($x1,$y1,$x2,$y2), 1); |
| 1149 |
} |
| 1150 |
elsif (s/^([^\W\d_]\d{0,4})//i) # it is a single id |
| 1151 |
{ |
| 1152 |
$v1 = $1; |
| 1153 |
if (!exists($VarTable{lc($v1)})) #it isn't a variable |
| 1154 |
{ |
| 1155 |
PrintErrorMessage("Variable $v1 has not been defined", $lc); |
| 1156 |
return (0,0); |
| 1157 |
} |
| 1158 |
return ($VarTable{lc($v1)}, 1); |
| 1159 |
} |
| 1160 |
else |
| 1161 |
{ |
| 1162 |
PrintErrorMessage("Unexpected token", $lc); |
| 1163 |
return (0,0); |
| 1164 |
} |
| 1165 |
} |
| 1166 |
|
| 1167 |
</pre><p><a name="NWDCUvTi-U">The subroutine </a><code>intersection4points</code> has 8 parameters that correspond to the |
| 1168 |
coordinates of four points that uniquely determine two lines, and computes the |
| 1169 |
the point of intersection of these two lines. |
| 1170 |
|
| 1171 |
<pre><a name="NWCUvTi-106ivL-1" href="#NWDCUvTi-U"><dfn><subroutine <tt>intersection4points</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1172 |
sub intersection4points { |
| 1173 |
my ($x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4) = @_; |
| 1174 |
my ($deltay12, $deltax12, $deltay34, $deltax34); |
| 1175 |
my ($xcc, $ycc, $m34, $c34, $m12, $c12); |
| 1176 |
|
| 1177 |
$deltay12 = $y2 - $y1; |
| 1178 |
$deltax12 = $x2 - $x1; |
| 1179 |
# |
| 1180 |
$deltay34 = $y4 - $y3; |
| 1181 |
$deltax34 = $x4 - $x3; |
| 1182 |
I4PXYLINE:{ |
| 1183 |
if (abs($deltay12) < 0.0000001) |
| 1184 |
{ |
| 1185 |
$ycc = $y1; |
| 1186 |
if (abs($deltax34) < 0.0000001) |
| 1187 |
{ |
| 1188 |
$xcc = $x3; |
| 1189 |
last I4PXYLINE; |
| 1190 |
} |
| 1191 |
else |
| 1192 |
{ |
| 1193 |
$m34 = $deltay34 / $deltax34; |
| 1194 |
$c34 = $y3 - $m34 * $x3; |
| 1195 |
$xcc = ($ycc - $c34) / $m34; |
| 1196 |
last I4PXYLINE; |
| 1197 |
} |
| 1198 |
} |
| 1199 |
if (abs($deltax12) < 0.0000001) |
| 1200 |
{ |
| 1201 |
$xcc = $x1; |
| 1202 |
if (abs($deltay34) < 0.0000001) |
| 1203 |
{ |
| 1204 |
$ycc = $y3; |
| 1205 |
last I4PXYLINE; |
| 1206 |
} |
| 1207 |
else |
| 1208 |
{ |
| 1209 |
$m34 = $deltay34 / $deltax34; |
| 1210 |
$c34 = $y3 - $m34 * $x3; |
| 1211 |
$ycc = $m34 * $xcc + $c34; |
| 1212 |
last I4PXYLINE; |
| 1213 |
} |
| 1214 |
} |
| 1215 |
if (abs($deltay34) < 0.0000001) |
| 1216 |
{ |
| 1217 |
$ycc = $y3; |
| 1218 |
if (abs($deltax12) < 0.0000001) |
| 1219 |
{ |
| 1220 |
$xcc = $x1; |
| 1221 |
last I4PXYLINE; |
| 1222 |
} |
| 1223 |
else |
| 1224 |
{ |
| 1225 |
$m12 = $deltay12 / $deltax12; |
| 1226 |
$c12 = $y1 - $m12 * $x1; |
| 1227 |
$xcc = ($ycc - $c12) / $m12; |
| 1228 |
last I4PXYLINE; |
| 1229 |
} |
| 1230 |
} |
| 1231 |
if (abs($deltax34) < 0.0000001) |
| 1232 |
{ |
| 1233 |
$xcc = $x3; |
| 1234 |
if (abs($deltay12) < 0.0000001) |
| 1235 |
{ |
| 1236 |
$ycc = $y1; |
| 1237 |
last I4PXYLINE; |
| 1238 |
} |
| 1239 |
else |
| 1240 |
{ |
| 1241 |
$m12 = $deltay12 / $deltax12; |
| 1242 |
$c12 = $y1 - $m12 * $x1; |
| 1243 |
$ycc = $m12 * $xcc + $c12; |
| 1244 |
last I4PXYLINE; |
| 1245 |
} |
| 1246 |
} |
| 1247 |
$m12 = $deltay12 / $deltax12; |
| 1248 |
$c12 = $y1 - $m12 * $x1; |
| 1249 |
$m34 = $deltay34 / $deltax34; |
| 1250 |
$c34 = $y3 - $m34 * $x3; |
| 1251 |
$xcc = ($c34 - $c12) / ($m12 - $m34); |
| 1252 |
$ycc = ($c34 * $m12 - $c12 * $m34) / ($m12 - $m34); |
| 1253 |
} |
| 1254 |
return ($xcc, $ycc); |
| 1255 |
} |
| 1256 |
|
| 1257 |
</pre><p>The subroutine <code>IncircleCenter</code> computes the center and the |
| 1258 |
radius of the circle that is inside a triangle and touches the sides of |
| 1259 |
the triangle. The subroutine has six arguments that correspond to the |
| 1260 |
coordinates of three points that uniquely determine the triangle. Here are |
| 1261 |
the details: |
| 1262 |
<ul> |
| 1263 |
<li> Let the triangle points be A, B, C and sides a, b, c, where side B |
| 1264 |
is opposite angle B, etc. </li> |
| 1265 |
<li> Use angles A and B only.</li> |
| 1266 |
<li> Let the bisector of angle A meet side a in point A1, and let the |
| 1267 |
distance of A1 from B be designated BA1</li> |
| 1268 |
<li> Using the sine rule, one gets: BA1/c = a/(b+c), that is |
| 1269 |
BA1 = c * a/(b+c).</li> |
| 1270 |
<li> Now do the same for side b, and determine equivalent point B1. |
| 1271 |
<a name="NWDCUvTi-V">CB1/a = b/(b+c), that is CB1 = a * b/(b+c).</a></li> |
| 1272 |
<li> We can now find the intersection of the line from point A to point A1, |
| 1273 |
and the line from point B to point B1. We have four points, so we use the |
| 1274 |
mathspic internal <code>intersection4points</code> subroutine to return the |
| 1275 |
coordinates of the intersection X<sub>i</sub>, Y<sub>i</sub>.</li> |
| 1276 |
<li> Now get the radius: R=(area of triangle)/(a+b+c)/2</li> |
| 1277 |
<li>Finally, return the radius and the coordinates of the center. |
| 1278 |
</ul> |
| 1279 |
|
| 1280 |
<pre><a name="NWCUvTi-Kxdzt-1" href="#NWDCUvTi-V"><dfn><subroutine <tt>IncircleCenter</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1281 |
sub IncircleCenter { |
| 1282 |
my ($Ax, $Ay, $Bx, $By, $Cx, $Cy) = @_; |
| 1283 |
my ($sideA, $sideB, $sideC); |
| 1284 |
my ($ba1, $xA1, $yA1, $cb1, $ac1, $xB1, $yB1, $xC1, $yC1, $a, $s, $r); |
| 1285 |
|
| 1286 |
#determine the lengths of the sides |
| 1287 |
$sideA = Length($Bx, $By, $Cx, $Cy); |
| 1288 |
$sideB = Length($Cx, $Cy, $Ax, $Ay); |
| 1289 |
$sideC = Length($Ax, $Ay, $Bx, $By); |
| 1290 |
# |
| 1291 |
$ba1 = ($sideC * $sideA) / ($sideB + $sideC); |
| 1292 |
($xA1, $yA1) = pointOnLine($Bx, $By, $Cx, $Cy, $ba1); |
| 1293 |
$cb1 = ($sideA * $sideB) / ($sideC + $sideA); |
| 1294 |
($xB1, $yB1) = pointOnLine($Cx, $Cy, $Ax, $Ay, $cb1); |
| 1295 |
$ac1 = ($sideB * $sideC) / ($sideA + $sideB); |
| 1296 |
($xC1, $yC1) = pointOnLine($Ax, $Ay, $Bx, $By, $ac1); |
| 1297 |
($xcenter, $ycenter) = &intersection4points($Ax, $Ay, $xA1, $yA1, |
| 1298 |
$Bx, $By, $xB1, $yB1); |
| 1299 |
# get radius |
| 1300 |
$a = &triangleArea($Ax, $Ay, $Bx, $By, $Cx, $Cy); |
| 1301 |
$s = ($sideA + $sideB +$sideC) / 2; |
| 1302 |
$r = $a / $s; |
| 1303 |
return ($xcenter, $ycenter, $r); |
| 1304 |
} |
| 1305 |
|
| 1306 |
</pre><p><a name="NWDCUvTi-W">The subroutine </a><code>Angle</code> takes six arguments which correspond to the |
| 1307 |
coordinates of three points that define an angle. The subroutine computes |
| 1308 |
the opening of the angle in degrees. In case there is an error it returns |
| 1309 |
the number -500. ****EXPLAIN THE ALGORITHM**** |
| 1310 |
|
| 1311 |
<pre><a name="NWCUvTi-3xteda-1" href="#NWDCUvTi-W"><dfn><subroutine <tt>Angle</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1312 |
sub Angle { |
| 1313 |
my ($Ax, $Ay, $Bx, $By, $Cx, $Cy) = @_; |
| 1314 |
my ($RAx, $RAy, $RBx, $RBy, $RCx, $RCy, $deltax, $deltay); |
| 1315 |
my ($lineBA, $lineBC, $lineAC, $k, $kk, $angle); |
| 1316 |
my ($T, $cosT, $sinT) = (0.3, cos(0.3), sin(0.3)); |
| 1317 |
|
| 1318 |
$RAx = $Ax * $cosT + $Ay * $sinT; |
| 1319 |
$RAy = -$Ax * $sinT + $Ay * $cosT; |
| 1320 |
$RBx = $Bx * $cosT + $By * $sinT; |
| 1321 |
$RBy = -$Bx * $sinT + $By * $cosT; |
| 1322 |
$RCx = $Cx * $cosT + $Cy * $sinT; |
| 1323 |
$RCy = -$Cx * $sinT + $Cy * $cosT; |
| 1324 |
$deltax = $RBx - $RAx; |
| 1325 |
$deltay = $RBy - $RAy; |
| 1326 |
$lineBA = sqrt($deltax*$deltax + $deltay*$deltay); |
| 1327 |
if ($lineBA < 0.0000001) |
| 1328 |
{ |
| 1329 |
return -500; |
| 1330 |
} |
| 1331 |
$deltax = $RBx - $RCx; |
| 1332 |
$deltay = $RBy - $RCy; |
| 1333 |
$lineBC = sqrt($deltax*$deltax + $deltay*$deltay); |
| 1334 |
if ($lineBC < 0.0000001) |
| 1335 |
{ |
| 1336 |
return -500; |
| 1337 |
} |
| 1338 |
$deltax = $RAx - $RCx; |
| 1339 |
$deltay = $RAy - $RCy; |
| 1340 |
$lineAC = sqrt($deltax*$deltax + $deltay*$deltay); |
| 1341 |
if ($lineAC < 0.0000001) |
| 1342 |
{ |
| 1343 |
return -500; |
| 1344 |
} |
| 1345 |
$k = ($lineBA*$lineBA + $lineBC*$lineBC - $lineAC*$lineAC ) / |
| 1346 |
(2 * $lineBA * $lineBC); |
| 1347 |
$k = -1 if $k < -0.99999; |
| 1348 |
$k = 1 if $k > 0.99999; |
| 1349 |
$kk = $k * $k; |
| 1350 |
if (($kk * $kk) == 1) |
| 1351 |
{ |
| 1352 |
$angle = PI if $k == -1; |
| 1353 |
$angle = 0 if $k == 1; |
| 1354 |
} |
| 1355 |
else |
| 1356 |
{ |
| 1357 |
$angle = (PI / 2) - atan2($k / sqrt(1 - $kk),1); |
| 1358 |
} |
| 1359 |
return $angle * 180 / PI; |
| 1360 |
} |
| 1361 |
|
| 1362 |
</pre><p>The subroutine <code>excircle</code> computes the center and the radius of a circle that |
| 1363 |
externally touches a given side (4th and 5th arguments) of triangle (determined |
| 1364 |
by the 1rst, the 2nd and 3rd argument). Here are the details: |
| 1365 |
<ul> |
| 1366 |
<li> Let the triangle points be A, B, C, and the given side be BC.</li> |
| 1367 |
<li> Now calculate the radius of Excircle = (triangle area)/(s - side length), |
| 1368 |
where s = (a+b+c)/2</li> |
| 1369 |
<li><a name="NWDCUvTi-X">Calculate the distance from the angle (A) (opposite the given side BC)</a> |
| 1370 |
to the excircle center = radius/sin(A/2)</li> |
| 1371 |
<li> Now determine the the Excircle center by locating it on the angle bisector |
| 1372 |
(i.e., same line that the IncircleCenter is on), but at distance d further |
| 1373 |
away from angle A. So, we now have the Incircle center (I), |
| 1374 |
determine deltaX and deltaY from I to A, calculate the distance AI, |
| 1375 |
and then extend the line from I by distance d to Excenter Xc, Yc.</li> |
| 1376 |
</ul> |
| 1377 |
|
| 1378 |
<pre><a name="NWCUvTi-cchrT-1" href="#NWDCUvTi-X"><dfn><subroutine <tt>excircle</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1379 |
sub excircle { |
| 1380 |
my ($A, $B, $C, $D, $E) = @_; |
| 1381 |
my ($Ax,$Ay,$Bx,$By,$Dx,$Dy,$Ex,$Ey,$ASVA,$ASA); |
| 1382 |
($Ax,$Ay,$ASVA,$ASA)=unpack("d3A*",$PointTable{$A}); |
| 1383 |
($Bx,$By,$ASVA,$ASA)=unpack("d3A*",$PointTable{$B}); |
| 1384 |
($Cx,$Cy,$ASVA,$ASA)=unpack("d3A*",$PointTable{$C}); |
| 1385 |
($Dx,$Dy,$ASVA,$ASA)=unpack("d3A*",$PointTable{$D}); |
| 1386 |
($Ex,$Ey,$ASVA,$ASA)=unpack("d3A*",$PointTable{$E}); |
| 1387 |
my ($sideA, $sideB, $sideC, $s, $R, $theAdeg, $d); |
| 1388 |
my ($Xmypoint, $Ymypoint, $deltax, $deltay, $mylength, $xc, $yc); |
| 1389 |
|
| 1390 |
$sideA = &Length($Bx, $By, $Cx, $Cy); |
| 1391 |
$sideB = &Length($Cx, $Cy, $Ax, $Ay); |
| 1392 |
$sideC = &Length($Ax, $Ay, $Bx, $By); |
| 1393 |
$s = ($sideA + $sideB + $sideC) / 2; |
| 1394 |
$R = triangleArea($Ax, $Ay, $Bx, $By, $Cx, $Cy) / |
| 1395 |
($s - &Length($Dx, $Dy, $Ex, $Ey)); |
| 1396 |
if (($D eq $A && $E eq $B) || ($D eq $B && $E eq $A)) |
| 1397 |
{ |
| 1398 |
$theAdeg = &Angle($Bx, $By, $Cx, $Cy, $Ax, $Ay); |
| 1399 |
$Xmypoint = $Cx; |
| 1400 |
$Ymypoint = $Cy; |
| 1401 |
} |
| 1402 |
elsif (($D eq $B && $E eq $C) || ($D eq $C && $E eq $B)) |
| 1403 |
{ |
| 1404 |
$theAdeg = &Angle($Cx, $Cy, $Ax, $Ay, $Bx, $By); |
| 1405 |
$Xmypoint = $Ax; |
| 1406 |
$Ymypoint = $Ay; |
| 1407 |
} |
| 1408 |
elsif (($D eq $C && $E eq $A) || ($D eq $A && $E eq $C)) |
| 1409 |
{ |
| 1410 |
$theAdeg = &Angle($Ax, $Ay, $Bx, $By, $Cx, $Cy); |
| 1411 |
$Xmypoint = $Bx; |
| 1412 |
$Ymypoint = $By; |
| 1413 |
} |
| 1414 |
else |
| 1415 |
{ |
| 1416 |
return (0,0,0); |
| 1417 |
} |
| 1418 |
$d = $R / sin($theAdeg * PI / 180 / 2); |
| 1419 |
my ($xIn, $yIn, $rin) = &IncircleCenter($Ax, $Ay, $Bx, $By, $Cx, $Cy); |
| 1420 |
$deltax = $xIn - $Xmypoint; |
| 1421 |
$deltay = $yIn - $Ymypoint; |
| 1422 |
$mylength = sqrt($deltax*$deltax + $deltay*$deltay); |
| 1423 |
$xc = $Xmypoint + $d * $deltax / $mylength; |
| 1424 |
$yc = $Ymypoint + $d * $deltay / $mylength; |
| 1425 |
return ($xc, $yc, $R); |
| 1426 |
} |
| 1427 |
|
| 1428 |
</pre><p>The <code>DrawLineOrArrow</code> subroutine is used to parse the arguments of the commands |
| 1429 |
<code>drawline</code>, <code>drawthickline</code>, <code>drawarrow</code>, <code>drawthickarrow</code> and |
| 1430 |
<code>drawCurve</code>. In general, these commands have as arguments a list of points separated by |
| 1431 |
commas that are used to draw a set of lines. The list of points is |
| 1432 |
enclosed in parentheses. Here we give only the syntax of the <code>drawline</code> |
| 1433 |
comma, as the syntax of the other commands is identical: |
| 1434 |
<pre> |
| 1435 |
drawline ::= "drawline" "(" Points { "," Points } ")" |
| 1436 |
Points ::= Point { separator Point} |
| 1437 |
separator ::= blank | empty |
| 1438 |
</pre> |
| 1439 |
<a name="NWDCUvTi-Y">In the following code we</a> |
| 1440 |
scan a list of points (possibly separated by blanks) and we stop when |
| 1441 |
we encounter either a comma or some other character. In case we have found |
| 1442 |
a comma, we check whether we have a <code>drawline</code> command and if this is |
| 1443 |
the case we plot the list of points. We continue with the next list of points, |
| 1444 |
until there are no more points. The inner while-loop is used to control the |
| 1445 |
consumption of point tokens and the external to reset the array <code>PP</code> which |
| 1446 |
holds the point names. |
| 1447 |
|
| 1448 |
<pre><a name="NWCUvTi-cviH2-1" href="#NWDCUvTi-Y"><dfn><subroutine <tt>DrawLineOrArrow</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1449 |
sub DrawLineOrArrow { |
| 1450 |
my $draw_Line = shift; |
| 1451 |
my $lc = shift; |
| 1452 |
my $lineLength = -1; |
| 1453 |
my $stacklen = 0; |
| 1454 |
my @PP = (); |
| 1455 |
# if ($draw_Line != 2) { |
| 1456 |
# s/\s*//; |
| 1457 |
# if (s/^\[\s*//) { # optional length specifier |
| 1458 |
# $lineLength = expr($lc); |
| 1459 |
# if ($lineLength <= 0) { |
| 1460 |
# PrintErrorMessage("length must greater than zero",$lc); |
| 1461 |
# $lineLength = -1; |
| 1462 |
# } |
| 1463 |
# chk_rsb("optional part",$lc); |
| 1464 |
# } |
| 1465 |
# } |
| 1466 |
chk_lparen("$cmd",$lc); |
| 1467 |
DRAWLINES:while(1) { |
| 1468 |
@PP = () ; |
| 1469 |
while(1) { |
| 1470 |
if (s/^([^\W\d_]\d{0,4})\s*//i) { #point name |
| 1471 |
$P = $1; |
| 1472 |
if (!exists($PointTable{lc($P)})) { |
| 1473 |
PrintErrorMessage("Undefined point $P",$lc); |
| 1474 |
} |
| 1475 |
else { |
| 1476 |
push (@PP,$P); |
| 1477 |
} |
| 1478 |
} |
| 1479 |
else { |
| 1480 |
$stacklen = @PP; |
| 1481 |
if ($draw_Line != 2) { |
| 1482 |
if ($stacklen <= 1) { |
| 1483 |
PrintErrorMessage("Wrong number of points",$lc); |
| 1484 |
} |
| 1485 |
else { |
| 1486 |
push(@PP,$lc); |
| 1487 |
if ($draw_Line == 0) { |
| 1488 |
drawarrows(@PP); |
| 1489 |
} |
| 1490 |
elsif ($draw_Line == 1) { |
| 1491 |
drawlines(@PP); |
| 1492 |
} |
| 1493 |
} |
| 1494 |
} |
| 1495 |
if (s/^,\s*// and $draw_Line != 2) { |
| 1496 |
next DRAWLINES; |
| 1497 |
} |
| 1498 |
else { |
| 1499 |
last DRAWLINES; |
| 1500 |
} |
| 1501 |
} |
| 1502 |
} |
| 1503 |
} |
| 1504 |
if ($draw_Line == 2) { |
| 1505 |
$stacklen = @PP; |
| 1506 |
if ($stacklen < 2) { |
| 1507 |
PrintErrorMessage("Wrong number of points",$lc); |
| 1508 |
} |
| 1509 |
elsif ($stacklen % 2 == 0) { |
| 1510 |
PrintErrorMessage("Number of points must be odd",$lc); |
| 1511 |
} |
| 1512 |
else { |
| 1513 |
drawCurve(@PP); |
| 1514 |
} |
| 1515 |
} |
| 1516 |
chk_rparen("arguments of $cmd",$lc); |
| 1517 |
chk_comment($lc); |
| 1518 |
} |
| 1519 |
|
| 1520 |
</pre><p>The subroutine <code>drawarrows</code> is used to draw one or more lines. The subroutine |
| 1521 |
accepts as argument an array which contains the names of the points which |
| 1522 |
<a name="NWDCUvTi-Z">define the lines, plus the current program line number. Each arrow is printed</a> |
| 1523 |
using the following code: |
| 1524 |
<center> |
| 1525 |
<tt>\arrow < </tt>ArrowLength <tt> mm> [</tt> beta <tt>,</tt> gamma <tt>] from |
| 1526 |
x1 y1 to x2 y2 </tt> |
| 1527 |
</center> |
| 1528 |
where beta is equal to tan(<code>$arrowAngleB</code> * <code>d2r</code> /2) and gamma is equal to |
| 1529 |
2*tan(<code>$arrowAngleC</code> * <code>d2r</code> / 2). |
| 1530 |
|
| 1531 |
<pre><a name="NWCUvTi-4STZZz-1" href="#NWDCUvTi-Z"><dfn><subroutine <tt>drawarrows</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1532 |
sub drawarrows { |
| 1533 |
my ($NoArgs); |
| 1534 |
$NoArgs = @_; |
| 1535 |
my ($lc) = $_[$NoArgs-1]; #line number is the last argument |
| 1536 |
my ($NumberOfPoints, $p, $q, $r12, $d12); |
| 1537 |
my ($px,$py,$pSV,$pS, $qx,$qy,$qSV,$qS); |
| 1538 |
|
| 1539 |
$NumberOfPoints = $NoArgs - 1; |
| 1540 |
LOOP: for(my $i=0; $i < $NumberOfPoints - 1; $i++) |
| 1541 |
{ |
| 1542 |
$p = $_[$i]; |
| 1543 |
$q = $_[$i+1]; |
| 1544 |
($px,$py,$pSV,$pS) = unpack("d3A*",$PointTable{lc($p)}); |
| 1545 |
($qx,$qy,$qSV,$qS) = unpack("d3A*",$PointTable{lc($q)}); |
| 1546 |
$pSV = $defaultLFradius if $pSV == 0; |
| 1547 |
$qSV = $defaultLFradius if $qSV == 0; |
| 1548 |
$r12 = $pSV + $qSV; |
| 1549 |
$d12 = Length($px,$py,$qx,$qy); |
| 1550 |
if ($d12 <= $r12) |
| 1551 |
{ |
| 1552 |
if($d12 == 0) |
| 1553 |
{ |
| 1554 |
PrintErrorMessage("points $p and $q are the same", $lc); |
| 1555 |
next LOOP; |
| 1556 |
} |
| 1557 |
PrintWarningMessage("arrow $p$q not drawn: points too close or ". |
| 1558 |
"radii too big", $lc); |
| 1559 |
next LOOP; |
| 1560 |
} |
| 1561 |
($px, $py) = pointOnLine($px, $py, $qx, $qy, $pSV) if $pSV > 0; |
| 1562 |
($qx, $qy) = pointOnLine($qx, $qy, $px, $py, $qSV) if $qSV > 0; |
| 1563 |
my ($beta, $gamma); |
| 1564 |
$beta = tan($arrowAngleB * D2R / 2); |
| 1565 |
$gamma = 2 * tan($arrowAngleC * D2R / 2); |
| 1566 |
printf OUT "\\arrow <%.5f%s> [%.5f,%.5f] from %.5f %.5f to %.5f %.5f\n", |
| 1567 |
$arrowLength, $arrowLengthUnits, $beta, $gamma, $px, $py, $qx, $qy; |
| 1568 |
} |
| 1569 |
} |
| 1570 |
|
| 1571 |
</pre><p>The subroutine <code>drawlines</code> is used to draw one or more lines. The subroutine |
| 1572 |
accepts as argument an array which contains the names of the points which |
| 1573 |
define the lines, plus the current program line number. If there are only |
| 1574 |
two points (i.e., only one line), then we output the following PiCTeX code: |
| 1575 |
<center> |
| 1576 |
<tt> \plot x1 y1 x2 y2 / %% pointname1 pointname2</tt> |
| 1577 |
</center> |
| 1578 |
If there are more than two points, then we need to write the PiCTeX code in |
| 1579 |
pairs with two points on each line (just to keep things simple) as follows: |
| 1580 |
<center> |
| 1581 |
<tt> \plot x1 y1 x2 y2 / %% pointname1 pointname2</tt> |
| 1582 |
<tt> \plot x2 y2 x3 y3 / %% pointname2 pointname3</tt> |
| 1583 |
<tt> \plot x3 y3 x4 y4 / %% pointname3 pointname4</tt> |
| 1584 |
</center> |
| 1585 |
<a name="NWDCUvTi-a">An important part of the subroutine is devoted to checking whether either</a> |
| 1586 |
or both of the pairs of points are associated with a line-free zone, and if |
| 1587 |
so, then we must take care not to draw the line inside the line-free zone. If |
| 1588 |
a point does have a line-free zone, then we use the <code>pointOnLine</code> |
| 1589 |
subroutine to determine the point on the line which is just on the line-free |
| 1590 |
boundary, and draw the line to the that point instead of to the exact |
| 1591 |
point-location. |
| 1592 |
|
| 1593 |
<pre><a name="NWCUvTi-3KtTfB-1" href="#NWDCUvTi-a"><dfn><subroutine <tt>drawlines</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1594 |
sub drawlines { |
| 1595 |
my ($NoArgs); |
| 1596 |
$NoArgs = @_; |
| 1597 |
my ($lc) = $_[$NoArgs-1]; #line number is the last argument |
| 1598 |
my ($NumberOfPoints, $p, $q, $r12, $d12); |
| 1599 |
my ($px,$py,$pSV,$pS, $qx,$qy,$qSV,$qS); |
| 1600 |
|
| 1601 |
$NumberOfPoints = $NoArgs - 1; |
| 1602 |
LOOP: for(my $i=0; $i < $NumberOfPoints - 1; $i++) |
| 1603 |
{ |
| 1604 |
$p = $_[$i]; |
| 1605 |
$q = $_[$i+1]; |
| 1606 |
($px,$py,$pSV,$pS) = unpack("d3A*",$PointTable{lc($p)}); |
| 1607 |
($qx,$qy,$qSV,$qS) = unpack("d3A*",$PointTable{lc($q)}); |
| 1608 |
$pSV = $defaultLFradius if $pSV == 0; |
| 1609 |
$qSV = $defaultLFradius if $qSV == 0; |
| 1610 |
$r12 = $pSV + $qSV; |
| 1611 |
$d12 = Length($px,$py,$qx,$qy); |
| 1612 |
if ($d12 <= $r12) |
| 1613 |
{ |
| 1614 |
if($d12 == 0) |
| 1615 |
{ |
| 1616 |
PrintErrorMessage("points $p and $q are the same", $lc); |
| 1617 |
next LOOP; |
| 1618 |
} |
| 1619 |
PrintWarningMessage("line $p$q not drawn: points too close or ". |
| 1620 |
"radii too big", $lc); |
| 1621 |
next LOOP; |
| 1622 |
} |
| 1623 |
($px, $py) = pointOnLine($px, $py, $qx, $qy, $pSV) if $pSV > 0; |
| 1624 |
($qx, $qy) = pointOnLine($qx, $qy, $px, $py, $qSV) if $qSV > 0; |
| 1625 |
if ($px == $qx || $py == $qy) |
| 1626 |
{ |
| 1627 |
printf OUT "\\putrule from %.5f %.5f to %.5f %.5f %%%% %s%s\n", |
| 1628 |
$px,$py,$qx,$qy,$p,$q; |
| 1629 |
} |
| 1630 |
else |
| 1631 |
{ |
| 1632 |
printf OUT "\\plot %.5f %.5f\t%.5f %.5f / %%%% %s%s\n", |
| 1633 |
$px, $py,$qx,$qy,$p,$q; |
| 1634 |
} |
| 1635 |
} |
| 1636 |
} |
| 1637 |
|
| 1638 |
</pre><p>The subroutine <code>drawCurve</code> is used to draw a curve that passes through an odd |
| 1639 |
number of points. The subroutine has as argument an array which contains the names of the |
| 1640 |
points which define the lines plus the current program line number. The subroutine |
| 1641 |
emits code that has the following general form: |
| 1642 |
<pre> |
| 1643 |
<a name="NWDCUvTi-b">\setquadratic</a> |
| 1644 |
\plot |
| 1645 |
X1 Y1 |
| 1646 |
X2 Y2 |
| 1647 |
X3 Y3 |
| 1648 |
\setlinear |
| 1649 |
</pre> |
| 1650 |
|
| 1651 |
|
| 1652 |
<pre><a name="NWCUvTi-3c2Tgd-1" href="#NWDCUvTi-b"><dfn><subroutine <tt>drawCurve</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1653 |
sub drawCurve { |
| 1654 |
my ($NoArgs); |
| 1655 |
$NoArgs = @_; |
| 1656 |
my ($lc) = $_[$NoArgs-1]; #line number is the last argument |
| 1657 |
my ($NumberOfPoints, $p); |
| 1658 |
|
| 1659 |
$NumberOfPoints = $NoArgs - 1; |
| 1660 |
print OUT "\\setquadratic\n\\plot\n"; |
| 1661 |
for(my $i=0; $i <= $NumberOfPoints; $i++) |
| 1662 |
{ |
| 1663 |
$p = $_[$i]; |
| 1664 |
my ($px,$py,$pSV,$pS) = unpack("d3A*",$PointTable{lc($p)}); |
| 1665 |
printf OUT "\t%0.5f %0.5f", $px, $py; |
| 1666 |
print OUT (($i == $NumberOfPoints) ? " / %$p\n" : " %$p\n"); |
| 1667 |
} |
| 1668 |
print OUT "\\setlinear\n"; |
| 1669 |
} |
| 1670 |
|
| 1671 |
</pre><p>The subroutine <code>drawpoints</code> is used to draw one or more points. The subroutine |
| 1672 |
<a name="NWDCUvTi-c">has as arguments a list of points. For each point we produce code that has</a> |
| 1673 |
the following general form: |
| 1674 |
<center> |
| 1675 |
<tt> \put {SYMBOL} at Px PY</tt> |
| 1676 |
</center> |
| 1677 |
where <code>SYMBOL</code> is either the default plot symbol, i.e., <code>$\bullet$</code>, |
| 1678 |
whatever the user has set with the <code>PointSymbol</code> command, or the plot |
| 1679 |
symbol specified in the definition of the point. |
| 1680 |
|
| 1681 |
<pre><a name="NWCUvTi-1NgToL-1" href="#NWDCUvTi-c"><dfn><subroutine <tt>drawpoints</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1682 |
sub drawpoints { |
| 1683 |
my ($NumberOfPoints,$p); |
| 1684 |
$NumberOfPoints = @_; |
| 1685 |
my ($px,$py,$pSV,$pS); |
| 1686 |
|
| 1687 |
for($i=0; $i < $NumberOfPoints; $i++) |
| 1688 |
{ |
| 1689 |
$p = $_[$i]; |
| 1690 |
($px,$py,$pSV,$pS) = unpack("d3A*",$PointTable{lc($p)}); |
| 1691 |
if ($pS eq "" and $defaultsymbol =~ /circle|square/) { |
| 1692 |
$pS = $defaultsymbol; |
| 1693 |
} |
| 1694 |
POINTSWITCH: { |
| 1695 |
if ($pS eq "") # no plot symbol specified |
| 1696 |
{ |
| 1697 |
printf OUT "\\put {%s} at %.5f %.5f %%%% %s\n", |
| 1698 |
$defaultsymbol, $px, $py, $p; |
| 1699 |
last POINTSWITCH; |
| 1700 |
} |
| 1701 |
if ($pS eq "circle") # plot symbol is a circle |
| 1702 |
{ |
| 1703 |
my $radius = (defined($DimOfPoint{lc($p)})) ? $DimOfPoint{lc($p)} : |
| 1704 |
$GlobalDimOfPoints; |
| 1705 |
if ($radius > 0) # draw a circle using the current units |
| 1706 |
{ |
| 1707 |
if ($radius == 1.5) # use \bigcirc |
| 1708 |
{ |
| 1709 |
printf OUT "\\put {\$\\bigcirc\$} at %.5f %.5f %%%% %s\n", |
| 1710 |
$px, $py, $p; |
| 1711 |
} |
| 1712 |
else |
| 1713 |
{ |
| 1714 |
printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f %%%% %s\n", |
| 1715 |
$px+$radius, $py, $px, $py, $p; |
| 1716 |
} |
| 1717 |
} |
| 1718 |
else #use \circ symbol |
| 1719 |
{ |
| 1720 |
printf OUT "\\put {\$\\circ\$} at %.5f %.5f %%%% %s\n", |
| 1721 |
$px,$py,$p; |
| 1722 |
} |
| 1723 |
last POINTSWITCH; |
| 1724 |
} |
| 1725 |
if ($pS eq "square") |
| 1726 |
{ |
| 1727 |
my $side = (defined($DimOfPoint{lc($p)})) ? $DimOfPoint{lc($p)} : |
| 1728 |
$GlobalDimOfPoints; |
| 1729 |
printf OUT "\\put {%s} at %.5f %.5f %%%% %s\n", |
| 1730 |
drawsquare($side), $px, $py, $p; |
| 1731 |
last POINTSWITCH; |
| 1732 |
} |
| 1733 |
printf OUT "\\put {%s} at %.5f %.5f %%%% %s\n", $pS,$px,$py,$p; |
| 1734 |
} |
| 1735 |
} |
| 1736 |
} |
| 1737 |
|
| 1738 |
</pre><p>The subroutine <code>drawAngleArc</code> gets six arguments which correspond to |
| 1739 |
three points defining an angle (variables <code>$P1</code>, <code>$P2</code> and <code>$P3</code>), |
| 1740 |
the radius, the internal/external specification and the direction |
| 1741 |
specification (clockwise or anticlockwise). |
| 1742 |
Depending on the values of these arguments, the subroutine |
| 1743 |
returns the corresponding PiCTeX code, the general format of |
| 1744 |
which is <pre> |
| 1745 |
\circulararc Angle degrees from x y center at x2 y2 |
| 1746 |
</pre> |
| 1747 |
<a name="NWDCUvTi-d">where </a><code>Angle</code> is the angle that the three points P1 P2 P3 define |
| 1748 |
(computed by subroutine <code>Angle</code>), |
| 1749 |
and <code>x</code> and <code>y</code> are the coordinates of a point |
| 1750 |
residing on line P2P1 at distance equal to a <code>$radius</code> from |
| 1751 |
point <code>$P2</code>; and <code>x2</code>, <code>y2</code> are the coordinates of the |
| 1752 |
center of the circle about which the arc is drawn, |
| 1753 |
i.e., point <code>$P2</code>. |
| 1754 |
|
| 1755 |
<pre><a name="NWCUvTi-497AQD-1" href="#NWDCUvTi-d"><dfn><subroutine <tt>drawAngleArc</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1756 |
sub drawAngleArc { |
| 1757 |
my ($P1, $P2, $P3, $radius, $inout, $direction) = @_; |
| 1758 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$P1}); |
| 1759 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$P2}); |
| 1760 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$P3}); |
| 1761 |
|
| 1762 |
my $internalAngle = Angle($x1, $y1, $x2, $y2, $x3, $y3); |
| 1763 |
my $externalAngle = 360 - $internalAngle; |
| 1764 |
my ($x, $y) = pointOnLine($x2, $y2, $x1, $y1, $radius); |
| 1765 |
my $code = ""; |
| 1766 |
if ($inout eq "internal" and $direction eq "clockwise" ) { |
| 1767 |
$code = sprintf "\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n", |
| 1768 |
-1 * $internalAngle, $x, $y, $x2, $y2; |
| 1769 |
} |
| 1770 |
elsif ($inout eq "internal" and $direction eq "anticlockwise" ) { |
| 1771 |
$code = sprintf "\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n", |
| 1772 |
$internalAngle, $x, $y, $x2, $y2; |
| 1773 |
} |
| 1774 |
elsif ($inout eq "external" and $direction eq "clockwise" ) { |
| 1775 |
$code = sprintf "\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n", |
| 1776 |
-1 * $externalAngle, $x, $y, $x2, $y2; |
| 1777 |
} |
| 1778 |
elsif ($inout eq "external" and $direction eq "anticlockwise" ) { |
| 1779 |
$code = sprintf "\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n", |
| 1780 |
$externalAngle, $x, $y, $x2, $y2; |
| 1781 |
} |
| 1782 |
return $code; |
| 1783 |
} |
| 1784 |
|
| 1785 |
</pre><p><a name="NWDCUvTi-e">The subroutine </a><code>drawAngleArrow</code> gets six arguments which correspond to |
| 1786 |
three points defining an angle (variables <code>$P1</code>, <code>$P2</code> and <code>$P3</code>), |
| 1787 |
the radius, the internal/external specification and the direction |
| 1788 |
specification. The subroutine mainly draws the arrowhead, and |
| 1789 |
calls the subroutine <code>drawAngleArc</code> to draw the |
| 1790 |
arc part of the arrow. |
| 1791 |
|
| 1792 |
<pre><a name="NWCUvTi-4UPwva-1" href="#NWDCUvTi-e"><dfn><subroutine <tt>drawAngleArrow</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1793 |
sub drawAngleArrow { |
| 1794 |
my ($P1, $P2, $P3, $radius, $inout, $direction) = @_; |
| 1795 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$P1}); |
| 1796 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$P2}); |
| 1797 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$P3}); |
| 1798 |
|
| 1799 |
my $code = drawAngleArc($P1, $P2, $P3, $radius, $inout, $direction); |
| 1800 |
|
| 1801 |
my ($xqp, $yqp) = pointOnLine($x2, $y2, $x1, $y1, $radius); |
| 1802 |
my ($deltax, $deltay) = ($x1 - $x2, $y1 - $y2); |
| 1803 |
my $AL; |
| 1804 |
|
| 1805 |
if ($xunits =~ /mm/) { |
| 1806 |
$AL = 1; |
| 1807 |
} |
| 1808 |
elsif ($xunits =~ /cm/) { |
| 1809 |
$AL = 0.1; |
| 1810 |
} |
| 1811 |
elsif ($xunits =~ /pt/) { |
| 1812 |
$AL = 2.845; |
| 1813 |
} |
| 1814 |
elsif ($xunits =~ /bp/) { |
| 1815 |
$AL = 2.835; |
| 1816 |
} |
| 1817 |
elsif ($xunits =~ /pc/) { |
| 1818 |
$AL = 0.2371; |
| 1819 |
} |
| 1820 |
elsif ($xunits =~ /in/) { |
| 1821 |
$AL = 0.03937; |
| 1822 |
} |
| 1823 |
elsif ($xunits =~ /dd/) { |
| 1824 |
$AL = 2.659; |
| 1825 |
} |
| 1826 |
elsif ($xunits =~ /cc/) { |
| 1827 |
$AL = 0.2216; |
| 1828 |
} |
| 1829 |
elsif ($xunits =~ /sp/) { |
| 1830 |
$AL = 186467.98; |
| 1831 |
} |
| 1832 |
my $halfAL = $AL / 2; |
| 1833 |
my $d = sqrt($radius * $radius - $halfAL * $halfAL); |
| 1834 |
my $alpha = atan2($d / $halfAL, 1) * R2D; |
| 1835 |
my $beta = 2 * (90 - $alpha); |
| 1836 |
my $thetaqr; |
| 1837 |
if (abs($deltay) < 0.00001) { |
| 1838 |
if ($deltax > 0 ) {$thetaqr = 0 } |
| 1839 |
elsif ($deltax < 0) {$thetaqr = -180} |
| 1840 |
} |
| 1841 |
else { |
| 1842 |
if (abs($deltax) < 0.00001) { |
| 1843 |
$thetaqr = 90; |
| 1844 |
} |
| 1845 |
else { |
| 1846 |
$thetaqr = atan2($deltay / $deltax, 1) * R2D; |
| 1847 |
} |
| 1848 |
} |
| 1849 |
my ($xqr, $yqr) = pointOnLine($x2, $y2, $x3, $y3, $radius); |
| 1850 |
$deltax = $x3 - $x2; |
| 1851 |
$deltay = $y3 - $y2; |
| 1852 |
$alpha = atan2(sqrt($radius * $radius - $halfAL * $halfAL) / $halfAL, 1) / |
| 1853 |
D2R; |
| 1854 |
$beta = 2 * (90 - $alpha); |
| 1855 |
LINE2 : { |
| 1856 |
if (abs($deltax) < 0.00001) { |
| 1857 |
if ($deltay > 0) { $thetaqr = 90 } |
| 1858 |
elsif ($deltay < 0) { $thetaqr = - 90 } |
| 1859 |
last LINE2; |
| 1860 |
} |
| 1861 |
else { |
| 1862 |
$thetaqr = atan2($deltay / $deltax, 1) * R2D; |
| 1863 |
} |
| 1864 |
if (abs($deltay) < 0.00001) { |
| 1865 |
if ($deltax > 0) { $thetaqr = 0 } |
| 1866 |
elsif ($deltax < 0) { $thetaqr = -180 } |
| 1867 |
last LINE2; |
| 1868 |
} |
| 1869 |
else { |
| 1870 |
$thetaqr = atan2($deltay / $deltax, 1) * R2D; |
| 1871 |
} |
| 1872 |
if ($deltax < 0 and $deltay > 0) { $thetaqr += 180 } |
| 1873 |
elsif ($deltax < 0 and $deltay < 0) { $thetaqr += 180 } |
| 1874 |
elsif ($deltax > 0 and $deltay < 0) { $thetaqr += 360 } |
| 1875 |
} |
| 1876 |
my $xqrleft = $x2 + $radius * cos(($thetaqr + $beta) * D2R); |
| 1877 |
my $yqrleft = $y2 + $radius * sin(($thetaqr + $beta) * D2R); |
| 1878 |
my $xqrright = $x2 + $radius * cos(($thetaqr - $beta) * D2R); |
| 1879 |
my $yqrright = $y2 + $radius * sin(($thetaqr - $beta) * D2R); |
| 1880 |
if ($inout eq "internal" and $direction eq "clockwise") { |
| 1881 |
$code .= sprintf "\\arrow <1.5mm> [0.5, 1] from %.5f %.5f to %.5f %.5f\n", |
| 1882 |
$xqrleft, $yqrleft, $xqr, $yqr; |
| 1883 |
} |
| 1884 |
elsif ($inout eq "internal" and $direction eq "anticlockwise") { |
| 1885 |
$code .= sprintf "\\arrow <1.5mm> [0.5, 1] from %.5f %.5f to %.5f %.5f\n", |
| 1886 |
$xqrright, $yqrright, $xqr, $yqr; |
| 1887 |
} |
| 1888 |
elsif ($inout eq "external" and $direction eq "clockwise") { |
| 1889 |
$code .= sprintf "\\arrow <1.5mm> [0.5, 1] from %.5f %.5f to %.5f %.5f\n", |
| 1890 |
$xqrleft, $yqrleft, $xqr, $yqr; |
| 1891 |
} |
| 1892 |
elsif ($inout eq "external" and $direction eq "anticlockwise") { |
| 1893 |
$code .= sprintf "\\arrow <1.5mm> [0.5, 1] from %.5f %.5f to %.5f %.5f\n", |
| 1894 |
$xqrright, $yqrright, $xqr, $yqr; |
| 1895 |
} |
| 1896 |
return $code; |
| 1897 |
} |
| 1898 |
|
| 1899 |
</pre><p>The subroutine <code>expr</code> is used to parse an expression. We are using a |
| 1900 |
recursive descent parser to parse and evaluate an expression. The |
| 1901 |
general syntax of an expression is as follows: |
| 1902 |
<pre> |
| 1903 |
expr ::= term { addop term } |
| 1904 |
addop ::= "+" | "-" |
| 1905 |
term ::= factor { mulop factor } |
| 1906 |
mulop ::= "*" | "/" | "rem" |
| 1907 |
factor ::= primitive [ ** factor ] |
| 1908 |
primitive ::= [ "+" | "-"] primitive | number | variable | |
| 1909 |
pair-of-points | "(" expr ")" | |
| 1910 |
"sin (" expr ")" | "cos (" expr ")" | "area (" ThreePoints ")" | |
| 1911 |
"tan (" expr ")" | "exp (" expr ")" | "int" "(" expr ")" | |
| 1912 |
"log (" expr ")" | "atan (" expr ")" | "sgn" "(" expr ")" | |
| 1913 |
<a name="NWDCUvTi-f">"sqrt (" expr ")" | "acos (" expr ")" | "asin (" expr ")" |</a> |
| 1914 |
"atan (" expr ")" | "_pi_" | "_e_" | |
| 1915 |
"xcoord (" point ")" | "ycoord (" point ")" | "angle "(" ThreePoints ")"| |
| 1916 |
"angledeg" "(" ThreePoints ")" | "direction" "(" TwoPoints ")" | |
| 1917 |
"directiondeg" "(" TwoPoints ")" | "_linethickness_" |
| 1918 |
</pre> |
| 1919 |
Note that <code>_pi_</code> and <code>_e_</code> can be used to access the value of the constants |
| 1920 |
Pi and e. |
| 1921 |
|
| 1922 |
<pre><a name="NWCUvTi-1aVxdI-1" href="#NWDCUvTi-f"><dfn><subroutine <tt>expr</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 1923 |
sub expr { |
| 1924 |
my $lc = $_[0]; |
| 1925 |
my($left,$op,$right); |
| 1926 |
|
| 1927 |
$left = term($lc); |
| 1928 |
while ($op = addop()) { |
| 1929 |
$right = term($lc); |
| 1930 |
if ($op eq '+') |
| 1931 |
{ $left += $right } |
| 1932 |
else |
| 1933 |
{ $left -= $right } |
| 1934 |
} |
| 1935 |
return $left; |
| 1936 |
} |
| 1937 |
|
| 1938 |
sub addop { |
| 1939 |
s/^([+-])// && $1; |
| 1940 |
} |
| 1941 |
|
| 1942 |
sub term { |
| 1943 |
my $lc = $_[0]; |
| 1944 |
my ($left, $op, $right); |
| 1945 |
$left = factor($lc); |
| 1946 |
while ($op = mulop()) { |
| 1947 |
$right = factor($lc); |
| 1948 |
if ($op eq '*') |
| 1949 |
{ $left *= $right } |
| 1950 |
elsif ($op =~ /rem/i) { |
| 1951 |
eval {$left %= $right}; |
| 1952 |
PrintFatalError("Division by zero", $lc) if $@; |
| 1953 |
} |
| 1954 |
else { |
| 1955 |
eval {$left /= $right}; |
| 1956 |
PrintFatalError("Division by zero", $lc) if $@; |
| 1957 |
} |
| 1958 |
} |
| 1959 |
return $left; |
| 1960 |
} |
| 1961 |
|
| 1962 |
sub mulop { |
| 1963 |
(s#^([*/])## || s/^(rem)//i) && lc($1); |
| 1964 |
} |
| 1965 |
|
| 1966 |
sub factor { |
| 1967 |
my $lc = $_[0]; |
| 1968 |
my ($left); |
| 1969 |
|
| 1970 |
$left = primitive($lc); |
| 1971 |
if (s/^\*\*//) { |
| 1972 |
$left **= factor($lc); |
| 1973 |
} |
| 1974 |
return $left; |
| 1975 |
} |
| 1976 |
|
| 1977 |
sub primitive { |
| 1978 |
my $lc = $_[0]; |
| 1979 |
my $val; |
| 1980 |
s/\s*//; |
| 1981 |
if (s/^\(//) { #is it an expr in parentheses |
| 1982 |
$val = expr($lc); |
| 1983 |
s/^\)// || PrintErrorMessage("Missing right parenthesis", $lc); |
| 1984 |
} |
| 1985 |
elsif (s/^-//) { # is it a negated primitive |
| 1986 |
$val = - primitive(); |
| 1987 |
} |
| 1988 |
elsif (s/^\+//) { # is it a positive primitive |
| 1989 |
$val = primitive(); |
| 1990 |
} |
| 1991 |
elsif (s/^angledeg//i) { |
| 1992 |
chk_lparen("angledeg",$lc); |
| 1993 |
my $point_1 = get_point($lc); |
| 1994 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1}); |
| 1995 |
my $point_2 = get_point($lc); |
| 1996 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2}); |
| 1997 |
my $point_3 = get_point($lc); |
| 1998 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3}); |
| 1999 |
my $d12 = Length($x1, $y1, $x2, $y2); |
| 2000 |
my $d23 = Length($x2, $y2, $x3, $y3); |
| 2001 |
my $d31 = Length($x3, $y3, $x1, $y1); |
| 2002 |
if ( $d12 == 0 ) { |
| 2003 |
PrintErrorMessage("points `$point_1' and `$point_2' are the same", $lc); |
| 2004 |
$val = 0; |
| 2005 |
} |
| 2006 |
elsif ( $d23 == 0 ) { |
| 2007 |
PrintErrorMessage("points `$point_2' and `$point_3' are the same", $lc); |
| 2008 |
$val = 0; |
| 2009 |
} |
| 2010 |
elsif ( $d31 == 0 ) { |
| 2011 |
PrintErrorMessage("points `$point_1' and `$point_3' are the same", $lc); |
| 2012 |
$val = 0; |
| 2013 |
} |
| 2014 |
else { |
| 2015 |
$val = Angle($x1, $y1, $x2, $y2, $x3, $y3); |
| 2016 |
$val = 0 if $val == -500; |
| 2017 |
} |
| 2018 |
chk_rparen("Missing right parenthesis", $lc); |
| 2019 |
} |
| 2020 |
elsif (s/^angle//i) { |
| 2021 |
chk_lparen("angle",$lc); |
| 2022 |
my $point_1 = get_point($lc); |
| 2023 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1}); |
| 2024 |
my $point_2 = get_point($lc); |
| 2025 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2}); |
| 2026 |
my $point_3 = get_point($lc); |
| 2027 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3}); |
| 2028 |
my $d12 = Length($x1, $y1, $x2, $y2); |
| 2029 |
my $d23 = Length($x2, $y2, $x3, $y3); |
| 2030 |
my $d31 = Length($x3, $y3, $x1, $y1); |
| 2031 |
if ( $d12 == 0 ) { |
| 2032 |
PrintErrorMessage("points `$point_1' and `$point_2' are the same", $lc); |
| 2033 |
$val = 0; |
| 2034 |
} |
| 2035 |
elsif ( $d23 == 0 ) { |
| 2036 |
PrintErrorMessage("points `$point_2' and `$point_3' are the same", $lc); |
| 2037 |
$val = 0; |
| 2038 |
} |
| 2039 |
elsif ( $d31 == 0 ) { |
| 2040 |
PrintErrorMessage("points `$point_1' and `$point_3' are the same", $lc); |
| 2041 |
$val = 0; |
| 2042 |
} |
| 2043 |
else { |
| 2044 |
$val = Angle($x1, $y1, $x2, $y2, $x3, $y3); |
| 2045 |
if ($val == -500) { |
| 2046 |
$val = 0; |
| 2047 |
} |
| 2048 |
else { |
| 2049 |
$val = D2R * $val; |
| 2050 |
} |
| 2051 |
} |
| 2052 |
chk_rparen("Missing right parenthesis", $lc); |
| 2053 |
} |
| 2054 |
elsif (s/^area//i) { |
| 2055 |
chk_lparen("angledeg",$lc); |
| 2056 |
my $point_1 = get_point($lc); |
| 2057 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1}); |
| 2058 |
my $point_2 = get_point($lc); |
| 2059 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2}); |
| 2060 |
my $point_3 = get_point($lc); |
| 2061 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3}); |
| 2062 |
$val = triangleArea($x1, $y1, $x2, $y2, $x3, $y3); |
| 2063 |
chk_rparen("Missing right parenthesis", $lc); |
| 2064 |
} |
| 2065 |
elsif (s/^asin//i) { |
| 2066 |
chk_lparen("asin"); |
| 2067 |
$val = expr(); |
| 2068 |
PrintFatalError("Can't take asin of $val", $lc) if $val < -1 || $val > 1; |
| 2069 |
$val = asin($val); |
| 2070 |
chk_rparen("Missing right parenthesis", $lc); |
| 2071 |
} |
| 2072 |
elsif (s/^acos//i) { |
| 2073 |
chk_lparen("acos"); |
| 2074 |
$val = expr(); |
| 2075 |
PrintFatalError("Can't take acos of $val", $lc) if $val < -1 || $val > 1 ; |
| 2076 |
$val = acos($val); |
| 2077 |
chk_rparen("Missing right parenthesis", $lc); |
| 2078 |
} |
| 2079 |
elsif (s/^atan//i) { |
| 2080 |
chk_lparen("atan"); |
| 2081 |
$val = expr(); |
| 2082 |
$val = atan($val); |
| 2083 |
chk_rparen("Missing right parenthesis", $lc); |
| 2084 |
} |
| 2085 |
elsif (s/^cos//i) { |
| 2086 |
chk_lparen("cos"); |
| 2087 |
$val = expr(); |
| 2088 |
$val = cos($val); |
| 2089 |
chk_rparen("Missing right parenthesis", $lc); |
| 2090 |
} |
| 2091 |
elsif (s/^directiondeg//i) { |
| 2092 |
chk_lparen("directiondeg",$lc); |
| 2093 |
my $point_1 = get_point($lc); |
| 2094 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1}); |
| 2095 |
my $point_2 = get_point($lc); |
| 2096 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2}); |
| 2097 |
my $x3 = $x1+1; |
| 2098 |
if ( ($y2 - $y1) >= 0) { |
| 2099 |
$val = Angle($x3, $y1, $x1, $y1, $x2, $y2); |
| 2100 |
$val = 0 if $val == -500; |
| 2101 |
} |
| 2102 |
else { |
| 2103 |
$val = 360 - Angle($x3, $y1, $x1, $y1, $x2, $y2); |
| 2104 |
$val = 0 if $val == -500; |
| 2105 |
} |
| 2106 |
chk_rparen("Missing right parenthesis", $lc); |
| 2107 |
} |
| 2108 |
elsif (s/^direction//i) { |
| 2109 |
chk_lparen("direction",$lc); |
| 2110 |
my $point_1 = get_point($lc); |
| 2111 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1}); |
| 2112 |
my $point_2 = get_point($lc); |
| 2113 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2}); |
| 2114 |
my $x3 = $x1+1; |
| 2115 |
if ( ($y2 - $y1) >= 0) { |
| 2116 |
$val = Angle($x3, $y1, $x1, $y1, $x2, $y2); |
| 2117 |
$val = 0 if $val == -500; |
| 2118 |
$val = D2R * $val; |
| 2119 |
} |
| 2120 |
else { |
| 2121 |
$val = 360 - Angle($x3, $y1, $x1, $y1, $x2, $y2); |
| 2122 |
$val = 0 if $val == -500; |
| 2123 |
$val = D2R * $val; |
| 2124 |
} |
| 2125 |
chk_rparen("Missing right parenthesis", $lc); |
| 2126 |
} |
| 2127 |
elsif (s/^exp//i) { |
| 2128 |
chk_lparen("exp"); |
| 2129 |
$val = expr(); |
| 2130 |
$val = exp($val); |
| 2131 |
chk_rparen("Missing right parenthesis", $lc); |
| 2132 |
} |
| 2133 |
elsif (s/^int//i) { |
| 2134 |
chk_lparen("int"); |
| 2135 |
$val = expr(); |
| 2136 |
$val = int($val); |
| 2137 |
chk_rparen("Missing right parenthesis", $lc); |
| 2138 |
} |
| 2139 |
elsif (s/^log//i) { |
| 2140 |
chk_lparen("log"); |
| 2141 |
$val = expr(); |
| 2142 |
PrintFatalError("Can't take log of $val", $lc) if $val <= 0; |
| 2143 |
$val = log($val); |
| 2144 |
chk_rparen("Missing right parenthesis", $lc); |
| 2145 |
} |
| 2146 |
elsif (s/^sin//i) { |
| 2147 |
chk_lparen("sin"); |
| 2148 |
$val = expr(); |
| 2149 |
$val = sin($val); |
| 2150 |
chk_rparen("Missing right parenthesis", $lc); |
| 2151 |
} |
| 2152 |
elsif (s/^sgn//i) { |
| 2153 |
chk_lparen("sgn"); |
| 2154 |
$val = expr(); |
| 2155 |
if ($val > 0) { |
| 2156 |
$val = 1; |
| 2157 |
} |
| 2158 |
elsif ($val == 0) { |
| 2159 |
$val = 0; |
| 2160 |
} |
| 2161 |
else { |
| 2162 |
$val = -1; |
| 2163 |
} |
| 2164 |
chk_rparen("Missing right parenthesis", $lc); |
| 2165 |
} |
| 2166 |
elsif (s/^sqrt//i) { |
| 2167 |
chk_lparen("sqrt"); |
| 2168 |
$val = expr(); |
| 2169 |
$val = sqrt($val); |
| 2170 |
chk_rparen("Missing right parenthesis", $lc); |
| 2171 |
} |
| 2172 |
elsif (s/^tan//i) { |
| 2173 |
chk_lparen("tan"); |
| 2174 |
$val = expr(); |
| 2175 |
$val = sin($val)/cos($val); |
| 2176 |
chk_rparen("Missing right parenthesis", $lc); |
| 2177 |
} |
| 2178 |
elsif (s/^xcoord//i) { |
| 2179 |
chk_lparen("xcoord"); |
| 2180 |
my $point_name = get_point; |
| 2181 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_name}); |
| 2182 |
$val = $x1; |
| 2183 |
chk_rparen("Missing right parenthesis", $lc); |
| 2184 |
} |
| 2185 |
elsif (s/^ycoord//i) { |
| 2186 |
chk_lparen("ycoord"); |
| 2187 |
my $point_name = get_point; |
| 2188 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_name}); |
| 2189 |
$val = $y1; |
| 2190 |
chk_rparen("Missing right parenthesis", $lc); |
| 2191 |
} |
| 2192 |
elsif (s/^_pi_//i) { |
| 2193 |
$val = PI; |
| 2194 |
} |
| 2195 |
elsif (s/^_e_//i) { |
| 2196 |
$val = 2.71828182845905; |
| 2197 |
} |
| 2198 |
elsif (s/^_linethickness_//i) { |
| 2199 |
$val = $LineThickness / $xunits; |
| 2200 |
} |
| 2201 |
else { |
| 2202 |
my $err_code; |
| 2203 |
($val,$err_code) = ComputeDist($lc); |
| 2204 |
} |
| 2205 |
s/\s*//; |
| 2206 |
return $val; |
| 2207 |
} |
| 2208 |
|
| 2209 |
</pre><p><a name="NWDCUvTi-g">The subroutine </a><code>memberOf</code> is used to check whether a string is part of |
| 2210 |
a list of strings. We assume that the first argument is the string in |
| 2211 |
question. We compare each list element against the string in question and |
| 2212 |
if we find it we stop and return the value <code>1</code> (denoting truth). Otherwise, |
| 2213 |
we simply return the value <code>0</code> (denoting false). |
| 2214 |
|
| 2215 |
<pre><a name="NWCUvTi-2tc9Fr-1" href="#NWDCUvTi-g"><dfn><subroutine <tt>memberOf</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 2216 |
sub memberOf { |
| 2217 |
my $elem = shift(@_); |
| 2218 |
|
| 2219 |
my $found = 0; |
| 2220 |
foreach $item (@_){ |
| 2221 |
if ($item eq $elem){ |
| 2222 |
$found = 1; |
| 2223 |
last; |
| 2224 |
} |
| 2225 |
} |
| 2226 |
return $found; |
| 2227 |
} |
| 2228 |
|
| 2229 |
</pre><p><a name="NWDCUvTi-h">The subroutine </a><code>midpoint</code> computes the coordinates of the midpoint of two points |
| 2230 |
by means of the simple formula: |
| 2231 |
<center> |
| 2232 |
m<sub>x</sub>=x<sub>1</sub>+(y<sub>2</sub> - y<sub>1</sub>)/2 <br> |
| 2233 |
m<sub>y</sub>=y<sub>1</sub>+(x<sub>2</sub> - x<sub>1</sub>)/2 |
| 2234 |
</center> |
| 2235 |
|
| 2236 |
<pre><a name="NWCUvTi-2wh1NN-1" href="#NWDCUvTi-h"><dfn><subroutine <tt>midpoint</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 2237 |
sub midpoint { |
| 2238 |
my ($x1, $y1, $x2, $y2)=@_; |
| 2239 |
return ($x1 + ($x2 - $x1)/2, |
| 2240 |
$y1 + ($y2 - $y1)/2); |
| 2241 |
} |
| 2242 |
|
| 2243 |
|
| 2244 |
</pre><p><a name="NWDCUvTi-i">The subroutine </a><code>tand</code> computes the tangent of an angle. The angle is |
| 2245 |
supposed to be in degrees. We simply transform it into radians and then |
| 2246 |
compute the actual result. |
| 2247 |
|
| 2248 |
<pre><a name="NWCUvTi-22jtMr-1" href="#NWDCUvTi-i"><dfn><subroutine <tt>tand</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 2249 |
sub tand { |
| 2250 |
my $d = $_[0]; |
| 2251 |
$d = $d * PI / 180; |
| 2252 |
return sin($d)/cos($d); |
| 2253 |
} |
| 2254 |
|
| 2255 |
</pre><p>The subroutine <code>get_string</code> is used to extract a leading valid mathspic string |
| 2256 |
from the input line. A string must start with a quotation mark, i.e., <code>"</code>, |
| 2257 |
and must end with the same symbol. A string may contain quotation marks which |
| 2258 |
must be escaped with a backslash, i.e., <code>\</code>. Initially, we remove all |
| 2259 |
leading white space. If the next character of the string is not a quotation |
| 2260 |
mark we print an error message and stop. Otherwise, we split the string into |
| 2261 |
an array of characters and store the characters up to the next quotation |
| 2262 |
mark to the array <code>@cmd</code>. In case the next character is a backslash and |
| 2263 |
we aren't at the end of the input string and the next character is a |
| 2264 |
quotation mark, we have an escape sequence. This means that we store these |
| 2265 |
two characters in the <code>@cmd</code> array and skip to characters after the quotation |
| 2266 |
mark. Otherwise, we simply store the character in the <code>@cmd</code> array and |
| 2267 |
<a name="NWDCUvTi-j">skip to the next character. This process is repeated until either we consume</a> |
| 2268 |
all the characters of the string or until we find a sole quotation mark. |
| 2269 |
Since we are not sure what has forced the loop to exit, we check whether |
| 2270 |
there are still characters in the input string and we check whether this |
| 2271 |
is a quotation mark. If these tests fail we have a string without a |
| 2272 |
closing quotation mark. In all cases we return a triplet consisting of |
| 2273 |
a number denoting success (1) or failure (0) and what we have consumed |
| 2274 |
from the input string, and what is left from the input string. |
| 2275 |
|
| 2276 |
<pre><a name="NWCUvTi-ufkvF-1" href="#NWDCUvTi-j"><dfn><subroutine <tt>get_string</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 2277 |
sub get_string { |
| 2278 |
my $string = shift; |
| 2279 |
my $lc = shift; |
| 2280 |
|
| 2281 |
$string =~ s/^\s+//; |
| 2282 |
if ($string !~ s/^\"//) { |
| 2283 |
PrintErrorMessage("No starting \" found",$lc); |
| 2284 |
return (1,$string,$string); |
| 2285 |
} |
| 2286 |
my @ch = split //,$string; |
| 2287 |
my @cmd; |
| 2288 |
while (@ch and $ch[0] ne "\"") { |
| 2289 |
if ($ch[0] eq "\\" and (defined $ch[1]) and $ch[1] eq "\"") { |
| 2290 |
shift @ch; |
| 2291 |
push @cmd, $ch[0]; |
| 2292 |
shift @ch; |
| 2293 |
} |
| 2294 |
else { |
| 2295 |
push @cmd, $ch[0]; |
| 2296 |
shift @ch; |
| 2297 |
} |
| 2298 |
} |
| 2299 |
if (! defined $ch[0]) { |
| 2300 |
PrintErrorMessage("No closing \" found",$lc); |
| 2301 |
return (1,join("",@cmd), join("",@ch)) |
| 2302 |
} |
| 2303 |
else { |
| 2304 |
shift @ch; |
| 2305 |
return (0, join("",@cmd), join("",@ch)) |
| 2306 |
} |
| 2307 |
} |
| 2308 |
|
| 2309 |
</pre><p><a name="NWDCUvTi-k">The definition as well as an explanation of the functionality of the</a> |
| 2310 |
following subroutine can be found in "Programming Perl", 3rd edition. |
| 2311 |
|
| 2312 |
<pre><a name="NWCUvTi-1MGdDt-1" href="#NWDCUvTi-k"><dfn><subroutine <tt>is_tainted</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 2313 |
sub is_tainted { |
| 2314 |
my $arg = shift; |
| 2315 |
my $nada = substr($arg,0,0); |
| 2316 |
local $@; |
| 2317 |
eval { eval "# $nada"}; |
| 2318 |
return length($@) != 0; |
| 2319 |
} |
| 2320 |
|
| 2321 |
</pre><p><a name="NWDCUvTi-l">The subroutine </a><code>noOfDigits</code> has one argument which is a number and returns |
| 2322 |
the number of decimal digits it has. If the number matches the regular |
| 2323 |
expression <code>^\d+(?!\.)</code> (a series of digits <i>not</i> followed by a |
| 2324 |
period), then the number of decimal digits is zero. If the |
| 2325 |
number matches the |
| 2326 |
regular expression <code>^\d+\.(\d+)?</code>, then number of decimal digits equals |
| 2327 |
<code>length($1)</code>. Naturally, it maybe zero! |
| 2328 |
|
| 2329 |
<pre><a name="NWCUvTi-3mBo7s-1" href="#NWDCUvTi-l"><dfn><subroutine <tt>noOfDigits</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 2330 |
sub noOfDigits { |
| 2331 |
my $num = $_[0]; |
| 2332 |
|
| 2333 |
if ($num =~ /^[\+-]?\d+(?!\.)/) { |
| 2334 |
return 0; |
| 2335 |
} |
| 2336 |
elsif ($num =~ /^[\+-]\d+\.(\d+)?/) { |
| 2337 |
return length($1); |
| 2338 |
} |
| 2339 |
} |
| 2340 |
|
| 2341 |
</pre><p><a name="NWDCUvTi-m">Subroutine </a><code>drawsquare</code> is use by the <code>drawpoints</code> routine to plot a |
| 2342 |
point whose point symbol is a square. The subroutine has one argument, which is |
| 2343 |
equal to the radius of the point. From this argument it computes the side of |
| 2344 |
the square. |
| 2345 |
|
| 2346 |
<pre><a name="NWCUvTi-3ywJ89-1" href="#NWDCUvTi-m"><dfn><subroutine <tt>drawsquare</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 2347 |
sub drawsquare { |
| 2348 |
my $s = $_[0]; |
| 2349 |
#$s *= sqrt(2); |
| 2350 |
$s = sprintf "%.5f", $s; |
| 2351 |
my $code = "\\setlength{\\unitlength}{$xunits}%\n"; |
| 2352 |
$code .= "\\begin{picture}($s,$s)\\put(0,0)" . |
| 2353 |
"{\\framebox($s,$s){}}\\end{picture}"; |
| 2354 |
return $code; |
| 2355 |
} |
| 2356 |
|
| 2357 |
</pre><p><a name="NWDCUvTi-n">Subroutine </a><code>X2sp</code> has two arguments: a number and a length unit. It returns |
| 2358 |
the length expresssed in sp units. |
| 2359 |
|
| 2360 |
<pre><a name="NWCUvTi-39f7o8-1" href="#NWDCUvTi-n"><dfn><subroutine <tt>X2sp</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 2361 |
sub X2sp { |
| 2362 |
my $LT = shift; |
| 2363 |
my $units = shift; |
| 2364 |
|
| 2365 |
if ($units eq "pc") { |
| 2366 |
return $LT * 786432; |
| 2367 |
} |
| 2368 |
elsif ($units eq "pt") { |
| 2369 |
return $LT * 65536; |
| 2370 |
} |
| 2371 |
elsif ($units eq "in") { |
| 2372 |
return $LT * 4736286.72; |
| 2373 |
} |
| 2374 |
elsif ($units eq "bp") { |
| 2375 |
return $LT * 65781.76; |
| 2376 |
} |
| 2377 |
elsif ($units eq "cm") { |
| 2378 |
return $LT * 1864679.811023622; |
| 2379 |
} |
| 2380 |
elsif ($units eq "mm") { |
| 2381 |
return $LT * 186467.981102362; |
| 2382 |
} |
| 2383 |
elsif ($units eq "dd") { |
| 2384 |
return $LT * 70124.086430424; |
| 2385 |
} |
| 2386 |
elsif ($units eq "cc") { |
| 2387 |
return $LT * 841489.037165082; |
| 2388 |
} |
| 2389 |
elsif ($units eq "sp") { |
| 2390 |
return $LT; |
| 2391 |
} |
| 2392 |
} |
| 2393 |
|
| 2394 |
|
| 2395 |
</pre><p><a name="NWDCUvTi-o">Subroutine </a><code>sp2X</code> has two arguments: a number that denotes a length in sp units |
| 2396 |
and a length unit. It returns the length expresssed in units that are specified by |
| 2397 |
the second argument. |
| 2398 |
|
| 2399 |
<pre><a name="NWCUvTi-3wV39i-1" href="#NWDCUvTi-o"><dfn><subroutine <tt>sp2X</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 2400 |
sub sp2X { |
| 2401 |
my $LT = shift; |
| 2402 |
my $units = shift; |
| 2403 |
|
| 2404 |
if ($units eq "pc") { |
| 2405 |
return $LT / 786432; |
| 2406 |
} |
| 2407 |
elsif ($units eq "pt") { |
| 2408 |
return $LT / 65536; |
| 2409 |
} |
| 2410 |
elsif ($units eq "in") { |
| 2411 |
return $LT / 4736286.72; |
| 2412 |
} |
| 2413 |
elsif ($units eq "bp") { |
| 2414 |
return $LT / 65781.76; |
| 2415 |
} |
| 2416 |
elsif ($units eq "cm") { |
| 2417 |
return $LT / 1864679.811023622; |
| 2418 |
} |
| 2419 |
elsif ($units eq "mm") { |
| 2420 |
return $LT / 186467.981102362; |
| 2421 |
} |
| 2422 |
elsif ($units eq "dd") { |
| 2423 |
return $LT / 70124.086430424; |
| 2424 |
} |
| 2425 |
elsif ($units eq "cc") { |
| 2426 |
return $LT / 841489.037165082; |
| 2427 |
} |
| 2428 |
elsif ($units eq "sp") { |
| 2429 |
return $LT; |
| 2430 |
} |
| 2431 |
} |
| 2432 |
|
| 2433 |
</pre><p><a name="NWDCUvTi-p">Subroutine </a><code>setLineThickness</code> takes two arguments: the value of the variable |
| 2434 |
<code>$xunits</code> and a string denoting the linethickness. It returns the linthickness |
| 2435 |
expressed in the units of the <code>$xunits</code>. |
| 2436 |
|
| 2437 |
<pre><a name="NWCUvTi-4XWBBY-1" href="#NWDCUvTi-p"><dfn><subroutine <tt>setLineThickness</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 2438 |
sub setLineThickness { |
| 2439 |
my $Xunits = shift; |
| 2440 |
my $LT = shift; |
| 2441 |
$Xunits =~ s/^((\+|-)?\d+(\.\d+)?([eE](\+|-)?\d+)?)//; |
| 2442 |
my $xlength = "$1"; |
| 2443 |
$Xunits =~ s/^\s*($units)//; |
| 2444 |
my $x_in_units = $1; |
| 2445 |
$LT =~ s/^((\+|-)?\d+(\.\d+)?([eE](\+|-)?\d+)?)//; |
| 2446 |
my $LTlength = "$1"; |
| 2447 |
$LT =~ s/^\s*($units)//; |
| 2448 |
my $LT_in_units = $1; |
| 2449 |
$LTlength = X2sp($LTlength,$LT_in_units); |
| 2450 |
$LTlength = sp2X($LTlength,$x_in_units); |
| 2451 |
return $LTlength; |
| 2452 |
} |
| 2453 |
|
| 2454 |
</pre><p>The subroutine <code>process_input</code> accepts one argument which is a file handle |
| 2455 |
that corresponds to the file that the subroutine is supposed to process. |
| 2456 |
The processing cycle is fairly simple: we input one line at the time, remove |
| 2457 |
any leading space characters and the trailing new line character, and then |
| 2458 |
start the actual processing. The variable <code>$INFILE</code> contains the name of |
| 2459 |
the input file and the variable <code>$lc</code> is the local line counter. The |
| 2460 |
commands <code>beginSkip</code> and <code>endSkip</code> can be used to ignore blocks |
| 2461 |
of code and so we need to process them here. The variable <code>$no_output</code> |
| 2462 |
is used as a switch to toggle from process mode to no-precess mode. |
| 2463 |
<a name="NWDCUvTi-q">If the first token is </a><code>beginSkip</code>, we set the variable <code>$no_output</code> to 1, |
| 2464 |
print a comment to the output file and continue with the next input line. |
| 2465 |
If the first token is <code>endSkip</code>, we check whether we are in a no-process |
| 2466 |
mode. If this is the case, we revert to process mode; otherwise we print |
| 2467 |
an error message. Finally, depending on whether we are in process or no-process |
| 2468 |
mode we process the input text or simply printed commented out to the output |
| 2469 |
file. Note, that we don't allow nested comment blocks, as this makes really |
| 2470 |
no sense! |
| 2471 |
|
| 2472 |
<pre><a name="NWCUvTi-1RrLPF-1" href="#NWDCUvTi-q"><dfn><subroutine <tt>process_input</tt> >=</dfn></a> <b>(<a href="#NWDCUvTi-9"><-U</a>)</b> |
| 2473 |
sub process_input { |
| 2474 |
my ($INFILE,$currInFile) = @_; |
| 2475 |
my $lc = 0; |
| 2476 |
my $no_output = 0; |
| 2477 |
$curr_in_file = $currInFile; |
| 2478 |
LINE: while(<$INFILE>) { |
| 2479 |
$lc++; |
| 2480 |
chomp($command = $_); |
| 2481 |
s/^\s+//; |
| 2482 |
if (/^beginSkip\s*/i) { |
| 2483 |
$no_output = 1; |
| 2484 |
print OUT "%%$_" if $comments_on; |
| 2485 |
next LINE; |
| 2486 |
} |
| 2487 |
elsif (/^endSkip\s*/i) { |
| 2488 |
if ($no_output == 0) { |
| 2489 |
PrintErrorMessage("endSkip without beginSkip",$lc); |
| 2490 |
} |
| 2491 |
else { |
| 2492 |
$no_output = 0; |
| 2493 |
} |
| 2494 |
print OUT "%%$_" if $comments_on and !$no_output; |
| 2495 |
next LINE; |
| 2496 |
} |
| 2497 |
elsif ($no_output == 1) { |
| 2498 |
next LINE; |
| 2499 |
} |
| 2500 |
else { |
| 2501 |
if (/^[^\\]/) { |
| 2502 |
my $out_line = mpp($command,$lc) unless /^\\/; #call macro pre-processor |
| 2503 |
$_ = "$out_line\n"; |
| 2504 |
} |
| 2505 |
<a name="NWCUvTi-1RrLPF-1-u1" href="#NWDCUvTi-r"><i><process input line></i></a> |
| 2506 |
} |
| 2507 |
} |
| 2508 |
} |
| 2509 |
|
| 2510 |
</pre><p>Each command line starts with a particular <i>token</i> and depending on |
| 2511 |
which one we have we perform different actions. If the first character |
| 2512 |
is <code>%</code> we have a comment line, and depending on the value of the variable |
| 2513 |
<code>$comments_on</code> we either output the comment on the output file (default |
| 2514 |
action) or just ignore it and continue with the next input line. In case the |
| 2515 |
first token is the name of a valid command we process the command and |
| 2516 |
output the corresponding code. Otherwise, we print an error message to |
| 2517 |
the screen and to the log file and continue with the next input line. |
| 2518 |
Note that the input language is case-insensitive and so one is free to write a |
| 2519 |
command name using any combination of upper and lower case |
| 2520 |
letters, e.g., the tokens <code>lAtEx</code>, |
| 2521 |
<code>LaTeX</code>, and <code>latex</code> are considered exactly the same. |
| 2522 |
The valid <i>MathsPIC</i> commands are the following (don't pay attention |
| 2523 |
to the case!): |
| 2524 |
<ul> |
| 2525 |
<li> |
| 2526 |
Commands <code>drawAngleArc</code> and <code>drawAngleArrow</code> are used to draw an arc and an |
| 2527 |
arrow, respectively. Since, their user interface is identical, we process |
| 2528 |
them as if they were identical commands. |
| 2529 |
</li> |
| 2530 |
<li> |
| 2531 |
Command <code>drawcircle</code> is used to draw a circle with a specified radius. |
| 2532 |
</li> |
| 2533 |
<li> |
| 2534 |
Command <code>drawCircumCircle</code> is used to draw the circumcircle of triangle |
| 2535 |
specified by three points. |
| 2536 |
</li> |
| 2537 |
<li> |
| 2538 |
Command <code>drawexcircle</code> is used to draw the excircle of triangle |
| 2539 |
relative to a given side of the triangle. |
| 2540 |
</li> |
| 2541 |
<li> |
| 2542 |
Command <code>drawincircle</code> is used to draw the incircle of triangle. |
| 2543 |
</li> |
| 2544 |
<li> |
| 2545 |
Command <code>drawincurve</code> is used to draw a curve that passes through a number of points. |
| 2546 |
</li> |
| 2547 |
<li> Command <code>drawline</code> is used to draw either |
| 2548 |
a line (not necessarily a straight one) or a number of lines from a list |
| 2549 |
or lists of points. The lines are specified as pairs of points that can |
| 2550 |
be separated by blank spaces. |
| 2551 |
<li> Command <code>drawthickline</code> is used to draw either |
| 2552 |
a thick line (not necessarily a straight one) or a number of lines from a list |
| 2553 |
or lists of points. The lines are specified as pairs of points that can |
| 2554 |
be separated by blank spaces. |
| 2555 |
</li> |
| 2556 |
<li> |
| 2557 |
Command <code>drawPerpendicular</code> draws a perpendicular line from point A to |
| 2558 |
line BC. |
| 2559 |
</li> |
| 2560 |
<li> Command <code>drawpoint</code> is used to draw one, two or more points. |
| 2561 |
The point names can be separated by blanks. |
| 2562 |
</li> |
| 2563 |
<li> |
| 2564 |
Command <code>drawRightAngle</code> draws an angle, specified by three points, |
| 2565 |
of a size specified by a side length. |
| 2566 |
</li> |
| 2567 |
<li> |
| 2568 |
Command <code>drawsquare</code> draws a square, centered at the coordinates of the |
| 2569 |
first arguments, which is assumed to be a point, with side equal to the |
| 2570 |
second argument. |
| 2571 |
</li> |
| 2572 |
<li> |
| 2573 |
Command <code>inputfile*</code> is used to verbatim include a file into the output |
| 2574 |
file. |
| 2575 |
</li> |
| 2576 |
<li> |
| 2577 |
Command <code>inputfile</code> is used to include a <i>MathsPIC</i> program file |
| 2578 |
into the main file. |
| 2579 |
</li> |
| 2580 |
<li> |
| 2581 |
Command <code>linethickness</code> should be used to set the thickness of lines. |
| 2582 |
</li> |
| 2583 |
<li> |
| 2584 |
The <code>paper</code> command sets the paper scale, size, axes, etc. The most |
| 2585 |
general format of the command follows: |
| 2586 |
<center> |
| 2587 |
<tt>paper{units(mm), xrange(0,120), yrange(0,100),axes(LRTB)}</tt> |
| 2588 |
</center> |
| 2589 |
Note, that one may opt not to write the commas between the different |
| 2590 |
parts of command. |
| 2591 |
</li> |
| 2592 |
<li> |
| 2593 |
Command <code>point*</code> allocates <i>new</i> co-ordinates and optionally |
| 2594 |
a T<sub>E</sub>X point-name, to an existing point-name. |
| 2595 |
Command <code>point</code> allocates co-ordinates and, optionally a T<sub>E</sub>X |
| 2596 |
point character, to a <i>new</i> point-name. Since, both commands have |
| 2597 |
identical syntax, we handle them together. |
| 2598 |
</li> |
| 2599 |
<li> Command <code>PointSymbol</code> is used to set or reset the default |
| 2600 |
point symbol, i.e., when one plots a point this is the symbol that will |
| 2601 |
appear on the final DVI/PostScript file. |
| 2602 |
</li> |
| 2603 |
<li> |
| 2604 |
In the original DOS version of <tt>mathspic</tt> the command |
| 2605 |
<code>setPointNumber</code> was used to set the length of the arrays that keep the |
| 2606 |
various point related information. Since, in Perl arrays are dynamic objects |
| 2607 |
and one can push as many objects as he/she wants, the command is implemented |
| 2608 |
as an no-op. For reasons of compatibility, we only check the syntax of the |
| 2609 |
command. |
| 2610 |
</li> |
| 2611 |
<li> |
| 2612 |
Commands <code>showAngle</code> and <code>showArea</code> can be used to get |
| 2613 |
the angle or the area determined by three points. In addition, the command |
| 2614 |
<code>showLenght</code> can be used to get the length between two points. These three |
| 2615 |
commands produce a comment to the output file. |
| 2616 |
</li> |
| 2617 |
<li> The <code>system</code> command provides a shell escape. |
| 2618 |
</li> |
| 2619 |
<li> |
| 2620 |
The <code>text</code> command is used to put a symbol/text at a |
| 2621 |
particular point location. |
| 2622 |
</li> |
| 2623 |
<li> |
| 2624 |
Command <code>var</code> is used to store a numeric value into a comma separated |
| 2625 |
list of variables. |
| 2626 |
</li> |
| 2627 |
<li> |
| 2628 |
Command <code>const</code> is used to store a numeric value into a comma separated |
| 2629 |
list of variables, whose value cannot be altered. |
| 2630 |
</li> |
| 2631 |
<li> |
| 2632 |
<a name="NWDCUvTi-r">If a line starts with a backslash, </a><code>\</code>, then we copy verbatim this |
| 2633 |
line to the output file. In case the second character is a space character, |
| 2634 |
then we simply output a copy of the line without the leading backslash. |
| 2635 |
</li> |
| 2636 |
</ul> |
| 2637 |
Empty lines are always ignored. |
| 2638 |
|
| 2639 |
<pre><a name="NWCUvTi-RKDir-1" href="#NWDCUvTi-r"><dfn><process input line>=</dfn></a> <b>(<a href="#NWDCUvTi-q"><-U</a>)</b> |
| 2640 |
|
| 2641 |
if (/^\s*%/) |
| 2642 |
{ |
| 2643 |
print OUT "$_" if $comments_on; |
| 2644 |
} |
| 2645 |
elsif (s/^\s*(beginloop(?=\W))//i) { |
| 2646 |
s/\s+//; |
| 2647 |
my $times = expr($lc); |
| 2648 |
print OUT "%% BEGINLOOP $times\n" if $comments_on; |
| 2649 |
my @C = (); |
| 2650 |
REPEATCOMMS: while (<$INFILE>) { |
| 2651 |
if (/^\s*endloop/i) { |
| 2652 |
last REPEATCOMMS; |
| 2653 |
} |
| 2654 |
else { |
| 2655 |
push @C, $_; |
| 2656 |
} |
| 2657 |
} |
| 2658 |
if (! /^\s*endloop/i) { |
| 2659 |
PrintFatalError("unexpected end of file",$lc); |
| 2660 |
} |
| 2661 |
else { |
| 2662 |
s/^\s*endloop//i; |
| 2663 |
for(my $i=1; $i<=$times; $i++) { |
| 2664 |
tie *DUMMY, 'DummyFH', \@C; |
| 2665 |
process_input(DUMMY, $currInFile); |
| 2666 |
untie *DUMMY; |
| 2667 |
} |
| 2668 |
print OUT "%% ENDLOOP\n" if $comments_on; |
| 2669 |
} |
| 2670 |
} |
| 2671 |
elsif (s/^\s*(ArrowShape(?=\W))//i) |
| 2672 |
{ |
| 2673 |
my $cmd = $1; |
| 2674 |
print OUT "%% $cmd$_" if $comments_on; |
| 2675 |
<a name="NWCUvTi-RKDir-1-u1" href="#NWDCUvTi-1W"><i><process <tt>ArrowShape</tt> command></i></a> |
| 2676 |
} |
| 2677 |
elsif (s/^\s*(const(?=\W))//i) |
| 2678 |
{ |
| 2679 |
print OUT "%% $1$_" if $comments_on; |
| 2680 |
<a name="NWCUvTi-RKDir-1-u2" href="#NWDCUvTi-1c"><i><process <tt>const</tt> command></i></a> |
| 2681 |
} |
| 2682 |
elsif (s/^\s*(dasharray(?=\W))//i) |
| 2683 |
{ |
| 2684 |
my ($cmd) = $1; |
| 2685 |
print OUT "%% $cmd$_" if $comments_on; |
| 2686 |
<a name="NWCUvTi-RKDir-1-u3" href="#NWDCUvTi-s"><i><process <tt>dasharray</tt> command></i></a> |
| 2687 |
} |
| 2688 |
elsif (s/^\s*(drawAngleArc(?=\W))//i or s/^\s*(drawAngleArrow(?=\W))//i ) |
| 2689 |
{ |
| 2690 |
my $cmd = $1; |
| 2691 |
print OUT "%% $cmd$_" if $comments_on; |
| 2692 |
<a name="NWCUvTi-RKDir-1-u4" href="#NWDCUvTi-t"><i><process <tt>drawAngleArcOrArrow</tt> command></i></a> |
| 2693 |
} |
| 2694 |
elsif (s/^\s*(drawArrow(?=\W))//i) |
| 2695 |
{ |
| 2696 |
my ($cmd) = $1; |
| 2697 |
print OUT "%% $cmd$_" if $comments_on; |
| 2698 |
DrawLineOrArrow(0,$lc); |
| 2699 |
} |
| 2700 |
elsif (s/^\s*(drawcircle(?=\W))//i) |
| 2701 |
{ |
| 2702 |
my ($cmd) = $1; |
| 2703 |
print OUT "%% $cmd$_" if $comments_on; |
| 2704 |
<a name="NWCUvTi-RKDir-1-u5" href="#NWDCUvTi-w"><i><process <tt>drawcircle</tt> command></i></a> |
| 2705 |
} |
| 2706 |
elsif (s/^\s*(drawcurve(?=\W))//i) |
| 2707 |
{ |
| 2708 |
my ($cmd) = $1; |
| 2709 |
print OUT "%% $cmd$_" if $comments_on; |
| 2710 |
DrawLineOrArrow(2,$lc); |
| 2711 |
} |
| 2712 |
elsif (s/^\s*(drawcircumcircle(?=\W))//i) |
| 2713 |
{ |
| 2714 |
my ($cmd) = $1; |
| 2715 |
print OUT "%% $cmd$_" if $comments_on; |
| 2716 |
<a name="NWCUvTi-RKDir-1-u6" href="#NWDCUvTi-x"><i><process <tt>drawcircumcircle</tt> command></i></a> |
| 2717 |
} |
| 2718 |
elsif (s/^\s*(drawexcircle(?=\W))//i) |
| 2719 |
{ |
| 2720 |
my ($cmd) = $1; |
| 2721 |
print OUT "%% $cmd$_" if $comments_on; |
| 2722 |
<a name="NWCUvTi-RKDir-1-u7" href="#NWDCUvTi-y"><i><process <tt>drawexcircle</tt> command></i></a> |
| 2723 |
} |
| 2724 |
elsif (s/^\s*(drawincircle(?=\W))//i) |
| 2725 |
{ |
| 2726 |
my ($cmd) = $1; |
| 2727 |
print OUT "%% $cmd$_" if $comments_on; |
| 2728 |
<a name="NWCUvTi-RKDir-1-u8" href="#NWDCUvTi-z"><i><process <tt>drawincircle</tt> command></i></a> |
| 2729 |
} |
| 2730 |
elsif (s/^\s*(drawline(?=\W))//i) |
| 2731 |
{ |
| 2732 |
my ($cmd) = $1; |
| 2733 |
print OUT "%% $cmd$_" if $comments_on; |
| 2734 |
DrawLineOrArrow(1,$lc); |
| 2735 |
} |
| 2736 |
elsif (s/^\s*(drawthickarrow(?=\W))//i) |
| 2737 |
{ |
| 2738 |
my ($cmd) = $1; |
| 2739 |
print OUT "%% $cmd$_" if $comments_on; |
| 2740 |
print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\large .})%\n"; |
| 2741 |
print OUT "{\\setbox1=\\hbox{\\usefont{OT1}{cmr}{m}{n}\\large .}%\n"; |
| 2742 |
print OUT " \\global\\linethickness=0.31\\wd1}%\n"; |
| 2743 |
DrawLineOrArrow(0,$lc); |
| 2744 |
print OUT "\\setlength{\\linethickness}{0.4pt}%\n"; |
| 2745 |
print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\tiny .})%\n"; |
| 2746 |
} |
| 2747 |
elsif (s/^\s*(drawthickline(?=\W))//i) |
| 2748 |
{ |
| 2749 |
my ($cmd) = $1; |
| 2750 |
print OUT "%% $cmd$_" if $comments_on; |
| 2751 |
print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\large .})%\n"; |
| 2752 |
print OUT "{\\setbox1=\\hbox{\\usefont{OT1}{cmr}{m}{n}\\large .}%\n"; |
| 2753 |
print OUT " \\global\\linethickness=0.31\\wd1}%\n"; |
| 2754 |
DrawLineOrArrow(1,$lc); |
| 2755 |
print OUT "\\setlength{\\linethickness}{0.4pt}%\n"; |
| 2756 |
print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\tiny .})%\n"; |
| 2757 |
} |
| 2758 |
elsif (s/^\s*(drawperpendicular(?=\W))//i) |
| 2759 |
{ |
| 2760 |
my ($cmd) = $1; |
| 2761 |
print OUT "%% $cmd$_" if $comments_on; |
| 2762 |
<a name="NWCUvTi-RKDir-1-u9" href="#NWDCUvTi-10"><i><process <tt>drawPerpendicular</tt> command></i></a> |
| 2763 |
} |
| 2764 |
elsif (s/^\s*(drawpoint(?=\W))//i) |
| 2765 |
{ |
| 2766 |
my ($cmd) = $1; |
| 2767 |
print OUT "%% $cmd$_" if $comments_on; |
| 2768 |
<a name="NWCUvTi-RKDir-1-u10" href="#NWDCUvTi-11"><i><process <tt>drawpoint</tt> command></i></a> |
| 2769 |
} |
| 2770 |
elsif (s/^\s*(drawRightAngle(?=\W))//i) |
| 2771 |
{ |
| 2772 |
my ($cmd) = $1; |
| 2773 |
print OUT "%% $cmd$_" if $comments_on; |
| 2774 |
<a name="NWCUvTi-RKDir-1-u11" href="#NWDCUvTi-12"><i><process <tt>drawRightAngle</tt> command></i></a> |
| 2775 |
} |
| 2776 |
elsif (s/^\s*(drawsquare(?=\W))//i) |
| 2777 |
{ |
| 2778 |
my ($cmd) = $1; |
| 2779 |
print OUT "%% $cmd$_" if $comments_on; |
| 2780 |
<a name="NWCUvTi-RKDir-1-u12" href="#NWDCUvTi-13"><i><process <tt>drawsquare</tt> command></i></a> |
| 2781 |
} |
| 2782 |
elsif (s/^\s*inputfile\*//i) |
| 2783 |
{ |
| 2784 |
<a name="NWCUvTi-RKDir-1-u13" href="#NWDCUvTi-14"><i><process <tt>inputfile*</tt> command></i></a> |
| 2785 |
} |
| 2786 |
elsif (s/^\s*(inputfile(?=\W))//i) |
| 2787 |
{ |
| 2788 |
my ($cmd) = $1; |
| 2789 |
print OUT "%% $cmd$_" if $comments_on; |
| 2790 |
<a name="NWCUvTi-RKDir-1-u14" href="#NWDCUvTi-15"><i><process <tt>inputfile</tt> command></i></a> |
| 2791 |
} |
| 2792 |
elsif (s/^\s*(linethickness(?=\W))//i) |
| 2793 |
{ |
| 2794 |
my $cmd = $1; |
| 2795 |
print OUT "%% $cmd$_" if $comments_on; |
| 2796 |
<a name="NWCUvTi-RKDir-1-u15" href="#NWDCUvTi-16"><i><process <tt>linethickness</tt> command></i></a> |
| 2797 |
} |
| 2798 |
elsif (s/^\s*(paper(?=\W))//i) |
| 2799 |
{ |
| 2800 |
my ($cmd) = $1; |
| 2801 |
print OUT "%% $cmd$_" if $comments_on; |
| 2802 |
<a name="NWCUvTi-RKDir-1-u16" href="#NWDCUvTi-17"><i><process <tt>paper</tt> command></i></a> |
| 2803 |
} |
| 2804 |
elsif (s/^\s*(PointSymbol(?=\W))//i) |
| 2805 |
{ |
| 2806 |
my $cmd = $1; |
| 2807 |
print OUT "%% $cmd$_" if $comments_on; |
| 2808 |
<a name="NWCUvTi-RKDir-1-u17" href="#NWDCUvTi-1X"><i><process <tt>PointSymbol</tt> command></i></a> |
| 2809 |
} |
| 2810 |
elsif (s/^\s*point(?=\W)//i) |
| 2811 |
{ |
| 2812 |
my ($Point_Line); |
| 2813 |
chomp($Point_Line=$_); |
| 2814 |
<a name="NWCUvTi-RKDir-1-u18" href="#NWDCUvTi-1I"><i><process <tt>point/point*</tt> commands></i></a> |
| 2815 |
} |
| 2816 |
elsif (/^\s*setPointNumber(?=\W)/i) |
| 2817 |
{ |
| 2818 |
PrintWarningMessage("Command setPointNumber is ignored",$lc); |
| 2819 |
next LINE; |
| 2820 |
} |
| 2821 |
elsif (s/^\s*(showAngle(?=\W))//i) |
| 2822 |
{ |
| 2823 |
<a name="NWCUvTi-RKDir-1-u19" href="#NWDCUvTi-1B"><i><process <tt>showAngle</tt> command></i></a> |
| 2824 |
} |
| 2825 |
elsif (s/^\s*(showArea(?=\W))//i) |
| 2826 |
{ |
| 2827 |
<a name="NWCUvTi-RKDir-1-u20" href="#NWDCUvTi-1C"><i><process <tt>showArea</tt> command></i></a> |
| 2828 |
} |
| 2829 |
elsif (s/^\s*(showLength(?=\W))//i) |
| 2830 |
{ |
| 2831 |
<a name="NWCUvTi-RKDir-1-u21" href="#NWDCUvTi-1D"><i><process <tt>showLength</tt> command></i></a> |
| 2832 |
} |
| 2833 |
elsif (/^\s*showPoints(?=\W)/i) |
| 2834 |
{ |
| 2835 |
print OUT "%%-------------------------------------------------\n"; |
| 2836 |
print OUT "%% L I S T O F P O I N T S \n"; |
| 2837 |
print OUT "%%-------------------------------------------------\n"; |
| 2838 |
foreach my $p (keys(%PointTable)) { |
| 2839 |
my ($x, $y, $pSV, $pS) = unpack("d3A*",$PointTable{$p}); |
| 2840 |
printf OUT "%%%%\t%s\t= ( %.5f, %.5f ), LF-radius = %.5f, symbol = %s\n", |
| 2841 |
$p, $x, $y, $pSV, $pS; |
| 2842 |
} |
| 2843 |
print OUT "%%-------------------------------------------------\n"; |
| 2844 |
print OUT "%% E N D O F L I S T O F P O I N T S \n"; |
| 2845 |
print OUT "%%-------------------------------------------------\n"; |
| 2846 |
next LINE; |
| 2847 |
} |
| 2848 |
elsif (/^\s*showVariables(?=\W)/i) |
| 2849 |
{ |
| 2850 |
print OUT "%%-------------------------------------------------\n"; |
| 2851 |
print OUT "%% L I S T O F V A R I A B L E S \n"; |
| 2852 |
print OUT "%%-------------------------------------------------\n"; |
| 2853 |
foreach my $var (keys(%VarTable)) { |
| 2854 |
print OUT "%%\t", $var, "\t=\t", $VarTable{$var}, "\n"; |
| 2855 |
} |
| 2856 |
print OUT "%%-------------------------------------------------\n"; |
| 2857 |
print OUT "%% E N D O F L I S T O F V A R I A B L E S \n"; |
| 2858 |
print OUT "%%-------------------------------------------------\n"; |
| 2859 |
next LINE; |
| 2860 |
} |
| 2861 |
elsif (s/^\s*(system(?=\W))//i) |
| 2862 |
{ |
| 2863 |
print OUT "%% $1$_" if $comments_on; |
| 2864 |
<a name="NWCUvTi-RKDir-1-u22" href="#NWDCUvTi-1Y"><i><process <tt>system</tt> command></i></a> |
| 2865 |
} |
| 2866 |
elsif (s/^\s*(text(?=\W))//i) |
| 2867 |
{ |
| 2868 |
print OUT "%% $1$_" if $comments_on; |
| 2869 |
<a name="NWCUvTi-RKDir-1-u23" href="#NWDCUvTi-1Z"><i><process <tt>text</tt> command></i></a> |
| 2870 |
} |
| 2871 |
elsif (s/^\s*(var(?=\W))//i) |
| 2872 |
{ |
| 2873 |
print OUT "%% $1$_" if $comments_on; |
| 2874 |
<a name="NWCUvTi-RKDir-1-u24" href="#NWDCUvTi-1d"><i><process <tt>var</tt> command></i></a> |
| 2875 |
} |
| 2876 |
elsif (/^\s*\\(.+)/) |
| 2877 |
{ |
| 2878 |
my $line = $1; |
| 2879 |
if ($line =~ /^\s+(.+)/) |
| 2880 |
{ |
| 2881 |
print OUT " $line\n"; |
| 2882 |
} |
| 2883 |
else |
| 2884 |
{ |
| 2885 |
print OUT "\\$line\n"; |
| 2886 |
} |
| 2887 |
next LINE; |
| 2888 |
} |
| 2889 |
elsif (0==length) #empty line |
| 2890 |
{ |
| 2891 |
next LINE; |
| 2892 |
} |
| 2893 |
else { |
| 2894 |
PrintErrorMessage("command not recognized",$lc); |
| 2895 |
next LINE; |
| 2896 |
} |
| 2897 |
|
| 2898 |
</pre><p>Command <code>dasharray</code> takes an arbitrary number of arguments that are used to |
| 2899 |
specify a dash pattern. Its general syntax follows: |
| 2900 |
<center> |
| 2901 |
<tt> "dasharray" "(" d<sub>1</sub> "," g<sub>1</sub> "," d<sub>2</sub> "," |
| 2902 |
g<sub>2</sub> "," ... ")"</tt> |
| 2903 |
</center> |
| 2904 |
where <tt>d<sub>i</sub></tt> denotes the length of a dash and <tt>g<sub>i</sub></tt> |
| 2905 |
<a name="NWDCUvTi-s">denotes the length of gap between two consecutive dashes. Each </a><tt>d<sub>i</sub></tt> |
| 2906 |
and <tt>g<sub>i</sub></tt> is a length (i.e., a number accompanied by a length of unit). |
| 2907 |
Since we do not a priori know the number of arguments, we push them onto a stack and |
| 2908 |
then we produce a command of the form |
| 2909 |
<center> |
| 2910 |
<tt> \setdashpattern < d<sub>1</sub>, g<sub>1</sub>, d<sub>2</sub>, |
| 2911 |
g<sub>2</sub>, ...></tt> |
| 2912 |
</center> |
| 2913 |
|
| 2914 |
<pre><a name="NWCUvTi-19jqyn-1" href="#NWDCUvTi-s"><dfn><process <tt>dasharray</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 2915 |
chk_lparen($cmd,$lc); |
| 2916 |
my @DashArray = (); |
| 2917 |
my $dash = ""; |
| 2918 |
my $dashpattern = ""; |
| 2919 |
PATTERN: while (1) { |
| 2920 |
$dash = sprintf("%.5f", expr($lc)); |
| 2921 |
if (s/^\s*($units)//i) { |
| 2922 |
push (@DashArray, "$dash$1"); |
| 2923 |
} |
| 2924 |
else { |
| 2925 |
PrintErrorMessage("Did not found unit after expression", $lc); |
| 2926 |
} |
| 2927 |
s/\s*//; |
| 2928 |
if (/^[^,]/) { |
| 2929 |
last PATTERN; |
| 2930 |
} |
| 2931 |
else { |
| 2932 |
s/^,\s*//; |
| 2933 |
} |
| 2934 |
} |
| 2935 |
print OUT "\\setdashpattern <"; |
| 2936 |
while (@DashArray) { |
| 2937 |
$dashpattern .= shift @DashArray; |
| 2938 |
$dashpattern .= ","; |
| 2939 |
} |
| 2940 |
$dashpattern =~ s/,$//; |
| 2941 |
print OUT $dashpattern, ">\n"; |
| 2942 |
chk_rparen("arguments of $cmd",$lc); |
| 2943 |
chk_comment($lc); |
| 2944 |
|
| 2945 |
</pre><p>The command <code>drawAngleArc</code> draws an arc in the specified angle, a |
| 2946 |
distance <i>radius</i> from the angle. The angle is either <i>internal</i> |
| 2947 |
(<= 180 degrees) or <i>external</i> (>180 degrees). The direction of the |
| 2948 |
arc is either <i>clockwise</i> or <i>anticlockwise</i>. The command |
| 2949 |
<code>drawAngleArrow</code> draws an arrow just like the command <code>drawAngleArc</code> |
| 2950 |
draws an arc. The syntax of these commands is as follows: |
| 2951 |
<pre> |
| 2952 |
cmds ::= ( "drawAngleArc" | "drawAngleArrow" ) args |
| 2953 |
args ::= "{" angle comma radius comma internal comma clockwise "}" |
| 2954 |
angle ::= "angle" "(" three-points ")" |
| 2955 |
radius ::= "radius" "(" distance ")" |
| 2956 |
distance ::= expression |
| 2957 |
internal ::= "internal" | "external" |
| 2958 |
clockwise ::= "clockwise" | "anticlockwise" |
| 2959 |
comma ::= "," | empty |
| 2960 |
</pre> |
| 2961 |
We first collect all relevant information by parsing the <code>args</code> and then |
| 2962 |
call the either the subroutine <code>drawAngleArc</code> or the subroutine |
| 2963 |
<code>drawAngleArrow</code> to produce the actual code |
| 2964 |
which is then printed into the output file. In order to be able to distinguish |
| 2965 |
which command we are dealing with we simply use the variable <code>$cmd</code>. |
| 2966 |
<a name="NWDCUvTi-t">We now start parsing the input line. We first check whether there is a</a> |
| 2967 |
left curly bracket. Next, we parse the <code>angle</code>, the <code>distance</code>, the |
| 2968 |
<code>internal</code> and the <code>clockwise</code> parts of the command. Finally, we check |
| 2969 |
for right curly bracket and a trailing comment. Depending on |
| 2970 |
the value of |
| 2971 |
the variable <code>$cmd</code> we call either the subroutine <code>drawAngleArc</code> or the |
| 2972 |
subroutine <code>drawAngleArrow</code>. These subroutines return the code that will be |
| 2973 |
finally output to the output file. |
| 2974 |
|
| 2975 |
<pre><a name="NWCUvTi-12lwO-1" href="#NWDCUvTi-t"><dfn><process <tt>drawAngleArcOrArrow</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 2976 |
|
| 2977 |
chk_lcb($cmd,$lc); |
| 2978 |
<a name="NWCUvTi-12lwO-1-u1" href="#NWDCUvTi-u"><i><process <tt>angle</tt> part of command></i></a> |
| 2979 |
s/^,\s*// or s/\s*//; #parse optional comma |
| 2980 |
<a name="NWCUvTi-12lwO-1-u2" href="#NWDCUvTi-v"><i><process <tt>radius</tt> part of command></i></a> |
| 2981 |
s/^,\s*// or s/\s*//; #parse optional comma |
| 2982 |
my $inout = ""; |
| 2983 |
if (s/^(internal(?=\W))//i or s/^(external(?=\W))//i) { |
| 2984 |
$inout = $1; |
| 2985 |
} |
| 2986 |
else { |
| 2987 |
PrintErrorMessage("Did not find expected 'internal' specifier", $lc); |
| 2988 |
next LINE; |
| 2989 |
} |
| 2990 |
s/^,\s*// or s/\s*//; #parse optional comma |
| 2991 |
my $direction = ""; |
| 2992 |
if (s/^(clockwise(?=\W))//i or s/^(anticlockwise(?=\W))//i) { |
| 2993 |
$direction = $1; |
| 2994 |
} |
| 2995 |
else { |
| 2996 |
PrintErrorMessage("Did not find expected 'direction' specifier", $lc); |
| 2997 |
next LINE; |
| 2998 |
} |
| 2999 |
chk_rcb("arguments of $cmd",$lc); |
| 3000 |
chk_comment($lc); |
| 3001 |
my $code; |
| 3002 |
if (lc($cmd) eq "drawanglearc") { |
| 3003 |
$code = drawAngleArc($P1, $P2, $P3, $radius, $inout, $direction); |
| 3004 |
} |
| 3005 |
else { |
| 3006 |
$code = drawAngleArrow($P1, $P2, $P3, $radius, $inout, $direction); |
| 3007 |
} |
| 3008 |
print OUT $code if $code ne ""; |
| 3009 |
|
| 3010 |
</pre><p><a name="NWDCUvTi-u">We first check whether the first token is the word </a><code>angle</code>. In case it |
| 3011 |
isn't, this yields an unrecoverable error. In case the expected word is |
| 3012 |
there, we check for a left parenthesis. Next, we parse the three points that |
| 3013 |
must follow. For this purpose we use the user-defined subroutine |
| 3014 |
<code>get_point</code>. Now we check that the angle has a reasonable value, i.e., if |
| 3015 |
it is less than -400 or equal to zero, the value yields an unrecoverable error. |
| 3016 |
We finish by checking whether there is a right parenthesis. |
| 3017 |
|
| 3018 |
<pre><a name="NWCUvTi-4X9wPg-1" href="#NWDCUvTi-u"><dfn><process <tt>angle</tt> part of command>=</dfn></a> <b>(<a href="#NWDCUvTi-t"><-U</a>)</b> |
| 3019 |
my ($P1, $P2, $P3); |
| 3020 |
if (s/^angle(?=\W)//i) { |
| 3021 |
chk_lparen("token angle of command $cmd",$lc); |
| 3022 |
$P1 = get_point($lc); |
| 3023 |
next LINE if $P1 eq "_undef_"; |
| 3024 |
$P2 = get_point($lc); |
| 3025 |
next LINE if $P2 eq "_undef_"; |
| 3026 |
$P3 = get_point($lc); |
| 3027 |
next LINE if $P3 eq "_undef_"; |
| 3028 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$P1}); |
| 3029 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$P2}); |
| 3030 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$P3}); |
| 3031 |
my $Angle = Angle($x1, $y1, $x2, $y2, $x3, $y3); |
| 3032 |
if ($Angle <= 0) { |
| 3033 |
if ($Angle == 0) { |
| 3034 |
PrintErrorMessage("Angle is equal to zero",$lc); |
| 3035 |
next LINE; |
| 3036 |
} |
| 3037 |
elsif ($Angle < -400) { |
| 3038 |
PrintErrorMessage("Something is wrong with the points",$lc); |
| 3039 |
next LINE; |
| 3040 |
} |
| 3041 |
} |
| 3042 |
chk_rparen("angle part of command $cmd",$lc); |
| 3043 |
} |
| 3044 |
else { |
| 3045 |
PrintErrorMessage("Did not find expected angle part",$lc); |
| 3046 |
next LINE; |
| 3047 |
} |
| 3048 |
|
| 3049 |
</pre><p><a name="NWDCUvTi-v">In this section we parse the </a><code>radius</code> part of the <code>drawAngleArc</code> or the |
| 3050 |
<code>drawAngleArrow</code> command. We first check whether the next token is the word |
| 3051 |
<code>radius</code>. If it is not, then we continue with the next line. |
| 3052 |
|
| 3053 |
<pre><a name="NWCUvTi-2mAaDL-1" href="#NWDCUvTi-v"><dfn><process <tt>radius</tt> part of command>=</dfn></a> <b>(<a href="#NWDCUvTi-t"><-U</a>)</b> |
| 3054 |
|
| 3055 |
my $radius; |
| 3056 |
if (s/^radius(?=\W)//i) { |
| 3057 |
chk_lparen("token radius of command $cmd",$lc); |
| 3058 |
$radius = expr($lc); |
| 3059 |
chk_rparen("radius part of command $cmd",$lc); |
| 3060 |
} |
| 3061 |
else { |
| 3062 |
PrintErrorMessage("Did not found expected angle part",$lc); |
| 3063 |
next LINE; |
| 3064 |
} |
| 3065 |
|
| 3066 |
</pre><p>Command <code>drawcircle</code> accepts two arguments--a point name that is |
| 3067 |
used to specify the center of the circle and the radius of the circle. |
| 3068 |
The radius is simply an expression, whose value must be greater than zero. |
| 3069 |
Otherwise, we print an error message and continue with the next input line. |
| 3070 |
The general syntax of the command is as follows: |
| 3071 |
<pre> |
| 3072 |
"drawcircle" "(" point-name "," rad ")" |
| 3073 |
</pre> |
| 3074 |
The code we emit for a point with coordinates <code>x</code> and <code>y</code> and for radius |
| 3075 |
equal to <code>R</code> is: |
| 3076 |
<pre> |
| 3077 |
\circulararc 360 degrees from X y center at x y |
| 3078 |
</pre> |
| 3079 |
where <code>X = x+R</code>.<p> |
| 3080 |
<a name="NWDCUvTi-w">Initially, we check whether there is an opening left parenthesis. Next,</a> |
| 3081 |
we get the point name by using the subroutine <code>get_point</code> which |
| 3082 |
issues an error message if the point hasn't been defined. In this |
| 3083 |
case we stop processing the command, as there is absolutely no reason to |
| 3084 |
do otherwise. Next, we parse the comma and then the radius by using |
| 3085 |
the subroutine <code>ComputeDist</code>. If there is no problem, we emit the code |
| 3086 |
and finally we check for a closing right parenthesis and for |
| 3087 |
possible garbage that may follow the command. |
| 3088 |
|
| 3089 |
<pre><a name="NWCUvTi-EIAAh-1" href="#NWDCUvTi-w"><dfn><process <tt>drawcircle</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3090 |
chk_lparen("drawcircle",$lc); |
| 3091 |
my $Point = get_point($lc); |
| 3092 |
next LINE if $Point eq "_undef_"; |
| 3093 |
chk_comma($lc); |
| 3094 |
my $R = expr($lc); |
| 3095 |
if ($R <= 0) { |
| 3096 |
PrintErrorMessage("Radius must be greater than zero",$lc); |
| 3097 |
next LINE; |
| 3098 |
} |
| 3099 |
my ($x,$y,$pSV,$pS)=unpack("d3A*",$PointTable{lc($Point)}); |
| 3100 |
printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n", |
| 3101 |
$x+$R, $y, $x, $y; |
| 3102 |
chk_rparen("arguments of $cmd",$lc); |
| 3103 |
chk_comment($lc); |
| 3104 |
|
| 3105 |
</pre><p>Command <code>drawcircumcircle</code> is used to draw the circumcircle of triangle |
| 3106 |
specified by three points which are the arguments of the command. We start |
| 3107 |
by parsing the opening left parenthesis. Next, we get the three points |
| 3108 |
that define the triangle. We are now able to compute the center and |
| 3109 |
the radius of the circumcircle by calling the subroutine <code>circumCircleCenter</code>. |
| 3110 |
If the triangle area is equal to zero, then this subroutine will return |
| 3111 |
the array <code>(0,0,0)</code> to indicate this fact. |
| 3112 |
We now have all necessary information to draw the circumcircle. We use the |
| 3113 |
<a name="NWDCUvTi-x">following code to do the job:</a> |
| 3114 |
<pre> |
| 3115 |
\circulararc 360 degrees from X y center x y |
| 3116 |
</pre> |
| 3117 |
where <code>x</code> and <code>y</code> are the coordinates of the center, <code>R</code> its |
| 3118 |
radius and <code>X=x+R</code>. What is left is to check whether there is a |
| 3119 |
closing right parenthesis and any trailing garbage. |
| 3120 |
|
| 3121 |
|
| 3122 |
<pre><a name="NWCUvTi-1HqG4z-1" href="#NWDCUvTi-x"><dfn><process <tt>drawcircumcircle</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3123 |
chk_lparen("drawcircumcircle",$lc); |
| 3124 |
my $point1 = get_point($lc); |
| 3125 |
next LINE if $point1 eq "_undef_"; |
| 3126 |
my $point2 = get_point($lc); |
| 3127 |
next LINE if $point2 eq "_undef_"; |
| 3128 |
my $point3 = get_point($lc); |
| 3129 |
next LINE if $point3 eq "_undef_"; |
| 3130 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point1}); |
| 3131 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point2}); |
| 3132 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point3}); |
| 3133 |
my ($xc, $yc,$r) = circumCircleCenter($x1,$y1,$x2,$y2,$x3,$y3,$lc); |
| 3134 |
next LINE if $xc == 0 and $yc == 0 and $r == 0; |
| 3135 |
print OUT "%% circumcircle center = ($xc,$yc), radius = $r\n" if $comments_on; |
| 3136 |
printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n", |
| 3137 |
$xc+$r, $yc, $xc, $yc; |
| 3138 |
chk_rparen("arguments of $cmd",$lc); |
| 3139 |
chk_comment($lc); |
| 3140 |
|
| 3141 |
</pre><p>The syntax of the <code>drawexcircle</code> command is as follows: |
| 3142 |
<pre> |
| 3143 |
drawexcircle ::= "drawexcircle" "(" ThreePoints "," TwoPoints ")" |
| 3144 |
[ modifier ] |
| 3145 |
modifier ::= "[" expr "]" |
| 3146 |
|
| 3147 |
</pre> |
| 3148 |
The <code>modifier</code> is an expression that is used to modify the radius of the |
| 3149 |
excicle. We start by checking whether there is a left parenthesis. Then we |
| 3150 |
get names of the three points. In case any of the points is not defined |
| 3151 |
we issue an error message and continue with the next input line. Next, we |
| 3152 |
check whether there is a comma that separates the three points defining the |
| 3153 |
triangle from the two points defining a side of the triangle (variables |
| 3154 |
<code>$point1</code>, <code>$point2</code>, and <code>$point3</code>). Moreover, we must ensure that |
| 3155 |
the area of the area defined by these points is not equal to |
| 3156 |
zero. If it is we issue an error message and we continue with the next |
| 3157 |
input line. Now, we are ready to get the two |
| 3158 |
point names that define the side of the triangle (variables <code>$point3</code> and |
| 3159 |
<code>$point5</code>). At this point we must make sure that these points are different |
| 3160 |
points and that they are members of the list of points that define the triangle. |
| 3161 |
We make this check by calling the subroutine <code>memberOf</code>. Next, we check |
| 3162 |
whether there is a closing right parenthesis. We now compute the center |
| 3163 |
and the radius of the excircle by calling the subroutine <code>excircle</code>. The |
| 3164 |
coordinates of the center are stored in the variables <code>$xc</code> and <code>$yc</code>, |
| 3165 |
while the radius is stored in the variable <code>$r</code>. If the next |
| 3166 |
non-blank input character is a left square bracket, then we know the user has |
| 3167 |
specified the optional part. We use the subroutine <code>expr</code> to get the value of |
| 3168 |
the optional part. The value of the optional part is stored in the variable <code>$R</code>. |
| 3169 |
At this point we check whether the sum of the radius |
| 3170 |
plus the optional part is equal to zero and if it is we continue with the |
| 3171 |
next input line. Next, we check for a closing right square bracket. We are |
| 3172 |
<a name="NWDCUvTi-y">now ready to emit the source code. The first thing we must check is that</a> |
| 3173 |
the radius is not too big for PiCTeX, i.e., not greater than 500/2.845. |
| 3174 |
Then we print some informative text to the output file and of course the |
| 3175 |
actual code. We use the following code to do the job: |
| 3176 |
<pre> |
| 3177 |
\circulararc 360 degrees from (xc+R) yc center xc yc |
| 3178 |
</pre> |
| 3179 |
The last thing we check is whether there is some trailing garbage. |
| 3180 |
|
| 3181 |
<pre><a name="NWCUvTi-Wbuba-1" href="#NWDCUvTi-y"><dfn><process <tt>drawexcircle</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3182 |
chk_lparen("drawexcircle",$lc); |
| 3183 |
my $point1 = get_point($lc); |
| 3184 |
next LINE if $point1 eq "_undef_"; |
| 3185 |
my $point2 = get_point($lc); |
| 3186 |
next LINE if $point2 eq "_undef_"; |
| 3187 |
my $point3 = get_point($lc); |
| 3188 |
next LINE if $point3 eq "_undef_"; |
| 3189 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point1}); |
| 3190 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point2}); |
| 3191 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point3}); |
| 3192 |
if (triangleArea($x1, $y1, $x2, $y2, $x3, $y3) < 0.0001) { |
| 3193 |
PrintErrorMessage("Area of triangle is zero!",$lc); |
| 3194 |
next LINE; |
| 3195 |
} |
| 3196 |
chk_comma($lc); |
| 3197 |
my $point4 = get_point($lc); |
| 3198 |
if (!memberOf($point4, $point1, $point2, $point3)) { |
| 3199 |
PrintErrorMessage("Current point isn't a side point",$lc); |
| 3200 |
next LINE; |
| 3201 |
} |
| 3202 |
next LINE if $point4 eq "_undef_"; |
| 3203 |
my $point5 = get_point($lc); |
| 3204 |
next LINE if $point5 eq "_undef_"; |
| 3205 |
if (!memberOf($point5, $point1, $point2, $point3)) { |
| 3206 |
PrintErrorMessage("Current point isn't a side point",$lc); |
| 3207 |
next LINE; |
| 3208 |
} |
| 3209 |
if ($point4 eq $point5) { |
| 3210 |
PrintErrorMessage("Side points are identical",$lc); |
| 3211 |
next LINE; |
| 3212 |
} |
| 3213 |
chk_rparen("arguments of $cmd",$lc); |
| 3214 |
my ($xc, $yc, $r) = excircle($point1, $point2, $point3, |
| 3215 |
$point4, $point5); |
| 3216 |
my $R=$r; |
| 3217 |
if (s/^\s*\[\s*//) { |
| 3218 |
$R += expr($lc); |
| 3219 |
if ($R < 0.0001) { |
| 3220 |
PrintErrorMessage("Radius has become equal to zero!",$lc); |
| 3221 |
next LINE; |
| 3222 |
} |
| 3223 |
chk_rsb($lc); |
| 3224 |
} |
| 3225 |
if ($R > (500 / 2.845)) { |
| 3226 |
PrintErrorMessage("Radius is greater than 175mm!",$lc); |
| 3227 |
next LINE; |
| 3228 |
} |
| 3229 |
print OUT "%% excircle center = ($xc,$yc) radius = $R\n" if $comments_on; |
| 3230 |
printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n", |
| 3231 |
$xc+$R, $yc, $xc, $yc; |
| 3232 |
chk_comment($lc); |
| 3233 |
|
| 3234 |
</pre><p>The syntax of the <code>drawincircle</code> command is as follows: |
| 3235 |
<pre> |
| 3236 |
drawincircle ::= "drawincircle" "(" ThreePoints ")" [ modifier] |
| 3237 |
modifier ::= "[" expr "]" |
| 3238 |
</pre> |
| 3239 |
where <code>ThreePoints</code> correspond to the points defining the triangle and |
| 3240 |
<code>modifier</code> is an optional modification factor. |
| 3241 |
The first thing we do is to check whether |
| 3242 |
there is an opening left parenthesis. Then we get the names of the three |
| 3243 |
points that define the triangle (variables <code>$point1</code>, <code>$point2</code>, |
| 3244 |
and <code>$point3</code>). Next, we make sure that the area of the |
| 3245 |
triangle defined by these three points is not equal to zero. If it is, then |
| 3246 |
we issue an error message and continue with the next input line. Now, we |
| 3247 |
compute the center and the radius of the incircle (variables <code>$xc</code>, <code>$yc</code>, |
| 3248 |
and <code>$r</code>). If the next non-blank input character is a left square bracket, |
| 3249 |
then we now the user has specified the optional part. We use subroutine |
| 3250 |
<code>expr</code> to get the value of the optional part. The value of |
| 3251 |
the optional part |
| 3252 |
is stored in the variable <code>$R</code>. At this point we check whether the sum of the |
| 3253 |
radius plus the optional part is equal to zero and if it is we continue with |
| 3254 |
the next input line. Next, we check for a closing right square bracket. |
| 3255 |
<a name="NWDCUvTi-z">We are now ready to emit the source code. The first thing we must check is</a> |
| 3256 |
that the radius is not too big for PiCTeX, i.e., not greater than 500/2.845. |
| 3257 |
Then we print some informative text to the output file and of course the |
| 3258 |
actual code. We use the following code to do the job: |
| 3259 |
<pre> |
| 3260 |
\circulararc 360 degrees from (xc+R) yc center xc yc |
| 3261 |
</pre> |
| 3262 |
The last thing we check is whether there is some trailing garbage. |
| 3263 |
|
| 3264 |
<pre><a name="NWCUvTi-3GJ2p7-1" href="#NWDCUvTi-z"><dfn><process <tt>drawincircle</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3265 |
chk_lparen("drawincircle",$lc); |
| 3266 |
my $point1 = get_point($lc); |
| 3267 |
next LINE if $point1 eq "_undef_"; |
| 3268 |
my $point2 = get_point($lc); |
| 3269 |
next LINE if $point2 eq "_undef_"; |
| 3270 |
my $point3 = get_point($lc); |
| 3271 |
next LINE if $point3 eq "_undef_"; |
| 3272 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point1}); |
| 3273 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point2}); |
| 3274 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point3}); |
| 3275 |
if (triangleArea($x1, $y1, $x2, $y2, $x3, $y3) < 0.0001) { |
| 3276 |
PrintErrorMessage("Area of triangle is zero!",$lc); |
| 3277 |
next LINE; |
| 3278 |
} |
| 3279 |
my ($xc, $yc, $r) = IncircleCenter($x1,$y1,$x2,$y2,$x3,$y3); |
| 3280 |
my $R=$r; |
| 3281 |
if (s/^\s*\[\s*//) { |
| 3282 |
$R += expr($lc); |
| 3283 |
if ($R < 0.0001) { |
| 3284 |
PrintErrorMessage("Radius has become equal to zero!",$lc); |
| 3285 |
next LINE; |
| 3286 |
} |
| 3287 |
chk_rsb($lc); |
| 3288 |
} |
| 3289 |
if ($R > (500 / 2.845)) { |
| 3290 |
PrintErrorMessage("Radius is greater than 175mm!",$lc); |
| 3291 |
next LINE; |
| 3292 |
} |
| 3293 |
print OUT "%% incircle center = ($xc,$yc) radius = $R\n" if $comments_on; |
| 3294 |
printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n", |
| 3295 |
$xc+$R, $yc, $xc, $yc; |
| 3296 |
chk_rparen("arguments of $cmd",$lc); |
| 3297 |
chk_comment($lc); |
| 3298 |
|
| 3299 |
</pre><p>The command <code>drawPerpendicular</code> command draws a line from point A to line |
| 3300 |
BC, such that it is perpendicular to line BC. The general syntax of the |
| 3301 |
command is as follows: |
| 3302 |
<pre> |
| 3303 |
drawPenpedicular ::= "drawPenpedicular" "(" Point "," TwoPoints ")" |
| 3304 |
</pre> |
| 3305 |
The first thing we do is to parse the left parenthesis. Then we parse |
| 3306 |
the name of the first point, namely <code>$A$</code>. If this point is undefined |
| 3307 |
we print an error message and continue with the next line. Next, we parse |
| 3308 |
the expected leading comma and the names of the other two points. Certainly, |
| 3309 |
in case either of these two points has not been defined, we simply print an |
| 3310 |
error message and continue with the next input line. Finally, we check for |
| 3311 |
a closing right parenthesis and a possible trailing comment. Now we are |
| 3312 |
ready to compute the coordinates of the foot of the |
| 3313 |
perpendicular line. We do so my calling subroutine |
| 3314 |
<code><a name="NWDCUvTi-10">perpendicular</a></code>. Certainly, before we do this we have to get the |
| 3315 |
coordinates of the points that we have parsed. Finally, we output the |
| 3316 |
PiCTeX code: |
| 3317 |
<pre> |
| 3318 |
\plot x1 y1 xF xY / |
| 3319 |
</pre> |
| 3320 |
where <code>x1</code> and <code>y1</code> are coordinates of the point A and <code>xF</code> and <code>yF</code> |
| 3321 |
the coordinates of the foot. |
| 3322 |
|
| 3323 |
<pre><a name="NWCUvTi-4OiWfi-1" href="#NWDCUvTi-10"><dfn><process <tt>drawPerpendicular</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3324 |
|
| 3325 |
chk_lparen($cmd,$lc); |
| 3326 |
my $A = get_point($lc); |
| 3327 |
next LINE if $A eq "_undef_"; |
| 3328 |
chk_comma($lc); |
| 3329 |
my $B = get_point($lc); |
| 3330 |
next LINE if $A eq "_undef_"; |
| 3331 |
s/\s*//; #ignore white space |
| 3332 |
my $C = get_point($lc); |
| 3333 |
next LINE if $A eq "_undef_"; |
| 3334 |
chk_rparen("arguments of $cmd",$lc); |
| 3335 |
chk_comment($lc); |
| 3336 |
# |
| 3337 |
#start actual computation |
| 3338 |
# |
| 3339 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$A}); |
| 3340 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$B}); |
| 3341 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$C}); |
| 3342 |
my ($xF, $yF) = perpendicular($x1, $y1, $x2, $y2, $x3, $y3); |
| 3343 |
printf OUT "\\plot %.5f %.5f %.5f %.5f /\n", |
| 3344 |
$x1, $y1, $xF, $yF; |
| 3345 |
|
| 3346 |
</pre><p>The <code>drawpoint</code> command has a number of points as arguments and produces |
| 3347 |
PiCTeX code that draws a plot symbol at the coordinates of each point. The |
| 3348 |
syntax of the command is as follows: |
| 3349 |
<pre> |
| 3350 |
drawpoint ::= "drawpoint" "(" Point { separator Point } ")" |
| 3351 |
</pre> |
| 3352 |
The <code>while</code> loop is used to consume all points that are |
| 3353 |
<a name="NWDCUvTi-11">between an opening left parenthesis and a closing right parenthesis. All</a> |
| 3354 |
points are pushed on the local array <code>PP</code>. When we have parsed the lists |
| 3355 |
of points, we call the subroutine <code>drawpoints</code> to emit the actual PiCTeX code. |
| 3356 |
Finally, we check whether there is a closing parenthesis |
| 3357 |
parenthesis, and whether |
| 3358 |
there is some trailing text that makes no sense. In case there are no points |
| 3359 |
between the parentheses, then we issue an appropriate error message and |
| 3360 |
we continue with the next input line. |
| 3361 |
|
| 3362 |
<pre><a name="NWCUvTi-2EC5Ei-1" href="#NWDCUvTi-11"><dfn><process <tt>drawpoint</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3363 |
my ($stacklen); |
| 3364 |
chk_lparen("$cmd",$lc); |
| 3365 |
if (/^\)/) { |
| 3366 |
PrintErrorMessage("There are no point to draw",$lc); |
| 3367 |
next LINE; |
| 3368 |
} |
| 3369 |
my(@PP); |
| 3370 |
DRAWPOINTS:while(1) { |
| 3371 |
if (s/^([^\W\d_]\d{0,4})//i) { #point name |
| 3372 |
$P = $1; |
| 3373 |
if (!exists($PointTable{lc($P)})) { |
| 3374 |
PrintErrorMessage("Undefined point $P",$lc); |
| 3375 |
next DRAWPOINTS; |
| 3376 |
} |
| 3377 |
else { |
| 3378 |
push (@PP,$P); |
| 3379 |
s/\s*//; |
| 3380 |
} |
| 3381 |
} |
| 3382 |
else { |
| 3383 |
last DRAWPOINTS; |
| 3384 |
} |
| 3385 |
} |
| 3386 |
drawpoints(@PP); |
| 3387 |
chk_rparen("arguments of $cmd",$lc); |
| 3388 |
chk_comment($lc); |
| 3389 |
|
| 3390 |
</pre><p>The syntax of the <code>drawRightAngle</code> command is as follows: |
| 3391 |
<pre> |
| 3392 |
drawRightAngle "(" ThreePoints "," dist ")" |
| 3393 |
dist ::= expr | TwoPoints |
| 3394 |
</pre> |
| 3395 |
Before we proceed with the actual computation we parse the left parenthesis, |
| 3396 |
the three points, the comma, the <code>dist</code>, and the right parenthesis. In case |
| 3397 |
we have neither three points nor a <code>dist</code> we print an error message and |
| 3398 |
continue with the next input line, i.e., these errors are irrecoverable. |
| 3399 |
The names of the three points are stored in variables <code>$point1</code>, |
| 3400 |
<code>$point2</code>, and <code>$point3</code>. The value of the distance is stored |
| 3401 |
in the variable <code>$dist</code>. |
| 3402 |
Let's now explain the semantics of this command.<p> |
| 3403 |
|
| 3404 |
Our aim is to draw lines S<sub>1</sub>-S, S<sub>2</sub>-S (S<sub>1</sub> |
| 3405 |
and S<sub>2</sub> are at distance d from B). All the relevant points are |
| 3406 |
depicted in the following figure: |
| 3407 |
<center> |
| 3408 |
<img src="fig1.jpg"> |
| 3409 |
</center> |
| 3410 |
Some notes are in order: |
| 3411 |
<ol> |
| 3412 |
<li> BS bisects angle ABC, and meets AC in Q, so start by determining point |
| 3413 |
Q, then determine S, and then S<sub>1</sub> and S<sub>2</sub>, and then |
| 3414 |
draw S<sub>1</sub>-S and S<sub>2</sub>-S.</li> |
| 3415 |
<li> Distance AQ is given by AC/(1+tan(BCA))</li> |
| 3416 |
<li> The coordinates of Q are computed using the subroutine <code>pointOnLine</code>.</li> |
| 3417 |
<li> Now we compute the coordinates of S on line BQ.</li> |
| 3418 |
<li> We compute the coordinates of S<sub>1</sub> and S<sub>2</sub> by using |
| 3419 |
The subroutine <code>pointOnLine</code>.</li> |
| 3420 |
</ol> |
| 3421 |
<a name="NWDCUvTi-12">In order to implement the above steps we first compute the length of the line</a> |
| 3422 |
AB. Note that A is <code>$point1</code>, etc. Next we compute the angle BAC. Now |
| 3423 |
we compute the distance AQ (variable <code>$line1</code>). The coordinates of point |
| 3424 |
Q are stored in variables <code>$xQ</code> and <code>$yQ</code>. The coordinates of point |
| 3425 |
S are stored in variables <code>$xS</code> and <code>$yS</code>. Now we have to determine the |
| 3426 |
coordinates of points S<sub>1</sub> and S<sub>2</sub>. These coordinates |
| 3427 |
are stored in variables <code>$xS1</code>, <code>$yS1</code> and <code>$xS2</code>, <code>$yS2</code>, |
| 3428 |
respectively. Finally, we emit the PiCTeX target code. |
| 3429 |
|
| 3430 |
<pre><a name="NWCUvTi-2KJKP6-1" href="#NWDCUvTi-12"><dfn><process <tt>drawRightAngle</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3431 |
|
| 3432 |
chk_lparen("drawRightAngle",$lc); |
| 3433 |
my $point1 = get_point($lc); |
| 3434 |
next LINE if $point1 eq "_undef_"; |
| 3435 |
my $point2 = get_point($lc); |
| 3436 |
next LINE if $point2 eq "_undef_"; |
| 3437 |
my $point3 = get_point($lc); |
| 3438 |
next LINE if $point3 eq "_undef_"; |
| 3439 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point1}); |
| 3440 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point2}); |
| 3441 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point3}); |
| 3442 |
chk_comma($lc); |
| 3443 |
my $dist = expr($lc); |
| 3444 |
chk_rparen("arguments of $cmd",$lc); |
| 3445 |
chk_comment($lc); |
| 3446 |
# |
| 3447 |
#actual computation |
| 3448 |
# |
| 3449 |
my ($Px, $Py) = pointOnLine($x2, $y2, $x1, $y1, $dist); |
| 3450 |
my ($Qx, $Qy) = pointOnLine($x2, $y2, $x3, $y3, $dist); |
| 3451 |
my ($Tx, $Ty) = midpoint($Px, $Py, $Qx, $Qy); |
| 3452 |
my ($Ux, $Uy) = pointOnLine($x2, $y2, $Tx, $Ty, 2*Length($x2, $y2, $Tx, $Ty)); |
| 3453 |
if ($Px == $Ux || $Py == $Uy) { |
| 3454 |
printf OUT "\\putrule from %.5f %.5f to %.5f %.5f \n", $Px,$Py,$Ux,$Uy; |
| 3455 |
} |
| 3456 |
else { |
| 3457 |
printf OUT "\\plot %.5f %.5f\t%.5f %.5f / \n", $Px, $Py,$Ux,$Uy; |
| 3458 |
} |
| 3459 |
if ($Ux == $Qx || $Uy == $Qy) { |
| 3460 |
printf OUT "\\putrule from %.5f %.5f to %.5f %.5f \n", $Ux,$Uy,$Qx,$Qy; |
| 3461 |
} |
| 3462 |
else { |
| 3463 |
printf OUT "\\plot %.5f %.5f\t%.5f %.5f / \n", $Ux, $Uy,$Qx,$Qy; |
| 3464 |
} |
| 3465 |
|
| 3466 |
|
| 3467 |
</pre><p><a name="NWDCUvTi-13">The command </a><code>drawsquare</code> has two arguments: a point, which specifies the |
| 3468 |
coordinates of the point where the square will be placed, and a number, which |
| 3469 |
specifies the length of the side of the square. The syntax of the command is as follows: |
| 3470 |
<center> |
| 3471 |
<tt> "drawSquare" "(" Point "," expression ")" </tt> |
| 3472 |
</center> |
| 3473 |
Note that RWDN has suggested to alter the value of the <code>$side</code> variable (see the |
| 3474 |
line with <code>RWDN</code> comment). |
| 3475 |
|
| 3476 |
<pre><a name="NWCUvTi-2lxjRF-1" href="#NWDCUvTi-13"><dfn><process <tt>drawsquare</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3477 |
chk_lparen("drawSquare",$lc); |
| 3478 |
my $p = get_point($lc); |
| 3479 |
chk_comma($lc); |
| 3480 |
my $side = expr($lc); |
| 3481 |
$side = $side - (1.1 * $LineThickness/$xunits); #Suggested by RWDN |
| 3482 |
my ($x,$y,$pSV,$pS) = unpack("d3A*",$PointTable{$p}); |
| 3483 |
printf OUT "\\put {%s} at %.5f %.5f %%drawsquare\n", drawsquare($side), $x, $y; |
| 3484 |
chk_rparen("arguments of $cmd",$lc); |
| 3485 |
chk_comment($lc); |
| 3486 |
|
| 3487 |
</pre><p>The argument of the <code>inputfile*</code> command is a file name that is always |
| 3488 |
enclosed in parentheses: |
| 3489 |
<pre> |
| 3490 |
starred-input-file ::= "inputfile*" "(" file-name ")" |
| 3491 |
file-name ::= (alpha | period) { alpha | period } |
| 3492 |
alpha ::= letter | digit | "_" | "-" |
| 3493 |
</pre> |
| 3494 |
<a name="NWDCUvTi-14">Note, that the input file is assumed to contain TeX code.</a> |
| 3495 |
We first check to see if there is a left parenthesis. Then we consume |
| 3496 |
the file name. We check if the file exists and then we copy verbatim the |
| 3497 |
input file to the output file. Next, we check for the closing parenthesis. |
| 3498 |
Now, if there is a trailing comment we copy it to the output file depending |
| 3499 |
on the value of the variable <code>$comments_on</code>, else if there is some other |
| 3500 |
text we simply ignore it and issue a warning message. |
| 3501 |
|
| 3502 |
<pre><a name="NWCUvTi-fJuCf-1" href="#NWDCUvTi-14"><dfn><process <tt>inputfile*</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3503 |
chk_lparen("inputfile*",$lc); |
| 3504 |
my $row_in = ""; |
| 3505 |
if (s/^((\w|-|\.)+)//) { |
| 3506 |
$row_in = $1; |
| 3507 |
} |
| 3508 |
else { |
| 3509 |
PrintErrorMessage("No input file name found",$lc); |
| 3510 |
next LINE; |
| 3511 |
} |
| 3512 |
if (!(-e $row_in)) { |
| 3513 |
PrintErrorMessage("File $row_in does not exist",$lc); |
| 3514 |
next LINE; |
| 3515 |
} |
| 3516 |
open(ROW, "$row_in")|| die "Can't open file $row_in\n"; |
| 3517 |
while (defined($in_line=<ROW>)) { print OUT $in_line; } |
| 3518 |
print OUT "%% ... end of input file <$row_in>\n"; |
| 3519 |
close ROW; |
| 3520 |
chk_rparen("input file name",$lc); |
| 3521 |
chk_comment($lc); |
| 3522 |
|
| 3523 |
|
| 3524 |
</pre><p>The <code>inputfile</code> command has at most two arguments, second being |
| 3525 |
optional: a file name enclosed in curly brackets and the number of |
| 3526 |
times this file should be included in square brackets: |
| 3527 |
<pre> |
| 3528 |
inputfile ::= "inputfile" "(" file-name ")" [ Times ] |
| 3529 |
<a name="NWDCUvTi-15">Times ::= "[" expr "]"</a> |
| 3530 |
</pre> |
| 3531 |
Note that the input file is assumed to contain mathspic commands. In addition, if |
| 3532 |
the expression is equal to a decimal number, it is truncated. |
| 3533 |
As in the case of the <code>inputfile*</code> command we parse the left parenthesis, |
| 3534 |
the file name, the right parenthesis and the optional argument if it exists. |
| 3535 |
In order to process the commands contained in the input file, we call |
| 3536 |
The subroutine <code>process_input</code>. |
| 3537 |
|
| 3538 |
<pre><a name="NWCUvTi-2EQO3c-1" href="#NWDCUvTi-15"><dfn><process <tt>inputfile</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3539 |
|
| 3540 |
chk_lparen("inputfile",$lc); |
| 3541 |
my $comm_in = ""; |
| 3542 |
if (s/^((\w|-|\.)+)//) { |
| 3543 |
$comm_in = $1; |
| 3544 |
} |
| 3545 |
else { |
| 3546 |
PrintErrorMessage("No input file name found",$lc); |
| 3547 |
next LINE; |
| 3548 |
} |
| 3549 |
if (!(-e $comm_in)) { |
| 3550 |
PrintErrorMessage("File $comm_in does not exist",$lc); |
| 3551 |
next LINE; |
| 3552 |
} |
| 3553 |
chk_rparen("input file name",$lc); |
| 3554 |
my $input_times = 1; #default value |
| 3555 |
if (s/^\[//) { |
| 3556 |
$input_times = expr($lc); |
| 3557 |
chk_rsb("optional argument",$lc); |
| 3558 |
} |
| 3559 |
print OUT "%% ... start of file <$comm_in> loop [$input_times]\n"; |
| 3560 |
for (my $i=0; $i<int($input_times); $i++) { |
| 3561 |
open(COMM,"$comm_in") or die "Can't open file $comm_in\n"; |
| 3562 |
print OUT "%%% Iteration number: ",$i+1,"\n"; |
| 3563 |
my $old_file_name = $curr_in_file; |
| 3564 |
process_input(COMM,"File $comm_in, "); |
| 3565 |
$curr_in_file = $old_file_name; |
| 3566 |
close COMM; |
| 3567 |
} |
| 3568 |
print OUT "%% ... end of file <$comm_in> loop [$input_times]\n"; |
| 3569 |
chk_comment($lc); |
| 3570 |
|
| 3571 |
</pre><p><a name="NWDCUvTi-16">The </a><code>linethickness</code> command should be used to set the thickness of lines. |
| 3572 |
The command has one argument, which is a length or the word <code>default</code>. |
| 3573 |
The default line thickness is 0.4 pt. |
| 3574 |
|
| 3575 |
<pre><a name="NWCUvTi-1t58ZF-1" href="#NWDCUvTi-16"><dfn><process <tt>linethickness</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3576 |
chk_lparen("linethickness", $lc); |
| 3577 |
if (s/^default//i) { |
| 3578 |
print OUT "\\linethickness=0.4pt\\Linethickness{0.4pt}%%\n"; |
| 3579 |
print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\tiny .})%\n"; |
| 3580 |
$LineThickness = setLineThickness($xunits,"0.4pt"); |
| 3581 |
} |
| 3582 |
else { |
| 3583 |
my $length = expr($lc); |
| 3584 |
if (s/^\s*($units)//i) { |
| 3585 |
my $units = $1; |
| 3586 |
printf OUT "\\linethickness=%.5f%s\\Linethickness{%.5f%s}%%\n", |
| 3587 |
$length, $units, $length, $units; |
| 3588 |
$LineThickness = setLineThickness($xunits,"$length$units"); |
| 3589 |
my $mag; |
| 3590 |
if ($units eq "pc") { |
| 3591 |
$mag = $length * 12; |
| 3592 |
} |
| 3593 |
elsif ($units eq "in") { |
| 3594 |
$mag = $length * 72.27; |
| 3595 |
} |
| 3596 |
elsif ($units eq "bp") { |
| 3597 |
$mag = $length * 1.00375; |
| 3598 |
} |
| 3599 |
elsif ($units eq "cm") { |
| 3600 |
$mag = $length * 28.45275; |
| 3601 |
} |
| 3602 |
elsif ($units eq "mm") { |
| 3603 |
$mag = $length * 2.845275; |
| 3604 |
} |
| 3605 |
elsif ($units eq "dd") { |
| 3606 |
$mag = $length * 1.07001; |
| 3607 |
} |
| 3608 |
elsif ($units eq "cc") { |
| 3609 |
$mag = $length * 0.08917; |
| 3610 |
} |
| 3611 |
elsif ($units eq "sp") { |
| 3612 |
$mag = $length * 0.000015259; |
| 3613 |
} |
| 3614 |
elsif ($units eq "pt") { |
| 3615 |
$mag = $length; |
| 3616 |
} |
| 3617 |
$mag = 10 * $mag / 1.00278219; |
| 3618 |
printf OUT "\\font\\CM=cmr10 at %.5fpt%%\n", $mag; |
| 3619 |
print OUT "\\setplotsymbol ({\\CM .})%\n"; |
| 3620 |
} |
| 3621 |
else { |
| 3622 |
PrintErrorMessage("Did not found expect units part",$lc); |
| 3623 |
} |
| 3624 |
} |
| 3625 |
chk_rparen("linethickness", $lc); |
| 3626 |
chk_comment($lc); |
| 3627 |
|
| 3628 |
|
| 3629 |
</pre><p>We first output the input line as a comment into the output file. Now, |
| 3630 |
after the <code>paper</code> token we look for an opening brace. Then we process |
| 3631 |
the <code>units</code> part of the command, if the token <code>units</code> is present. Note |
| 3632 |
that the <code>units</code> part is optional. Next we process the <code>xrange</code> and the |
| 3633 |
<code>yrange</code> part of the command, which are also optional parts of the command. |
| 3634 |
We are now ready to process the <code>axis</code> part. Note, that the user is allowed |
| 3635 |
to alternatively specify this part with the word <code>axes</code>. |
| 3636 |
<a name="NWDCUvTi-17">The variable </a><code>$axis</code> |
| 3637 |
is supposed to hold the various data relate to the <code>axis</code> part. The last |
| 3638 |
thing we check is the <code>ticks</code> part. In case the user has not specified |
| 3639 |
this part we assume that both ticks are equal to zero. If everything is |
| 3640 |
according to the language syntax, we expect a closing right curly bracket. |
| 3641 |
Now, that we have all relevant information we can output the rest of the code, |
| 3642 |
as some parts of it have already been output during parsing. The last thing we |
| 3643 |
do is to check whether there is any trailing comment. |
| 3644 |
|
| 3645 |
<pre><a name="NWCUvTi-1Pby5X-1" href="#NWDCUvTi-17"><dfn><process <tt>paper</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3646 |
chk_lcb("paper", $lc); |
| 3647 |
if (s/^units(?=\W)//i) |
| 3648 |
{ |
| 3649 |
<a name="NWCUvTi-1Pby5X-1-u1" href="#NWDCUvTi-18"><i><process <tt>unit</tt> part></i></a> |
| 3650 |
$nounits = 0; |
| 3651 |
} |
| 3652 |
else |
| 3653 |
{ |
| 3654 |
$nounits = 1; |
| 3655 |
} |
| 3656 |
s/^,\s*// or s/\s*//; |
| 3657 |
if (s/^xrange//i) |
| 3658 |
{ |
| 3659 |
<a name="NWCUvTi-1Pby5X-1-u2" href="#NWDCUvTi-19"><i><process <tt>xrange</tt> part></i></a> |
| 3660 |
$noxrange = 0; |
| 3661 |
} |
| 3662 |
else |
| 3663 |
{ |
| 3664 |
$noxrange = 1; |
| 3665 |
} |
| 3666 |
s/^,\s*// or s/\s*//; |
| 3667 |
if (s/^yrange//i) |
| 3668 |
{ |
| 3669 |
<a name="NWCUvTi-1Pby5X-1-u3" href="#NWDCUvTi-1A"><i><process <tt>yrange</tt> part></i></a> |
| 3670 |
$noyrange = 0; |
| 3671 |
} |
| 3672 |
else |
| 3673 |
{ |
| 3674 |
$noyrange = 1; |
| 3675 |
} |
| 3676 |
<a name="NWCUvTi-1Pby5X-1-u4" href="#NWDCUvTi-1E"><i><generate plot area related commands></i></a> |
| 3677 |
s/^,\s*// or s/\s*//; |
| 3678 |
$axis = ""; |
| 3679 |
if (s/^ax[ei]s(?=\W)//i) |
| 3680 |
{ |
| 3681 |
<a name="NWCUvTi-1Pby5X-1-u5" href="#NWDCUvTi-1F"><i><process <tt>axis</tt> part></i></a> |
| 3682 |
} |
| 3683 |
$axis = uc($axis); |
| 3684 |
s/^,\s*// or s/\s*//; |
| 3685 |
if (s/^ticks(?=\W)//i) |
| 3686 |
{ |
| 3687 |
<a name="NWCUvTi-1Pby5X-1-u6" href="#NWDCUvTi-1G"><i><process <tt>ticks</tt> part></i></a> |
| 3688 |
} |
| 3689 |
else |
| 3690 |
{ |
| 3691 |
$xticks = $yticks = 0; |
| 3692 |
} |
| 3693 |
chk_rcb("paper", $lc); |
| 3694 |
<a name="NWCUvTi-1Pby5X-1-u7" href="#NWDCUvTi-1H"><i><generate the rest of the code for the <tt>paper</tt> command></i></a> |
| 3695 |
chk_comment($lc); |
| 3696 |
|
| 3697 |
</pre><p><a name="NWDCUvTi-18">We first check whether there is a left parenthesis. Next, we check</a> |
| 3698 |
whether there is decimal number or a variable name. In case there isn't one we assume it |
| 3699 |
is the number 1. Now, we get the units. If there is no valid unit, we issue |
| 3700 |
an error and the x-unit is set to its default value. In case, there is |
| 3701 |
a trailing comma, we assume the user wants also to specify the y-unit and |
| 3702 |
we process this part just like we did with the x-unit part. Finally, we |
| 3703 |
output the corresponding PiCTeX command. In case there is no y-unit |
| 3704 |
we assume it is equal to the x-unit. |
| 3705 |
|
| 3706 |
<pre><a name="NWCUvTi-15UlOC-1" href="#NWDCUvTi-18"><dfn><process <tt>unit</tt> part>=</dfn></a> <b>(<a href="#NWDCUvTi-17"><-U</a>)</b> |
| 3707 |
|
| 3708 |
chk_lparen("units",$lc); |
| 3709 |
if(s/^\)//) |
| 3710 |
{ |
| 3711 |
PrintWarningMessage("Missing value in \"units\"--default is 1pt", |
| 3712 |
$lc); |
| 3713 |
$xunits = "1pt"; |
| 3714 |
} |
| 3715 |
else { |
| 3716 |
$xunits = expr($lc); |
| 3717 |
s/\s*//; |
| 3718 |
if (s/^($units)//i) { |
| 3719 |
$xunits .= "$1"; |
| 3720 |
$LineThickness = setLineThickness($xunits,"0.4pt"); |
| 3721 |
} |
| 3722 |
elsif(s/^(\w)+//i) { |
| 3723 |
PrintErrorMessage("$1 is not a valid mathspic unit",$lc); |
| 3724 |
$xunits = "1pt"; |
| 3725 |
} |
| 3726 |
else { |
| 3727 |
PrintErrorMessage("No x-units found",$lc); |
| 3728 |
$xunits = "1pt"; |
| 3729 |
} |
| 3730 |
s/\s*//; #ignore white space |
| 3731 |
if (s/^,//) { # there is a comma so expect an y-units |
| 3732 |
s/\s*//; #ignore white space |
| 3733 |
$yunits = expr($lc); |
| 3734 |
s/\s*//; #ignore white space |
| 3735 |
if (s/^($units)//i) { |
| 3736 |
$yunits .= "$1"; |
| 3737 |
} |
| 3738 |
elsif(s/^(\w)+//i) { |
| 3739 |
PrintErrorMessage("$1 is not a valid mathspic unit",$lc); |
| 3740 |
$yunits = "1pt"; |
| 3741 |
} |
| 3742 |
else { |
| 3743 |
PrintErrorMessage("No y-units found",$lc); |
| 3744 |
$yunits = $xunits; |
| 3745 |
} |
| 3746 |
} |
| 3747 |
else { |
| 3748 |
$yunits = $xunits; |
| 3749 |
} |
| 3750 |
chk_rparen("units",$lc); |
| 3751 |
} |
| 3752 |
|
| 3753 |
</pre><p><a name="NWDCUvTi-19">The </a><code>xrange</code> token must be followed by a left parenthesis, so we |
| 3754 |
check whether the next token is a left parenthesis. We store in the variables |
| 3755 |
<code>$xlow</code> and <code>$xhigh</code> the values of the range. The range is specified |
| 3756 |
as pair of decimal numbers/variable/pair of points, separated by a |
| 3757 |
comma. We use the subroutine <code>ComputeDist</code> to get the value of the lower |
| 3758 |
end and the upper end of the range. The last thing we check is whether |
| 3759 |
the lower end is less than the upper end. If this isn't the case we |
| 3760 |
issue an error message and we skip into the next input line. |
| 3761 |
|
| 3762 |
<pre><a name="NWCUvTi-39noUt-1" href="#NWDCUvTi-19"><dfn><process <tt>xrange</tt> part>=</dfn></a> <b>(<a href="#NWDCUvTi-17"><-U</a>)</b> |
| 3763 |
|
| 3764 |
chk_lparen("xrange",$lc); |
| 3765 |
my $ec; |
| 3766 |
($xlow,$ec) = ComputeDist($lc); |
| 3767 |
next LINE if $ec == 0; |
| 3768 |
chk_comma($lc); |
| 3769 |
($xhigh,$ec) = ComputeDist($lc); |
| 3770 |
next LINE if $ec == 0; |
| 3771 |
if ($xlow >= $xhigh) |
| 3772 |
{ |
| 3773 |
PrintErrorMessage("xlow >= xhigh in xrange",$lc); |
| 3774 |
next LINE; |
| 3775 |
} |
| 3776 |
chk_rparen("$xhigh",$lc); |
| 3777 |
|
| 3778 |
</pre><p><a name="NWDCUvTi-1A">The </a><code>yrange</code> token must be followed by a left parenthesis, so we |
| 3779 |
check whether the next token is a left parenthesis. We store in the variables |
| 3780 |
<code>$ylow</code> and <code>$yhigh</code> the values of the range. The range is specified |
| 3781 |
as pair of decimal numbers/variable/pair of points, separated by a |
| 3782 |
comma. We use the subroutine <code>ComputeDist</code> to get the value of the lower |
| 3783 |
end and the upper end of the range. The last thing we check is whether |
| 3784 |
the lower end is less than the upper end. If this isn't the case we |
| 3785 |
issue an error message and we skip into the next input line. |
| 3786 |
|
| 3787 |
<pre><a name="NWCUvTi-3SApmu-1" href="#NWDCUvTi-1A"><dfn><process <tt>yrange</tt> part>=</dfn></a> <b>(<a href="#NWDCUvTi-17"><-U</a>)</b> |
| 3788 |
|
| 3789 |
chk_lparen("yrange",$lc); |
| 3790 |
my $ec; |
| 3791 |
($ylow,$ec) = ComputeDist($lc); |
| 3792 |
next LINE if $ec == 0; |
| 3793 |
chk_comma($lc); |
| 3794 |
($yhigh,$ec) = ComputeDist($lc); |
| 3795 |
next LINE if $ec == 0; |
| 3796 |
if ($ylow >= $yhigh) |
| 3797 |
{ |
| 3798 |
PrintErrorMessage("ylow >= yhigh in yrange",$lc); |
| 3799 |
next LINE; |
| 3800 |
} |
| 3801 |
chk_rparen("$yhigh",$lc); |
| 3802 |
|
| 3803 |
</pre><p><a name="NWDCUvTi-1B">The </a><code>showAngle</code> command has three arguments that correspond to three distinct |
| 3804 |
points and emits a comment of the form: |
| 3805 |
<center> |
| 3806 |
<tt>%% angle(ABC) = 45</tt> |
| 3807 |
</center> |
| 3808 |
Note that the computed angle is expressed in degrees. |
| 3809 |
|
| 3810 |
<pre><a name="NWCUvTi-2ObcXb-1" href="#NWDCUvTi-1B"><dfn><process <tt>showAngle</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3811 |
chk_lparen("showangle",$lc); |
| 3812 |
my $point_1 = get_point($lc); |
| 3813 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1}); |
| 3814 |
my $point_2 = get_point($lc); |
| 3815 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2}); |
| 3816 |
my $point_3 = get_point($lc); |
| 3817 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3}); |
| 3818 |
my $angle = Angle($x1, $y1, $x2, $y2, $x3, $y3); |
| 3819 |
$angle = 0 if $angle == -500; |
| 3820 |
printf OUT "%%%% angle(%s%s%s) = %.5f deg ( %.5f rad)\n", $point_1, |
| 3821 |
$point_2, $point_3, $angle, $angle*D2R; |
| 3822 |
chk_rparen("Missing right parenthesis", $lc); |
| 3823 |
|
| 3824 |
</pre><p><a name="NWDCUvTi-1C">The </a><code>showArea</code> command has three arguments that correspond to three distinct |
| 3825 |
points and emits a comment of the form: |
| 3826 |
<center> |
| 3827 |
<tt>%% area(ABC) = 45</tt> |
| 3828 |
</center> |
| 3829 |
Note that the computed angle is expressed in degrees. |
| 3830 |
|
| 3831 |
<pre><a name="NWCUvTi-2THNRJ-1" href="#NWDCUvTi-1C"><dfn><process <tt>showArea</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3832 |
chk_lparen("showarea",$lc); |
| 3833 |
my $point_1 = get_point($lc); |
| 3834 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1}); |
| 3835 |
my $point_2 = get_point($lc); |
| 3836 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2}); |
| 3837 |
my $point_3 = get_point($lc); |
| 3838 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3}); |
| 3839 |
print OUT "%% area($point_1$point_2$point_3) = ", |
| 3840 |
triangleArea($x1, $y1, $x2, $y2, $x3, $y3), "\n"; |
| 3841 |
chk_rparen("Missing right parenthesis", $lc); |
| 3842 |
|
| 3843 |
</pre><p><a name="NWDCUvTi-1D">The </a><code>showLength</code> command has two arguments that correspond to two distinct |
| 3844 |
points and emits a comment of the form: |
| 3845 |
<center> |
| 3846 |
<tt>%% length(AB) = 45</tt> |
| 3847 |
</center> |
| 3848 |
Note that the computed angle is expressed in degrees. |
| 3849 |
|
| 3850 |
<pre><a name="NWCUvTi-Ofe1b-1" href="#NWDCUvTi-1D"><dfn><process <tt>showLength</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 3851 |
chk_lparen("showlength",$lc); |
| 3852 |
my $point_1 = get_point($lc); |
| 3853 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1}); |
| 3854 |
my $point_2 = get_point($lc); |
| 3855 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2}); |
| 3856 |
print OUT "%% length($point_1$point_2) = ", |
| 3857 |
Length($x1, $y1, $x2, $y2), "\n"; |
| 3858 |
chk_rparen("Missing right parenthesis", $lc); |
| 3859 |
|
| 3860 |
|
| 3861 |
</pre><p><a name="NWDCUvTi-1E">If the user hasn't specified units then we use the previous values to</a> |
| 3862 |
set the coordinate system. If the user hasn't specified either the |
| 3863 |
<code>xunits</code> part or the <code>yunits</code>, then we don't emit code. In case he/she |
| 3864 |
has specified both parts we generate the command that sets the plot area. |
| 3865 |
|
| 3866 |
<pre><a name="NWCUvTi-2SitZA-1" href="#NWDCUvTi-1E"><dfn><generate plot area related commands>=</dfn></a> <b>(<a href="#NWDCUvTi-17"><-U</a>)</b> |
| 3867 |
|
| 3868 |
if (!$nounits) |
| 3869 |
{ |
| 3870 |
printf OUT "\\setcoordinatesystem units <%s,%s>\n", |
| 3871 |
$xunits,$yunits; |
| 3872 |
} |
| 3873 |
if(!$noxrange && !$noyrange) |
| 3874 |
{ |
| 3875 |
printf OUT "\\setplotarea x from %.5f to %.5f, y from %.5f to %.5f\n", |
| 3876 |
$xlow, $xhigh, $ylow, $yhigh; |
| 3877 |
|
| 3878 |
} |
| 3879 |
|
| 3880 |
</pre><p>We first check to see whether there is an opening left parenthesis. Next |
| 3881 |
<a name="NWDCUvTi-1F">we get the various options the user may have entered. The valid options</a> |
| 3882 |
are the letters L, R, T, B, X, and Y. These letters may be followed by |
| 3883 |
an optional star <code>*</code> with space characters between the letter and the star. |
| 3884 |
We use a loop, that stops when a right parenthesis is found, to |
| 3885 |
go through all |
| 3886 |
possible arguments and append each argument in the string <code>$axis</code>. Note |
| 3887 |
one can have blank space between different arguments. The last thing we do is |
| 3888 |
to check for the closing right parenthesis. |
| 3889 |
|
| 3890 |
<pre><a name="NWCUvTi-19Hy2D-1" href="#NWDCUvTi-1F"><dfn><process <tt>axis</tt> part>=</dfn></a> <b>(<a href="#NWDCUvTi-17"><-U</a>)</b> |
| 3891 |
|
| 3892 |
chk_lparen("axis",$lc); |
| 3893 |
while(/^[^\)]/) |
| 3894 |
{ |
| 3895 |
if (s/^([lrtbxy]{1}\*?)//i) |
| 3896 |
{ |
| 3897 |
$axis .= $1; |
| 3898 |
} |
| 3899 |
elsif (s/^([^lrtbxy])//i) |
| 3900 |
{ |
| 3901 |
PrintErrorMessage("Non-valid character \"$1\" in axis()",$lc); |
| 3902 |
} |
| 3903 |
s/\s*//; |
| 3904 |
} |
| 3905 |
chk_rparen("axis(arguments",$lc); |
| 3906 |
|
| 3907 |
</pre><p>As usual we start by skipping white space. Next we check whether there is |
| 3908 |
<a name="NWDCUvTi-1G">an opening left parenthesis. Now, we expect two numbers/variables/pair of</a> |
| 3909 |
point representing the <code>ticks</code> increment value. These <code>ticks</code> increment |
| 3910 |
values must be separated by a comma (and possibly some white space around |
| 3911 |
them). We use the subroutine <code>ComputeDist</code> to get the value of the <code>ticks</code> |
| 3912 |
increment value and we assign to the variables <code>$xticks</code> and <code>$yticks</code> |
| 3913 |
the value of x-ticks and y-ticks increment value. In case there is a |
| 3914 |
problem we issue an error message and continue with the next line. The last |
| 3915 |
thing we check is whether there is a closing right parenthesis. |
| 3916 |
|
| 3917 |
<pre><a name="NWCUvTi-1isLLJ-1" href="#NWDCUvTi-1G"><dfn><process <tt>ticks</tt> part>=</dfn></a> <b>(<a href="#NWDCUvTi-17"><-U</a>)</b> |
| 3918 |
chk_lparen("ticks",$lc); |
| 3919 |
my $ec; |
| 3920 |
($xticks,$ec) = ComputeDist($lc); |
| 3921 |
next LINE if $ec == 0; |
| 3922 |
chk_comma($lc); |
| 3923 |
($yticks,$ec) = ComputeDist($lc); |
| 3924 |
next LINE if $ec == 0; |
| 3925 |
chk_rparen("ticks(arguments",$lc); |
| 3926 |
|
| 3927 |
</pre><p><a name="NWDCUvTi-1H">We actually emit code if the user has specified either the </a><code>X</code> or |
| 3928 |
<code>Y</code> option in the <code>axis</code> part. If the user has specified the |
| 3929 |
<code>Y*</code> or the <code>X*</code> option in the axis part, we just emit the commands |
| 3930 |
<code>\axis left shiftedto x=0</code> or <code>\axis bottom shiftedto y=0</code> respectively |
| 3931 |
and exit. If the use has specified ticks, then, depending on the options |
| 3932 |
he had supplied with the <code>axis</code> part, we emit code that |
| 3933 |
implements the user's wishes. |
| 3934 |
**** HERE WE MUST EXPLAIN THE MEANING OF THE CODE EMITTED!!! ***** |
| 3935 |
|
| 3936 |
<pre><a name="NWCUvTi-2gFm3I-1" href="#NWDCUvTi-1H"><dfn><generate the rest of the code for the <tt>paper</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-17"><-U</a>)</b> |
| 3937 |
YBRANCH: { |
| 3938 |
if (index($axis, "Y")>-1) |
| 3939 |
{ |
| 3940 |
if (index($axis, "Y*")>-1) |
| 3941 |
{ |
| 3942 |
print OUT "\\axis left shiftedto x=0 / \n"; |
| 3943 |
last YBRANCH; |
| 3944 |
} |
| 3945 |
if ($yticks > 0) |
| 3946 |
{ |
| 3947 |
if (index($axis, "T")>-1 && index($axis, "B")==-1) |
| 3948 |
{ |
| 3949 |
print OUT "\\axis left shiftedto x=0 ticks numbered from "; |
| 3950 |
print OUT "$ylow to -$yticks by $yticks\n from $yticks to "; |
| 3951 |
print OUT $yhigh-$yticks," by $yticks /\n"; |
| 3952 |
} |
| 3953 |
elsif (index($axis, "T")==-1 && index($axis, "B")>-1) |
| 3954 |
{ |
| 3955 |
print OUT "\\axis left shiftedto x=0 ticks numbered from "; |
| 3956 |
print OUT $ylow+$yticks," to -$yticks by $yticks\n from "; |
| 3957 |
print OUT "$yticks to $yhigh by $yticks /\n"; |
| 3958 |
} |
| 3959 |
elsif (index($axis, "T")>-1 && index($axis, "B")>-1) |
| 3960 |
{ |
| 3961 |
print OUT "\\axis left shiftedto x=0 ticks numbered from "; |
| 3962 |
print OUT $ylow+$yticks," to -$yticks by $yticks\n from "; |
| 3963 |
print OUT "$yticks to ",$yhigh-$yticks," by $yticks /\n"; |
| 3964 |
} |
| 3965 |
else |
| 3966 |
{ |
| 3967 |
print OUT "\\axis left shiftedto x=0 ticks numbered from "; |
| 3968 |
print OUT "$ylow to -$yticks by $yticks\n from "; |
| 3969 |
print OUT "$yticks to $yhigh by $yticks /\n"; |
| 3970 |
} |
| 3971 |
} |
| 3972 |
else |
| 3973 |
{ |
| 3974 |
print OUT "\\axis left shiftedto x=0 /\n"; |
| 3975 |
} |
| 3976 |
} |
| 3977 |
} |
| 3978 |
XBRANCH: { if (index($axis, "X")>-1) |
| 3979 |
{ |
| 3980 |
if (index($axis, "X*")>-1) |
| 3981 |
{ |
| 3982 |
print OUT "\\axis bottom shiftedto y=0 /\n"; |
| 3983 |
last XBRANCH; |
| 3984 |
} |
| 3985 |
if ($xticks > 0) |
| 3986 |
{ |
| 3987 |
if (index($axis, "L")>-1 && index($axis, "R")==1) |
| 3988 |
{ |
| 3989 |
print OUT "\\axis bottom shiftedto y=0 ticks numbered from "; |
| 3990 |
print OUT $xlow + $xticks," to -$xticks by $xticks\n from"; |
| 3991 |
print OUT " $xticks to $xhigh by $xticks /\n"; |
| 3992 |
} |
| 3993 |
elsif (index($axis, "L")==-1 && index($axis, "R")>-1) |
| 3994 |
{ |
| 3995 |
print OUT "\\axis bottom shiftedto y=0 ticks numbered from "; |
| 3996 |
print OUT "$xlow to -$xticks by $xticks\n from "; |
| 3997 |
print OUT "$xticks to ",$xhigh-$xticks," by $xticks /\n"; |
| 3998 |
} |
| 3999 |
elsif (index($axis, "L")>-1 && index($axis, "R")>-1) |
| 4000 |
{ |
| 4001 |
print OUT "\\axis bottom shiftedto y=0 ticks numbered from "; |
| 4002 |
print OUT $xlow + $xticks," to -$xticks by $xticks\n from "; |
| 4003 |
print OUT "$xticks to ",$xhigh - $xticks," by $xticks /\n"; |
| 4004 |
} |
| 4005 |
else |
| 4006 |
{ |
| 4007 |
print OUT "\\axis bottom shiftedto y=0 ticks numbered from "; |
| 4008 |
print OUT "$xlow to -$xticks by $xticks\n from "; |
| 4009 |
print OUT "$xticks to $xhigh by $xticks /\n"; |
| 4010 |
} |
| 4011 |
} |
| 4012 |
else |
| 4013 |
{ |
| 4014 |
print OUT "\\axis bottom shiftedto y=0 /\n"; |
| 4015 |
} |
| 4016 |
} } |
| 4017 |
LBRANCH: {if (index($axis, "L")>-1) |
| 4018 |
{ |
| 4019 |
if (index($axis, "L")>-1) |
| 4020 |
{ |
| 4021 |
if (index($axis, "L*")>-1) |
| 4022 |
{ |
| 4023 |
print OUT "\\axis left /\n"; |
| 4024 |
last LBRANCH; |
| 4025 |
} |
| 4026 |
if ($yticks > 0) |
| 4027 |
{ |
| 4028 |
print OUT "\\axis left ticks numbered from "; |
| 4029 |
print OUT "$ylow to $yhigh by $yticks /\n"; |
| 4030 |
} |
| 4031 |
else |
| 4032 |
{ |
| 4033 |
print OUT "\\axis left /\n"; |
| 4034 |
} |
| 4035 |
} |
| 4036 |
} } |
| 4037 |
RBRANCH: { if (index($axis, "R")>-1) |
| 4038 |
{ |
| 4039 |
if (index($axis, "R*")>-1) |
| 4040 |
{ |
| 4041 |
print OUT "\\axis right /\n"; |
| 4042 |
last RBRANCH; |
| 4043 |
} |
| 4044 |
if ($yticks > 0) |
| 4045 |
{ |
| 4046 |
print OUT "\\axis right ticks numbered from $ylow to $yhigh by "; |
| 4047 |
print OUT "$yticks /\n"; |
| 4048 |
} |
| 4049 |
else |
| 4050 |
{ |
| 4051 |
print OUT "\\axis right /\n"; |
| 4052 |
} |
| 4053 |
} } |
| 4054 |
TBRANCH: { if (index($axis, "T")>-1) |
| 4055 |
{ |
| 4056 |
if (index($axis, "T*")>-1) |
| 4057 |
{ |
| 4058 |
print OUT "\\axis top /\n"; |
| 4059 |
last TBRANCH; |
| 4060 |
} |
| 4061 |
if ($xticks > 0) |
| 4062 |
{ |
| 4063 |
print OUT "\\axis top ticks numbered from $xlow to $xhigh by "; |
| 4064 |
print OUT "$xticks /\n"; |
| 4065 |
} |
| 4066 |
else |
| 4067 |
{ |
| 4068 |
print OUT "\\axis top /\n"; |
| 4069 |
} |
| 4070 |
} } |
| 4071 |
BBRANCH: { if (index($axis, "B")>-1) |
| 4072 |
{ |
| 4073 |
if (index($axis, "B*")>-1) |
| 4074 |
{ |
| 4075 |
print OUT "\\axis bottom /\n"; |
| 4076 |
last BBRANCH; |
| 4077 |
} |
| 4078 |
if ($xticks > 0) |
| 4079 |
{ |
| 4080 |
print OUT "\\axis bottom ticks numbered from $xlow to $xhigh by "; |
| 4081 |
print OUT "$xticks /\n"; |
| 4082 |
} |
| 4083 |
else |
| 4084 |
{ |
| 4085 |
print OUT "\\axis bottom /\n"; |
| 4086 |
} |
| 4087 |
} } |
| 4088 |
|
| 4089 |
|
| 4090 |
</pre><p>The syntax of the <code>point</code> commands follows: |
| 4091 |
<pre> |
| 4092 |
point[*](PointName){Coordinates}[PointSymbol] |
| 4093 |
</pre> |
| 4094 |
where <code>PointName</code> is valid point name, <code>Coordinates</code> is either a |
| 4095 |
pair of numbers denoting the coordinates of the point or an expression |
| 4096 |
by means of which the system computes the coordinates of the point, and |
| 4097 |
the <code>PointSymbol</code> is a valid T<sub><font size=+1>E</font></sub>X |
| 4098 |
command denoting a point symbol. A valid point name consists of a |
| 4099 |
letter and at most two trailing digits. That is, the names <code>a11</code>, |
| 4100 |
<code>b2</code> and <code>c</code> are valid names while <code>qw</code> and <code>s123</code> are not. |
| 4101 |
The first thing we do is to set the point shape to the default symbol |
| 4102 |
(this has been initialized in the main program). Next, we check whether |
| 4103 |
we have a <code>point</code>command or a <code>point*</code> simply by inspecting the very |
| 4104 |
next token. Note that there must be no blank spaces between the token |
| 4105 |
<code>point</code> and the star symbol. Next, we get the point name: remember that |
| 4106 |
<a name="NWDCUvTi-1I">the point name is surrounded by parentheses. In case we don't find a valid</a> |
| 4107 |
point name we issue an error message and continue with the next line of |
| 4108 |
input. Suppose the point name was a valid one. If we have a <code>point*</code> |
| 4109 |
command we must ensure that the this particular point name has been defined. |
| 4110 |
If we have a <code>point</code> command we must ensure that this particular point |
| 4111 |
name has not been defined. Point names are stored in the hash <code>%PointTable</code>. |
| 4112 |
We are now ready to process the coordinates part and the optional |
| 4113 |
plot symbol part. |
| 4114 |
|
| 4115 |
<pre><a name="NWCUvTi-2bvYBY-1" href="#NWDCUvTi-1I"><dfn><process <tt>point/point*</tt> commands>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 4116 |
my ($pointStar, $PointName, $origPN); |
| 4117 |
$pointStar = 0; # default value: he have a point command |
| 4118 |
$pointStar = 1 if s/^\*//; |
| 4119 |
chk_lparen("point" . (($pointStar)?"*":""),$lc); |
| 4120 |
if (s/^([^\W\d_](?![^\W\d_])\d{0,4})//i) { |
| 4121 |
# |
| 4122 |
# Note: the regular expression (foo)(?!bar) means that we are |
| 4123 |
# looking a foo not followed by a bar. Moreover, the regular |
| 4124 |
# expression [^\W\d_] means that we are looking for letter. |
| 4125 |
# |
| 4126 |
$origPN = $1; |
| 4127 |
$PointName = lc($1); |
| 4128 |
} |
| 4129 |
else { |
| 4130 |
PrintErrorMessage("Invalid point name",$lc); |
| 4131 |
next LINE; |
| 4132 |
} |
| 4133 |
#if ($pointStar and !exists($PointTable{$PointName})) { |
| 4134 |
# PrintWarningMessage("Point $origPN has not been defined",$lc); |
| 4135 |
#} |
| 4136 |
if (!$pointStar and exists($PointTable{$PointName})) { |
| 4137 |
PrintWarningMessage("Point $origPN has been used already",$lc); |
| 4138 |
} |
| 4139 |
chk_rparen("point" . (($pointStar)?"*":""). "($origPN",$lc); |
| 4140 |
chk_lcb("point" . (($pointStar)?"*":""). "($origPN)",$lc); |
| 4141 |
my ($Px, $Py); |
| 4142 |
<a name="NWCUvTi-2bvYBY-1-u1" href="#NWDCUvTi-1J"><i><process coordinates></i></a> |
| 4143 |
chk_rcb("coordinates part",$lc); |
| 4144 |
my $sv = $defaultsymbol; |
| 4145 |
my $sh = $defaultLFradius; |
| 4146 |
my $side_or_radius = undef; |
| 4147 |
if (s/^\[\s*//) { # the user has opted to specify the optional part |
| 4148 |
<a name="NWCUvTi-2bvYBY-1-u2" href="#NWDCUvTi-1V"><i><process optional point shape part></i></a> |
| 4149 |
chk_rsb("optional part",$lc); |
| 4150 |
} |
| 4151 |
# to avoid truncation problems introduced by the pack function, we |
| 4152 |
# round each number up to five decimal digits |
| 4153 |
$Px = sprintf("%.5f", $Px); |
| 4154 |
$Py = sprintf("%.5f", $Py); |
| 4155 |
print OUT "%% point$Point_Line \t$origPN = ($Px, $Py)\n" if $comments_on; |
| 4156 |
chk_comment($lc); |
| 4157 |
$PointTable{$PointName} = pack("d3A*",$Px,$Py,$sh,$sv); |
| 4158 |
if (defined($side_or_radius)) { |
| 4159 |
$DimOfPoint{$PointName} = $side_or_radius; |
| 4160 |
} |
| 4161 |
|
| 4162 |
</pre><p>In this section we parse the <code>Coordinates</code> part of the <code>point</code> command. |
| 4163 |
The complete syntax of the <code>Coordinates</code> part follows: |
| 4164 |
<pre> |
| 4165 |
Coordinates ::= Variable | |
| 4166 |
Distance "," Distance | |
| 4167 |
"midpoint" "(" Point-Name Point-Name ")" | |
| 4168 |
"pointOnLine" "(" Two-Points "," Distance ")" | |
| 4169 |
"intersection" "(" Two-Points "," Two-Points ")" | |
| 4170 |
"perpendicular" "(" Point-Name "," Two-Points ")" | |
| 4171 |
"circumCircleCenter" "(" Three-Points ") | |
| 4172 |
"incircleCenter" "(" Three-Points ")" | |
| 4173 |
"excircleCenter" "(" Three-Points "," Two-Points ")" | |
| 4174 |
Point-Name [ "," Modifier ] |
| 4175 |
|
| 4176 |
Modifier ::= "shift" "(" Distance "," Distance ")" | |
| 4177 |
"polar" "(" Distance, Distance [ "deg" | "rad" ] ")" | |
| 4178 |
"rotate" "(" Point-Name, Distance [ "deg" | "rad" ] ")" | |
| 4179 |
"vector" "(" Two-Points ")" |
| 4180 |
|
| 4181 |
Distance ::= expression |
| 4182 |
|
| 4183 |
Two-Points ::= Point-Name Point-Name |
| 4184 |
|
| 4185 |
Three-Points ::= Point-Name Two-Points |
| 4186 |
</pre> |
| 4187 |
We now briefly explain the functionality of each option: |
| 4188 |
<ul> |
| 4189 |
<li>midpoint(AB): the midpoint between points A and B</li> |
| 4190 |
<li>pointOnLine(AB,d): point at distance d from A towards B</li> |
| 4191 |
<li>intersection(AB,CD): intersection of lines defined by AB and CD</li> |
| 4192 |
<li>perpendicular(A,BC): point of the foot of the perpendicular from A to line BC</li> |
| 4193 |
<li>circumCircleCenter(ABC): center of circumcircle of triangle ABC</li> |
| 4194 |
<li>incircleCenter(ABC):center of incircle of triangle ABC</li> |
| 4195 |
<li>excircleCenter(ABC,BC): center of excircle of triangle ABC, touching |
| 4196 |
side BC</li> |
| 4197 |
<li>A, shift(x,y): Point displaced from A by x and y along the X and Y |
| 4198 |
axes</li> |
| 4199 |
<li>A, polar(r,d): Point displaced from A by distance r in direction d</li> |
| 4200 |
<li>A, rotate(B,d): Rotate A about B by d</li> |
| 4201 |
</ul> |
| 4202 |
We now explain how the following piece of code operates. In case the first |
| 4203 |
token is a number, we assume that the coordinates are specified by a |
| 4204 |
number and another number, a variable or a pair of points. So, we check |
| 4205 |
whether there is a comma and use the subroutine <code>ComputeDist</code> to get the |
| 4206 |
second coordinate. In case the next token is one of the words |
| 4207 |
<code>perpendicular</code>, <code>intersection</code>, <code>midpoint</code>, <code>pointonline</code>, |
| 4208 |
<code>circumcircleCenter</code>, <code>IncircleCenter</code>, or <code>ExcircleCenter</code> |
| 4209 |
we consume the corresponding token and process the corresponding case. |
| 4210 |
In case the first two tokens are two identifiers, then we assume that we |
| 4211 |
have a pair of numbers. We compute their distance, check whether there is |
| 4212 |
a leading comma and compute the y-coordinate by calling subroutine |
| 4213 |
<code>ComputeDist</code>. In case the next token is a single identifier, we store |
| 4214 |
its name in the variable <code>$PointA</code>. If this identifier is a defined point name, |
| 4215 |
we check whether the next token is a comma. In case it is, we check whether |
| 4216 |
he token after the comma is either the token <code>shift</code>, <code>polar</code>, or |
| 4217 |
<code>rotate</code> and process each case accordingly. If it is |
| 4218 |
<a name="NWDCUvTi-1J">none of these tokens we issue an error message and continue with the next</a> |
| 4219 |
input line. Now, if the token after the identifier isn't a comma, we assume |
| 4220 |
that the coordinates of the point will be identical to those of the point |
| 4221 |
whose name has been stored in the variable <code>$PointA</code>. If the identifier is a |
| 4222 |
variable name, we assume that the x-coordinate is the value of this variable. |
| 4223 |
We check whether the next token is a comma, and compute the y-coordinate by |
| 4224 |
calling the subroutine <code>ComputeDist</code>. The x-coordinate is stored in the variable |
| 4225 |
<code>$Px</code> and the y-coordinate in the variable <code>$Py</code>. |
| 4226 |
|
| 4227 |
<pre><a name="NWCUvTi-3bnmlP-1" href="#NWDCUvTi-1J"><dfn><process coordinates>=</dfn></a> <b>(<a href="#NWDCUvTi-1I"><-U</a>)</b> |
| 4228 |
if (s/^perpendicular(?=\W)//i) { |
| 4229 |
<a name="NWCUvTi-3bnmlP-1-u1" href="#NWDCUvTi-1K"><i><process <tt>perpendicular</tt> case></i></a> |
| 4230 |
} |
| 4231 |
elsif (s/^intersection(?=\W)//i) { |
| 4232 |
<a name="NWCUvTi-3bnmlP-1-u2" href="#NWDCUvTi-1L"><i><process <tt>intersection</tt> case></i></a> |
| 4233 |
} |
| 4234 |
elsif (s/^midpoint(?=\W)//i) { |
| 4235 |
<a name="NWCUvTi-3bnmlP-1-u3" href="#NWDCUvTi-1M"><i><process <tt>midpoint</tt> case></i></a> |
| 4236 |
} |
| 4237 |
elsif (s/^pointonline(?=\W)//i) { |
| 4238 |
<a name="NWCUvTi-3bnmlP-1-u4" href="#NWDCUvTi-1N"><i><process <tt>pointonline</tt> case></i></a> |
| 4239 |
} |
| 4240 |
elsif (s/^circumcircleCenter(?=\W)//i) { |
| 4241 |
<a name="NWCUvTi-3bnmlP-1-u5" href="#NWDCUvTi-1O"><i><process <tt>circumcircleCenter</tt> case></i></a> |
| 4242 |
} |
| 4243 |
elsif (s/^IncircleCenter(?=\W)//i) { |
| 4244 |
<a name="NWCUvTi-3bnmlP-1-u6" href="#NWDCUvTi-1P"><i><process <tt>IncircleCenter</tt> case></i></a> |
| 4245 |
} |
| 4246 |
elsif (s/^ExcircleCenter(?=\W)//i) { |
| 4247 |
<a name="NWCUvTi-3bnmlP-1-u7" href="#NWDCUvTi-1Q"><i><process <tt>ExcircleCenter</tt> case></i></a> |
| 4248 |
} |
| 4249 |
elsif (/^[^\W\d_]\d{0,4}\s*[^,\w]/) { |
| 4250 |
m/^([^\W\d_]\d{0,4})\s*/i; |
| 4251 |
if (exists($PointTable{lc($1)})) { |
| 4252 |
my $Tcoord = get_point($lc); |
| 4253 |
my ($x,$y,$pSV,$pS)=unpack("d3A*",$PointTable{$Tcoord}); |
| 4254 |
$Px = $x; |
| 4255 |
$Py = $y; |
| 4256 |
} |
| 4257 |
else { |
| 4258 |
$Px = expr(); |
| 4259 |
chk_comma($lc); |
| 4260 |
$Py = expr(); |
| 4261 |
} |
| 4262 |
} |
| 4263 |
elsif (/[^\W\d_]\d{0,4}\s*,\s*shift|polar|rotate|vector/i) { #a point? |
| 4264 |
s/^([^\W\d_]\d{0,4})//i; |
| 4265 |
my $PointA = $1; |
| 4266 |
if (exists($PointTable{lc($PointA)})) { |
| 4267 |
s/\s*//; |
| 4268 |
if (s/^,//) { |
| 4269 |
s/\s*//; |
| 4270 |
if (s/^shift(?=\W)//i) { |
| 4271 |
<a name="NWCUvTi-3bnmlP-1-u8" href="#NWDCUvTi-1R"><i><process <tt>shift</tt> case></i></a> |
| 4272 |
} |
| 4273 |
elsif (s/^polar(?=\W)//i) { |
| 4274 |
<a name="NWCUvTi-3bnmlP-1-u9" href="#NWDCUvTi-1S"><i><process <tt>polar</tt> case></i></a> |
| 4275 |
} |
| 4276 |
elsif (s/^rotate(?=\W)//i) { |
| 4277 |
<a name="NWCUvTi-3bnmlP-1-u10" href="#NWDCUvTi-1T"><i><process <tt>rotate</tt> case></i></a> |
| 4278 |
} |
| 4279 |
elsif (s/^vector(?=\W)//i) { |
| 4280 |
<a name="NWCUvTi-3bnmlP-1-u11" href="#NWDCUvTi-1U"><i><process <tt>vector</tt> case></i></a> |
| 4281 |
} |
| 4282 |
else { |
| 4283 |
PrintErrorMessage("unexpected token",$lc); |
| 4284 |
next LINE; |
| 4285 |
} |
| 4286 |
} |
| 4287 |
else { |
| 4288 |
my ($xA,$yA,$pSVA,$pSA)=unpack("d3A*",$PointTable{lc($PointA)}); |
| 4289 |
$Px = $xA; |
| 4290 |
$Py = $yA; |
| 4291 |
} |
| 4292 |
} |
| 4293 |
else { |
| 4294 |
PrintErrorMessage("Undefined point $PointA",$lc); |
| 4295 |
next LINE; |
| 4296 |
} |
| 4297 |
} |
| 4298 |
else { |
| 4299 |
$Px = expr(); |
| 4300 |
chk_comma($lc); |
| 4301 |
$Py = expr(); |
| 4302 |
} |
| 4303 |
|
| 4304 |
</pre><p>In the following piece of code we process the <code>perpendicular</code> |
| 4305 |
case of the <code>point</code> specification. We first check whether there is an |
| 4306 |
<a name="NWDCUvTi-1K">opening left parenthesis. Next, we get the first point name. In case</a> |
| 4307 |
there is no point name, we simply abandon the processing of this |
| 4308 |
line and continue with the next one. Then we see whether there is |
| 4309 |
a trailing comma. Omitting this token yields a non-fatal error. |
| 4310 |
Then we get two more points. As before, if we can't find any of these |
| 4311 |
points this yields a fatal-error. Note, that each time we check that the |
| 4312 |
point names correspond to existing point names. Then, we call subroutine |
| 4313 |
<code>perpendicular</code> to calculate the coordinates of the point. |
| 4314 |
|
| 4315 |
<pre><a name="NWCUvTi-s2gHc-1" href="#NWDCUvTi-1K"><dfn><process <tt>perpendicular</tt> case>=</dfn></a> <b>(<a href="#NWDCUvTi-1J"><-U</a>)</b> |
| 4316 |
chk_lparen("perpendicular",$lc); |
| 4317 |
my $FirstPoint = &get_point($lc); |
| 4318 |
next LINE if $FirstPoint eq "_undef_"; |
| 4319 |
chk_comma($lc); |
| 4320 |
my $SecondPoint = &get_point($lc); |
| 4321 |
next LINE if $SecondPoint eq "_undef_"; |
| 4322 |
my $ThirdPoint = &get_point($lc); |
| 4323 |
next LINE if $ThirdPoint eq "_undef_"; |
| 4324 |
chk_rparen("No closing parenthesis found",$lc); |
| 4325 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint}); |
| 4326 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint}); |
| 4327 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$ThirdPoint}); |
| 4328 |
($Px, $Py) = perpendicular($x1,$y1,$x2,$y2,$x3,$y3); |
| 4329 |
|
| 4330 |
</pre><p><a name="NWDCUvTi-1L">In the following piece of code we process the </a><code>intersection</code> case of the |
| 4331 |
<code>point</code> specification. We get the four point names and if there is |
| 4332 |
no error we compute the intersection point by calling subroutine |
| 4333 |
<code>intersection</code>. |
| 4334 |
|
| 4335 |
<pre><a name="NWCUvTi-1uJA3A-1" href="#NWDCUvTi-1L"><dfn><process <tt>intersection</tt> case>=</dfn></a> <b>(<a href="#NWDCUvTi-1J"><-U</a>)</b> |
| 4336 |
chk_lparen("intersection",$lc); |
| 4337 |
my $FirstPoint = get_point($lc); |
| 4338 |
next LINE if $FirstPoint eq "_undef_"; |
| 4339 |
my $SecondPoint = get_point($lc); |
| 4340 |
next LINE if $SecondPoint eq "_undef_"; |
| 4341 |
chk_comma($lc); |
| 4342 |
my $ThirdPoint = get_point($lc); |
| 4343 |
next LINE if $ThirdPoint eq "_undef_"; |
| 4344 |
my $ForthPoint = get_point($lc); |
| 4345 |
next LINE if $ForthPoint eq "_undef_"; |
| 4346 |
chk_rparen("No closing parenthesis found",$lc); |
| 4347 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint}); |
| 4348 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint}); |
| 4349 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$ThirdPoint}); |
| 4350 |
my ($x4,$y4,$pSV4,$pS4)=unpack("d3A*",$PointTable{$ForthPoint}); |
| 4351 |
($Px, $Py) = intersection4points($x1,$y1,$x2,$y2,$x3,$y3,$x4,$y4); |
| 4352 |
|
| 4353 |
|
| 4354 |
</pre><p><a name="NWDCUvTi-1M">Given two points A and B, the midpoint option computes the coordinates</a> |
| 4355 |
of a third point that lies on the middle of the line segment defined by |
| 4356 |
these two points. We get the the two points, and then we compute the |
| 4357 |
coordinates of the midpoint with function <code>midpoint</code>. |
| 4358 |
|
| 4359 |
<pre><a name="NWCUvTi-3udkns-1" href="#NWDCUvTi-1M"><dfn><process <tt>midpoint</tt> case>=</dfn></a> <b>(<a href="#NWDCUvTi-1J"><-U</a>)</b> |
| 4360 |
chk_lparen("midpoint",$lc); |
| 4361 |
my $FirstPoint = &get_point($lc); |
| 4362 |
next LINE if $FirstPoint eq "_undef_"; |
| 4363 |
my $SecondPoint = &get_point($lc); |
| 4364 |
next LINE if $SecondPoint eq "_undef_"; |
| 4365 |
chk_rparen("No closing parenthesis found",$lc); |
| 4366 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint}); |
| 4367 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint}); |
| 4368 |
($Px, $Py) = midpoint($x1, $y1, $x2, $y2); |
| 4369 |
|
| 4370 |
</pre><p><a name="NWDCUvTi-1N">Given two points A and B and length d, the </a><code>PointOnLine</code> option |
| 4371 |
computes the coordinates of a point that lies d units in the direction from |
| 4372 |
A towards B. We first get the coordinates of the two points that define |
| 4373 |
the line and then we get the distance, which can be a number, a variable, |
| 4374 |
or a pair of points. |
| 4375 |
|
| 4376 |
<pre><a name="NWCUvTi-2ahy6i-1" href="#NWDCUvTi-1N"><dfn><process <tt>pointonline</tt> case>=</dfn></a> <b>(<a href="#NWDCUvTi-1J"><-U</a>)</b> |
| 4377 |
chk_lparen("pointonline",$lc); |
| 4378 |
my $FirstPoint = &get_point($lc); |
| 4379 |
next LINE if $FirstPoint eq "_undef_"; |
| 4380 |
my $SecondPoint = &get_point($lc); |
| 4381 |
next LINE if $SecondPoint eq "_undef_"; |
| 4382 |
chk_comma($lc); |
| 4383 |
# now get the distance |
| 4384 |
my $distance = expr($lc); |
| 4385 |
chk_rparen("No closing parenthesis found",$lc); |
| 4386 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint}); |
| 4387 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint}); |
| 4388 |
($Px, $Py) = pointOnLine($x1,$y1,$x2,$y2,$distance); |
| 4389 |
|
| 4390 |
</pre><p><a name="NWDCUvTi-1O">The </a><code>circumcircleCenter</code> is used when one wants to compute the coordinates |
| 4391 |
of the center of circle that passes through the three points |
| 4392 |
of a triangle defined |
| 4393 |
by the three arguments of the option. All we do is get the coordinates |
| 4394 |
of the three points and then we call the subroutine <code>circumCircleCenter</code> |
| 4395 |
to compute the center. |
| 4396 |
|
| 4397 |
<pre><a name="NWCUvTi-2TpCLC-1" href="#NWDCUvTi-1O"><dfn><process <tt>circumcircleCenter</tt> case>=</dfn></a> <b>(<a href="#NWDCUvTi-1J"><-U</a>)</b> |
| 4398 |
chk_lparen("circumCircleCenter",$lc); |
| 4399 |
my $FirstPoint = &get_point($lc); |
| 4400 |
next LINE if $FirstPoint eq "_undef_"; |
| 4401 |
my $SecondPoint = &get_point($lc); |
| 4402 |
next LINE if $SecondPoint eq "_undef_"; |
| 4403 |
my $ThirdPoint = &get_point($lc); |
| 4404 |
next LINE if $ThirdPoint eq "_undef_"; |
| 4405 |
chk_rparen("No closing parenthesis found",$lc); |
| 4406 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint}); |
| 4407 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint}); |
| 4408 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$ThirdPoint}); |
| 4409 |
($Px, $Py,$r) = &circumCircleCenter($x1,$y1,$x2,$y2,$x3,$y3,$lc); |
| 4410 |
next LINE if $Px == 0 and $Py == 0 and $r == 0; |
| 4411 |
|
| 4412 |
</pre><p><a name="NWDCUvTi-1P">The </a><code>IncircleCenter</code> option is to determine the coordinates of a point |
| 4413 |
that is the center of circle that internally touches the sides |
| 4414 |
of a triangle defined by three given points. |
| 4415 |
The coordinates are computed by the subroutine <code>IncircleCenter</code>. |
| 4416 |
|
| 4417 |
<pre><a name="NWCUvTi-4fhWIW-1" href="#NWDCUvTi-1P"><dfn><process <tt>IncircleCenter</tt> case>=</dfn></a> <b>(<a href="#NWDCUvTi-1J"><-U</a>)</b> |
| 4418 |
chk_lparen("IncircleCenter",$lc); |
| 4419 |
my $FirstPoint = &get_point($lc); |
| 4420 |
next LINE if $FirstPoint eq "_undef_"; |
| 4421 |
my $SecondPoint = &get_point($lc); |
| 4422 |
next LINE if $SecondPoint eq "_undef_"; |
| 4423 |
my $ThirdPoint = &get_point($lc); |
| 4424 |
next LINE if $ThirdPoint eq "_undef_"; |
| 4425 |
chk_rparen("No closing parenthesis found",$lc); |
| 4426 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint}); |
| 4427 |
my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint}); |
| 4428 |
my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$ThirdPoint}); |
| 4429 |
($Px, $Py, $r) = IncircleCenter($x1,$y1,$x2,$y2,$x3,$y3); |
| 4430 |
|
| 4431 |
</pre><p>The <code>ExcircleCenter</code> option is used to define the coordinates of point |
| 4432 |
that is the center of an excircle of a triangle. We first check |
| 4433 |
whether there is an opening left parenthesis. Next, we get the names of the |
| 4434 |
<a name="NWDCUvTi-1Q">three points that define the triangle. Then, we</a> |
| 4435 |
check whether there is a comma. Now we get the names of the two points that |
| 4436 |
define one side of the triangle. We check whether the two points we |
| 4437 |
get are of the set of the triangle points. If not we issue |
| 4438 |
an error message and continue with the next input line. Then we make sure |
| 4439 |
that these two points are not identical. We compute the actual |
| 4440 |
coordinates by calling the subroutine <code>excircle</code>. Finally, we |
| 4441 |
make sure there is a closing right parenthesis. |
| 4442 |
|
| 4443 |
<pre><a name="NWCUvTi-13KcO0-1" href="#NWDCUvTi-1Q"><dfn><process <tt>ExcircleCenter</tt> case>=</dfn></a> <b>(<a href="#NWDCUvTi-1J"><-U</a>)</b> |
| 4444 |
chk_lparen("ExcircleCenter",$lc); |
| 4445 |
my $PointA = get_point($lc); |
| 4446 |
next LINE if $PointA eq "_undef_"; |
| 4447 |
my $PointB = get_point($lc); |
| 4448 |
next LINE if $PointB eq "_undef_"; |
| 4449 |
my $PointC = get_point($lc); |
| 4450 |
next LINE if $PointC eq "_undef_"; |
| 4451 |
chk_comma($lc); |
| 4452 |
my $PointD = &get_point($lc); |
| 4453 |
next LINE if $PointD eq "_undef_"; |
| 4454 |
if (!memberOf($PointD, $PointA, $PointB, $PointC)) { |
| 4455 |
PrintErrorMessage("Current point isn't a side point",$lc); |
| 4456 |
next LINE; |
| 4457 |
} |
| 4458 |
my $PointE = get_point($lc); |
| 4459 |
next LINE if $PointE eq "_undef_"; |
| 4460 |
if (!memberOf($PointE, $PointA, $PointB, $PointC)) { |
| 4461 |
PrintErrorMessage("Current point isn't a side point",$lc); |
| 4462 |
next LINE; |
| 4463 |
} |
| 4464 |
if ($PointD eq $PointE) { |
| 4465 |
PrintErrorMessage("Side points are identical",$lc); |
| 4466 |
next LINE; |
| 4467 |
} |
| 4468 |
($Px, $Py, $r) = excircle($PointA, $PointB, $PointC, |
| 4469 |
$PointD, $PointE); |
| 4470 |
chk_rparen("after coordinates part",$lc); |
| 4471 |
|
| 4472 |
</pre><p> <a name="NWDCUvTi-1R">The </a><code>shift</code> option allows us to define a point's coordinates relative |
| 4473 |
to the coordinates of an existing point by using two shift parameters. Each |
| 4474 |
parameter can be either a float, a variable name, or a pair of points. |
| 4475 |
|
| 4476 |
<pre><a name="NWCUvTi-aOKf8-1" href="#NWDCUvTi-1R"><dfn><process <tt>shift</tt> case>=</dfn></a> <b>(<a href="#NWDCUvTi-1J"><-U</a> <a href="#NWDCUvTi-1a">U-></a>)</b> |
| 4477 |
|
| 4478 |
chk_lparen("shift",$lc); |
| 4479 |
my $dist1 = expr($lc); |
| 4480 |
chk_comma($lc); |
| 4481 |
my $dist2 = expr($lc); |
| 4482 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{lc($PointA)}); |
| 4483 |
$Px = $x1 + $dist1; |
| 4484 |
$Py = $y1 + $dist2; |
| 4485 |
chk_rparen("shift part",$lc); |
| 4486 |
|
| 4487 |
</pre><p><a name="NWDCUvTi-1S">The </a><code>polar</code> option allows us to define a point's coordinates relative |
| 4488 |
to the coordinates of an existing point using the polar coordinates of some |
| 4489 |
other point. We first check whether there is a left parenthesis, |
| 4490 |
Then we parse the various parts of the <code>polar</code> option. |
| 4491 |
In case the user has specified the angle in degrees, we have |
| 4492 |
to transform it into radians, as all trigonometric function expect their |
| 4493 |
arguments to be radians. Next, we compute the coordinates of the point. |
| 4494 |
We conclude by checking whether there is a closing parenthesis. |
| 4495 |
|
| 4496 |
<pre><a name="NWCUvTi-2GUwzc-1" href="#NWDCUvTi-1S"><dfn><process <tt>polar</tt> case>=</dfn></a> <b>(<a href="#NWDCUvTi-1J"><-U</a> <a href="#NWDCUvTi-1a">U-></a>)</b> |
| 4497 |
chk_lparen("polar",$lc); |
| 4498 |
my ($R1, $Theta1); |
| 4499 |
$R1 = expr($lc); |
| 4500 |
chk_comma($lc); |
| 4501 |
$Theta1 = expr($lc); |
| 4502 |
my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{lc($PointA)}); |
| 4503 |
s/\s*//; |
| 4504 |
if (s/^rad(?=\W)//i) { |
| 4505 |
# do nothing! |
| 4506 |
} |
| 4507 |
elsif (s/^deg(?=\W)//i) { |
| 4508 |
$Theta1 = $Theta1 * PI / 180; |
| 4509 |
} |
| 4510 |
else { |
| 4511 |
#$Theta1 = $Theta1 * PI / 180; |
| 4512 |
} |
| 4513 |
$Px = $x1 + $R1 * cos($Theta1); |
| 4514 |
$Py = $y1 + $R1 * sin($Theta1); |
| 4515 |
chk_rparen("after polar part",$lc); |
| 4516 |
|
| 4517 |
</pre><p>The <code>rotate</code> option allows us to define a point's coordinates by |
| 4518 |
rotating an existing point, Q, about a third point, P, by a |
| 4519 |
specified angle. |
| 4520 |
The method to achieve this is to first get the coordinates of points |
| 4521 |
P and Q and then |
| 4522 |
<ol> |
| 4523 |
<li> <a name="NWDCUvTi-1T">translate origin to P</a></li> |
| 4524 |
<li> rotate about P</li> |
| 4525 |
<li> translate from P back to origin, etc</li> |
| 4526 |
</ol> |
| 4527 |
As in the case of the <code>polar</code> option, we check for an opening parenthesis. |
| 4528 |
Next, we parse the point name and the angle. At this point we are able to |
| 4529 |
compute the coordinates of the rotated point. We conclude by checking |
| 4530 |
whether there is a closing parenthesis. |
| 4531 |
|
| 4532 |
<pre><a name="NWCUvTi-42YuKP-1" href="#NWDCUvTi-1T"><dfn><process <tt>rotate</tt> case>=</dfn></a> <b>(<a href="#NWDCUvTi-1J"><-U</a>)</b> |
| 4533 |
chk_lparen("rotate",$lc); |
| 4534 |
my $Q = lc($PointA); |
| 4535 |
my $P = get_point($lc); |
| 4536 |
next LINE if $P eq "_undef_"; |
| 4537 |
chk_comma($lc); |
| 4538 |
my $Theta1 = expr($lc); |
| 4539 |
my ($xP,$yP,$pSV1,$pS1)=unpack("d3A*",$PointTable{$P}); |
| 4540 |
my ($xQ,$yQ,$pSV2,$pS2)=unpack("d3A*",$PointTable{$Q}); |
| 4541 |
s/\s*//; |
| 4542 |
if (s/^rad(?=\W)//i) |
| 4543 |
{ |
| 4544 |
# do nothing! |
| 4545 |
} |
| 4546 |
elsif (s/^deg(?=\W)//i) |
| 4547 |
{ |
| 4548 |
$Theta1 = $Theta1 * PI / 180; |
| 4549 |
} |
| 4550 |
else |
| 4551 |
{ |
| 4552 |
$Theta1 = $Theta1 * PI / 180; |
| 4553 |
} |
| 4554 |
# shift origin to P |
| 4555 |
$xQ -= $xP; |
| 4556 |
$yQ -= $yP; |
| 4557 |
# do the rotation |
| 4558 |
$Px = $xQ * cos($Theta1) - $yQ * sin($Theta1); |
| 4559 |
$Py = $xQ * sin($Theta1) + $yQ * cos($Theta1); |
| 4560 |
# return origin back to original origin |
| 4561 |
$Px += $xP; |
| 4562 |
$Py += $yP; |
| 4563 |
chk_rparen("after rotate part",$lc); |
| 4564 |
|
| 4565 |
</pre><p> <code><a name="NWDCUvTi-1U">vector(PQ)</a></code> is actually is a shorthand of <code>shift(xQ-xP,yQ-yP)</code>. Thus, it |
| 4566 |
is implemented by borrowing code from the <code>shift</code> modifier. |
| 4567 |
|
| 4568 |
<pre><a name="NWCUvTi-3FiNXu-1" href="#NWDCUvTi-1U"><dfn><process <tt>vector</tt> case>=</dfn></a> <b>(<a href="#NWDCUvTi-1J"><-U</a>)</b> |
| 4569 |
chk_lparen("vector",$lc); |
| 4570 |
my ($x0,$y0,$pSV0,$pS0) = unpack("d3A*",$PointTable{lc($PointA)}); |
| 4571 |
my $P = get_point($lc); |
| 4572 |
my $Q = get_point($lc); |
| 4573 |
my ($x1,$y1,$pSV1,$pS1) = unpack("d3A*",$PointTable{$P}); |
| 4574 |
my ($x2,$y2,$pSV2,$pS2) = unpack("d3A*",$PointTable{$Q}); |
| 4575 |
$Px = $x0 + $x2 - $x1; |
| 4576 |
$Py = $y0 + $y2 - $y1; |
| 4577 |
chk_rparen("vector part",$lc); |
| 4578 |
|
| 4579 |
|
| 4580 |
</pre><p> When lines are drawn to a point, the line will (unless otherwise |
| 4581 |
specified) extend to the point location. However, this can be prevented by |
| 4582 |
allocating an optional circular line-free zone to a point by specifying the |
| 4583 |
radius (in square brackets) of the optional point shape part. Currently, in this part |
| 4584 |
we are allowed to describe the point shape and the radius value. If only the |
| 4585 |
radius is specified, e.g., <tt>[radius=5]</tt>, then the line-free zone will be |
| 4586 |
applied to the default point character, i.e., <tt>$\bullet$</tt> or whatever it |
| 4587 |
has been set to. Here is the syntax we employ: |
| 4588 |
<pre> |
| 4589 |
Optional_point_shape_part ::= "[" [ symbol_part ] [","] [ radius_part ]" |
| 4590 |
<a name="NWDCUvTi-1V">symbol_part ::= "symbol" "=" symbol</a> |
| 4591 |
symbol ::= "circle" "(" expression ")" | |
| 4592 |
"square" "(" expression ")" | |
| 4593 |
LaTeX_Code |
| 4594 |
radius_part ::= "radius" "=" expression |
| 4595 |
</pre> |
| 4596 |
Note that it is possible to have right square bracket in the <tt>LaTeX_Code</tt> but it |
| 4597 |
has to be escaped (i.e., <tt>\]</tt>). |
| 4598 |
|
| 4599 |
<pre><a name="NWCUvTi-48J1W6-1" href="#NWDCUvTi-1V"><dfn><process optional point shape part>=</dfn></a> <b>(<a href="#NWDCUvTi-1I"><-U</a>)</b> |
| 4600 |
if (/^(symbol|radius|side)\s*/i) { |
| 4601 |
my @previous_options = (); |
| 4602 |
my $number_of_options = 1; |
| 4603 |
my $symbol_set = 0; |
| 4604 |
while (s/^(symbol|radius)\s*//i and $number_of_options <= 2) { |
| 4605 |
my $option = lc($1); |
| 4606 |
if (s/^=\s*//) { |
| 4607 |
if (memberOf($option,@previous_options)) { |
| 4608 |
PrintErrorMessage("Option \"$option\" has been already defined", $lc); |
| 4609 |
my $dummy = expr($lc); |
| 4610 |
} |
| 4611 |
elsif ($option eq "radius") { |
| 4612 |
$sh = expr($lc); |
| 4613 |
$sv = $defaultsymbol if ! $symbol_set; |
| 4614 |
} |
| 4615 |
elsif ($option eq "symbol") { |
| 4616 |
if (s/^circle\s*//i) { |
| 4617 |
$sv = "circle"; |
| 4618 |
chk_lparen("after token circle",$lc); |
| 4619 |
$side_or_radius = expr($lc); |
| 4620 |
chk_rparen("expression",$lc); |
| 4621 |
} |
| 4622 |
elsif (s/^square\s*//i) { |
| 4623 |
$sv = "square"; |
| 4624 |
chk_lparen("after token square",$lc); |
| 4625 |
$side_or_radius = expr($lc); |
| 4626 |
chk_rparen("expression",$lc); |
| 4627 |
} |
| 4628 |
elsif (s/^(((\\\]){1}|(\\,){1}|(\\\s){1}|[^\],\s])+)//) { |
| 4629 |
$sv = $1; |
| 4630 |
$sv =~ s/\\\]/\]/g; |
| 4631 |
$sv =~ s/\\,/,/g; |
| 4632 |
$sv =~ s/\\ / /g; |
| 4633 |
s/\s*//; |
| 4634 |
} |
| 4635 |
$symbol_set = 1; |
| 4636 |
} |
| 4637 |
} |
| 4638 |
else { |
| 4639 |
PrintErrorMessage("unexpected token", $lc); |
| 4640 |
next LINE; |
| 4641 |
} |
| 4642 |
$number_of_options++; |
| 4643 |
push (@previous_options, $option); |
| 4644 |
s/^,\s*//; |
| 4645 |
} |
| 4646 |
} |
| 4647 |
else { |
| 4648 |
PrintErrorMessage("unexpected token", $lc); |
| 4649 |
next LINE; |
| 4650 |
} |
| 4651 |
|
| 4652 |
</pre><p>The <code>ArrowShape</code> command has either one or three arguments. If the only argument of |
| 4653 |
the command is the token <code>default</code>, then the parameters associated with the |
| 4654 |
arrow shape resume their default values. Now, if there are three arguments, these are |
| 4655 |
used to specify the shape of an arrow. The command actually sets the three global variables |
| 4656 |
<code>$arrowLength</code>, <code>$arrowAngleB</code> and <code>$arrowAngleC</code>. Arguments whose value is equal |
| 4657 |
to zero, do not affect the value of the corresponding global variables. To reset the |
| 4658 |
values of the global variables one should use the commane with <code>default</code> as it |
| 4659 |
only argument. The syntax of the command is as follows: |
| 4660 |
<center> |
| 4661 |
<tt><a name="NWDCUvTi-1W">"ArrowShape" "(" expr [ units ] "," expr "," expr ")"</a></tt> or<br> |
| 4662 |
<tt>"ArrowShape" "(" "default" ")" </tt> |
| 4663 |
</center>> |
| 4664 |
Here <code>units</code> is any valid TeX unit (e.g., "mm", "cm", etc.). Note that if |
| 4665 |
any of the three expressions is equal to zero, the default value is taken |
| 4666 |
instead. As direct consequence, if the value of the first expression is zero, |
| 4667 |
the units part is actually ignored. |
| 4668 |
|
| 4669 |
<pre><a name="NWCUvTi-4T61Ms-1" href="#NWDCUvTi-1W"><dfn><process <tt>ArrowShape</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 4670 |
|
| 4671 |
chk_lparen("$cmd",$lc); |
| 4672 |
if (s/^default//i) { |
| 4673 |
$arrowLength = 2; |
| 4674 |
$arrowLengthUnits = "mm"; |
| 4675 |
$arrowAngleB = 30; |
| 4676 |
$arrowAngleC = 40; |
| 4677 |
} |
| 4678 |
else { |
| 4679 |
my ($LocalArrowLength, $LocalArrowAngleB ,$LocalArrowAngleC) = (0,0,0); |
| 4680 |
$LocalArrowLength = expr($lc); |
| 4681 |
if (s/^\s*($units)//i) { |
| 4682 |
$arrowLengthUnits = "$1"; |
| 4683 |
} |
| 4684 |
else { |
| 4685 |
$xunits =~ /(\d+(\.\d+)?)\s*($units)/; |
| 4686 |
$LocalArrowLength *= $1; |
| 4687 |
$arrowLengthUnits = "$3"; |
| 4688 |
} |
| 4689 |
chk_comma($lc); |
| 4690 |
$LocalArrowAngleB = expr($lc); |
| 4691 |
chk_comma($lc); |
| 4692 |
$LocalArrowAngleC = expr($lc); |
| 4693 |
$arrowLength = ($LocalArrowLength == 0 ? 2 : $LocalArrowLength); |
| 4694 |
$arrowLengthUnits = ($LocalArrowLength == 0 ? "mm" : $arrowLengthUnits); |
| 4695 |
$arrowAngleB = ($LocalArrowAngleB == 0 ? 30 : $LocalArrowAngleB); |
| 4696 |
$arrowAngleC = ($LocalArrowAngleC == 0 ? 40 : $LocalArrowAngleC); |
| 4697 |
} |
| 4698 |
chk_rparen("after $cmd arguments",$lc); |
| 4699 |
chk_comment("after $cmd command",$lc); |
| 4700 |
print OUT "%% arrowLength = $arrowLength$arrowLengthUnits, ", |
| 4701 |
"arrowAngleB = $arrowAngleB ", |
| 4702 |
"and arrowAngleC = $arrowAngleC\n" if $comments_on; |
| 4703 |
|
| 4704 |
</pre><p>The <code>PointSymbol</code> command is used to set the point symbol and possibly its |
| 4705 |
line-free radius. The point symbol can be either a LaTeX symbol or the word <code>default</code> |
| 4706 |
which corresponds to the default point symbol, i.e., <tt>$\bullet$</tt>. The line-free |
| 4707 |
radius can be an expression. Here is the complete syntax: |
| 4708 |
<pre> |
| 4709 |
<a name="NWDCUvTi-1X">pointsymbol ::= "pointsymbol" ( symbol [ "," radius])</a> |
| 4710 |
symbol ::= "default" | circle | square | LaTeX_Code |
| 4711 |
circle ::= "circle" "(" expression ")" |
| 4712 |
square ::= "square" "(" expression ")" |
| 4713 |
radius ::= expression |
| 4714 |
</pre> |
| 4715 |
Note that the <tt>LaTeX_Code</tt> can contain the symbols <tt>\,</tt> and |
| 4716 |
<tt>\)</tt> which are escape sequences for a comma and right parenthesis, respectively. |
| 4717 |
|
| 4718 |
<pre><a name="NWCUvTi-iKtUD-1" href="#NWDCUvTi-1X"><dfn><process <tt>PointSymbol</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 4719 |
|
| 4720 |
chk_lparen("$cmd",$lc); |
| 4721 |
if (s/^default//i) #default point symbol |
| 4722 |
{ |
| 4723 |
$defaultsymbol = "\$\\bullet\$"; |
| 4724 |
} |
| 4725 |
elsif (s/^(circle|square)//i) { |
| 4726 |
$defaultsymbol = $1; |
| 4727 |
chk_lparen($defaultsymbol, $lc); |
| 4728 |
$GlobalDimOfPoints = expr($lc); |
| 4729 |
chk_rparen("expression", $lc); |
| 4730 |
} |
| 4731 |
elsif (s/^(((\\,){1}|(\\\)){1}|(\\\s){1}|[^\),\s])+)//) #arbitrary LaTeX point |
| 4732 |
{ |
| 4733 |
$defaultsymbol = $1; |
| 4734 |
$defaultsymbol=~ s/\\\)/\)/g; |
| 4735 |
$defaultsymbol=~ s/\\,/,/g; |
| 4736 |
$defaultsymbol=~ s/\\ / /g; |
| 4737 |
} |
| 4738 |
else |
| 4739 |
{ |
| 4740 |
PrintErrorMessage("unrecognized point symbol",$lc); |
| 4741 |
} |
| 4742 |
if (s/\s*,\s*//) { |
| 4743 |
$defaultLFradius = expr($lc); |
| 4744 |
} |
| 4745 |
chk_rparen("after $cmd arguments",$lc); |
| 4746 |
chk_comment("after $cmd command",$lc); |
| 4747 |
|
| 4748 |
</pre><p>The <code>system</code> command provides a shell escape. However, we use a subroutine |
| 4749 |
to check whether the argument of the command contains tainted data. If this |
| 4750 |
is the case, then we simply ignore this command. The syntax of the command |
| 4751 |
is as follows: |
| 4752 |
<pre> |
| 4753 |
system-cmd ::= "system" "(" string ")" |
| 4754 |
</pre> |
| 4755 |
<a name="NWDCUvTi-1Y">where string is just a sequence of characters enclosed in quotation marks.</a> |
| 4756 |
We start by parsing a left parenthesis and then we get the command by |
| 4757 |
calling the subroutine <code>get_string</code>. If there is an error we skip this |
| 4758 |
command. Otherwise, we assign to the variable <code>$_</code> what is left. Now we check |
| 4759 |
if the variable <code>$command</code> contains any tainted data. If it doesn't, we |
| 4760 |
execute the command, otherwise we print an error message and skip to the |
| 4761 |
next input line. Next, we check for closing right parenthesis and a possible |
| 4762 |
trailing comment. |
| 4763 |
|
| 4764 |
<pre><a name="NWCUvTi-4C0pFV-1" href="#NWDCUvTi-1Y"><dfn><process <tt>system</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 4765 |
|
| 4766 |
chk_lparen("$cmd",$lc); |
| 4767 |
my ($error, $command, $rest) = get_string($_); |
| 4768 |
next LINE if $error == 1; |
| 4769 |
$_ = $rest; |
| 4770 |
if (! is_tainted($command)) { |
| 4771 |
system($command); |
| 4772 |
} |
| 4773 |
else { |
| 4774 |
PrintErrorMessage("String \"$command\" has tainted data", $lc); |
| 4775 |
next LINE; |
| 4776 |
} |
| 4777 |
chk_rparen("after $cmd arguments",$lc); |
| 4778 |
chk_comment("after $cmd command",$lc); |
| 4779 |
|
| 4780 |
</pre><p>The <code>text</code> command is used to put a piece of text or a symbol on |
| 4781 |
a particular point of the resulting graph. The syntax of the command is |
| 4782 |
as follows: |
| 4783 |
<pre> |
| 4784 |
text-comm ::= "text" "(" text ")" "{"coords"} "[" pos-code "]" |
| 4785 |
text ::= ascii string |
| 4786 |
coords ::= Coord "," Coord | |
| 4787 |
Point-Name "," "shift" "(" Coord "," Coord ")" | |
| 4788 |
Point-Name "," "polar" "(" Coord "," Coord [angle-unit] ")" |
| 4789 |
Coord ::= decimal number | variable | pair-of-Point-Names |
| 4790 |
pair-of-Point-Names ::= Point-Name Point-Name |
| 4791 |
angle-unit ::= "deg" | "rad" |
| 4792 |
pos-code ::= lr-code [tb-code] | tb-code [lr-code] |
| 4793 |
lr-code ::= "l" | "r" |
| 4794 |
tb-code ::= "t" | "b" | "B" |
| 4795 |
</pre> |
| 4796 |
Initially, we parse the <code>text</code>. Since the text may contain parentheses |
| 4797 |
we assume that the user enters pairs of matching parentheses. Note, that |
| 4798 |
this is a flaw in the original design of the language, which may be remedied |
| 4799 |
in future releases of the software. Then, we check the <code>coords</code> part. Next, |
| 4800 |
<a name="NWDCUvTi-1Z">if there is a left square bracket, we assume the user has specified the</a> |
| 4801 |
<code>pos-code</code>. We conclude by checking a possible trailing comment. |
| 4802 |
The next thing we do is to generate the PiCTeX code. The two possible |
| 4803 |
forms follow: |
| 4804 |
<center> |
| 4805 |
<tt>\put {TEXT} [POS] at Px Py</tt><br> |
| 4806 |
<tt>\put {TEXT} at Px Py</tt><br> |
| 4807 |
</center> |
| 4808 |
|
| 4809 |
<pre><a name="NWCUvTi-z25eX-1" href="#NWDCUvTi-1Z"><dfn><process <tt>text</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 4810 |
|
| 4811 |
chk_lparen("text",$lc); |
| 4812 |
my ($level,$text)=(1,""); |
| 4813 |
TEXTLOOP: while (1) |
| 4814 |
{ |
| 4815 |
$level++ if /^\(/; |
| 4816 |
$level-- if /^\)/; |
| 4817 |
s/^(.)//; |
| 4818 |
last TEXTLOOP if $level==0; |
| 4819 |
$text .= $1; |
| 4820 |
} |
| 4821 |
chk_lcb("text part",$lc); |
| 4822 |
my ($Px, $Py,$dummy,$pos); |
| 4823 |
$pos=""; |
| 4824 |
s/\s*//; |
| 4825 |
<a name="NWCUvTi-z25eX-1-u1" href="#NWDCUvTi-1a"><i><process coordinates part of text command></i></a> |
| 4826 |
chk_rcb("coordinates part of text command",$lc); |
| 4827 |
if (s/^\[//) |
| 4828 |
{ |
| 4829 |
s/\s*//; |
| 4830 |
<a name="NWCUvTi-z25eX-1-u2" href="#NWDCUvTi-1b"><i><process optional part of text command></i></a> |
| 4831 |
s/\s*//; |
| 4832 |
chk_rsb("optional part of text command",$lc); |
| 4833 |
} |
| 4834 |
chk_comment($lc); |
| 4835 |
if ($pos eq "") |
| 4836 |
{ |
| 4837 |
printf OUT "\\put {%s} at %f %f\n", $text, $Px, $Py; |
| 4838 |
} |
| 4839 |
else |
| 4840 |
{ |
| 4841 |
printf OUT "\\put {%s} [%s] at %f %f\n", $text, $pos, $Px, $Py; |
| 4842 |
} |
| 4843 |
|
| 4844 |
</pre><p> In this section we define the code that handles the coordinates part |
| 4845 |
<a name="NWDCUvTi-1a">of the </a><code>text</code> command. The code just implements the grammar given above. |
| 4846 |
If the first token is a number, we assume this is the x-coordinate. If |
| 4847 |
it is a variable, we assume its value is the x-coordinate. However, if |
| 4848 |
it is a point name, we check whether the next token is another point name. |
| 4849 |
In this case we compute the distance between the two points. In case we |
| 4850 |
have a single point followed by a comma, we expect to have either a polar |
| 4851 |
or a shift part, which we process the same we processed them in the point |
| 4852 |
command. |
| 4853 |
|
| 4854 |
<pre><a name="NWCUvTi-Ee8Ug-1" href="#NWDCUvTi-1a"><dfn><process coordinates part of text command>=</dfn></a> <b>(<a href="#NWDCUvTi-1Z"><-U</a>)</b> |
| 4855 |
|
| 4856 |
if (/^[^\W\d_]\d{0,4}\s*[^,\w]/) { |
| 4857 |
my $Tcoord = get_point($lc); |
| 4858 |
my ($x,$y,$pSV,$pS)=unpack("d3A*",$PointTable{$Tcoord}); |
| 4859 |
$Px = $x; |
| 4860 |
$Py = $y; |
| 4861 |
} |
| 4862 |
elsif (/[^\W\d_]\d{0,4}\s*,\s*shift|polar/i) { |
| 4863 |
s/^([^\W\d_]\d{0,4})//i; |
| 4864 |
my $PointA = $1; |
| 4865 |
if (exists($PointTable{lc($PointA)})) { |
| 4866 |
s/\s*//; |
| 4867 |
if (s/^,//) { |
| 4868 |
s/\s*//; |
| 4869 |
if (s/^shift(?=\W)//i) { |
| 4870 |
<a name="NWCUvTi-Ee8Ug-1-u1" href="#NWDCUvTi-1R"><i><process <tt>shift</tt> case></i></a> |
| 4871 |
} |
| 4872 |
elsif (s/^polar(?=\W)//i) { |
| 4873 |
<a name="NWCUvTi-Ee8Ug-1-u2" href="#NWDCUvTi-1S"><i><process <tt>polar</tt> case></i></a> |
| 4874 |
} |
| 4875 |
} |
| 4876 |
} |
| 4877 |
else { |
| 4878 |
PrintErrorMessage("undefined point/var",$lc); |
| 4879 |
next LINE; |
| 4880 |
} |
| 4881 |
} |
| 4882 |
else { |
| 4883 |
$Px = expr(); |
| 4884 |
chk_comma($lc); |
| 4885 |
$Py = expr(); |
| 4886 |
} |
| 4887 |
|
| 4888 |
</pre><p>In this section we process the optional part of the <code>text</code> command. |
| 4889 |
The general rule is that we are allowed to have up to two options one |
| 4890 |
from the characters <code>l</code> and <code>r</code> and one from the the characters |
| 4891 |
<code>B</code>, <code>b</code>, and <code>t</code>. We first check whether the next character is |
| 4892 |
letter, if it isn't we issue an error message and continue with the next |
| 4893 |
input line. If it is a letter we check whether it belongs to one of the |
| 4894 |
two groups and if it doesn't we issue an error message and continue with the |
| 4895 |
next input line. If the next character belongs to first group, i.e., it is |
| 4896 |
either <code>l</code> or <code>r</code>, we store this character into the variable <code>$pos</code>. Next, |
| 4897 |
<a name="NWDCUvTi-1b">we check whether there is another letter. If it is a letter, we store it</a> |
| 4898 |
in the variable <code>$np</code>. Now we make sure that this character belongs to the |
| 4899 |
other group, i.e., it is either <code>b</code>, <code>B</code>, or <code>t</code>. In case it belongs |
| 4900 |
to the other group, we append the value of <code>$np</code> to the string stored in |
| 4901 |
the variable <code>$pos</code>. Otherwise we issue an error message and continue with the |
| 4902 |
next input line. We work similarly for the other case. In order to check |
| 4903 |
whether a character belongs to some group of characters, we use the user |
| 4904 |
defined function <code>memberOf</code>. |
| 4905 |
|
| 4906 |
<pre><a name="NWCUvTi-RSg70-1" href="#NWDCUvTi-1b"><dfn><process optional part of text command>=</dfn></a> <b>(<a href="#NWDCUvTi-1Z"><-U</a>)</b> |
| 4907 |
|
| 4908 |
if (s/^(\w{1})\s*//) { |
| 4909 |
$pos .= $1; |
| 4910 |
if (memberOf($pos, "l", "r")) { |
| 4911 |
if (s/^(\w{1})\s*//) { |
| 4912 |
my $np = $1; |
| 4913 |
if (memberOf($np, "t", "b", "B")) { |
| 4914 |
$pos .= $np; |
| 4915 |
} |
| 4916 |
else { |
| 4917 |
if (memberOf($np, "l", "r")) { |
| 4918 |
PrintErrorMessage("$np can't follow 'l' or 'r'", $lc); |
| 4919 |
} |
| 4920 |
else { |
| 4921 |
PrintErrorMessage("$np is not a valid positioning option", $lc); |
| 4922 |
} |
| 4923 |
next LINE; |
| 4924 |
} |
| 4925 |
} |
| 4926 |
} |
| 4927 |
elsif (memberOf($pos, "t", "b", "B")) { |
| 4928 |
if (s/^(\w{1})\s*//) { |
| 4929 |
my $np = $1; |
| 4930 |
if (memberOf($np, "l", "r")) { |
| 4931 |
$pos .= $np; |
| 4932 |
} |
| 4933 |
else { |
| 4934 |
if (memberOf($np, "t", "b", "B")) { |
| 4935 |
PrintErrorMessage("$np can't follow 't', 'b', or 'B'", $lc); |
| 4936 |
} |
| 4937 |
else { |
| 4938 |
PrintErrorMessage("$np is not a valid positioning option", $lc); |
| 4939 |
} |
| 4940 |
next LINE; |
| 4941 |
} |
| 4942 |
} |
| 4943 |
} |
| 4944 |
else { |
| 4945 |
PrintErrorMessage("$pos is not a valid positioning option", $lc); |
| 4946 |
next LINE; |
| 4947 |
} |
| 4948 |
} |
| 4949 |
else { |
| 4950 |
PrintErrorMessage("illegal token in optional part of text command",$lc); |
| 4951 |
next LINE; |
| 4952 |
} |
| 4953 |
|
| 4954 |
</pre><p>The <code>const</code> command is used to store values into a comma separated |
| 4955 |
list of named constants. Constant names have the same format as point names, |
| 4956 |
i.e., they start with a letter and are followed by up to two digits. The |
| 4957 |
<a name="NWDCUvTi-1c">whole operation is performed by a </a><code>do-while</code> construct that checks that |
| 4958 |
there is a valid constant name, a <code>=</code> sign, and an expression. The |
| 4959 |
<code>do-while</code> construct terminates if the next token isn't a comma. Variable |
| 4960 |
<code>$Constname</code> is used to store the initial variable name, while we store |
| 4961 |
in variable <code>$varname</code> the lowercase version of the variable name. In addition, |
| 4962 |
we make sure a constant is not redefined (or else it wouldn't be a constant:-). |
| 4963 |
The last thing we do is to check whether there is a trailing comment. |
| 4964 |
In case there, we simply ignore itl; otherwise we print a warning message. |
| 4965 |
|
| 4966 |
<pre><a name="NWCUvTi-4F0xHm-1" href="#NWDCUvTi-1c"><dfn><process <tt>const</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 4967 |
do{ |
| 4968 |
s/\s*//; |
| 4969 |
PrintErrorMessage("no identifier found after token const",$lc) |
| 4970 |
if $_ !~ s/^([^\W\d_]\d{0,4})//i; |
| 4971 |
my $Constname = $1; |
| 4972 |
my $constname = lc($Constname); |
| 4973 |
if (exists $ConstTable{$constname}) { |
| 4974 |
PrintErrorMessage("Redefinition of constant $constname",$lc); |
| 4975 |
} |
| 4976 |
s/\s*//; #remove leading white space |
| 4977 |
PrintErrorMessage("did not find expected = sign",$lc) |
| 4978 |
if $_ !~ s/^[=]//i; |
| 4979 |
my $val = expr($lc); |
| 4980 |
$VarTable{$constname} = $val; |
| 4981 |
$ConstTable{$constname} = 1; |
| 4982 |
print OUT "%% $Constname = $val\n" if $comments_on; |
| 4983 |
}while (s/^,//); |
| 4984 |
chk_comment($lc); |
| 4985 |
s/\s*//; |
| 4986 |
if (/^[^%]/) { |
| 4987 |
PrintWarningMessage("Trailing text is ignored",$lc); |
| 4988 |
} |
| 4989 |
|
| 4990 |
</pre><p>The <code>var</code> command is used to store values into a comma separated |
| 4991 |
list of named variables. Variable names have the same format as point names, |
| 4992 |
<a name="NWDCUvTi-1d">i.e., they start with a letter and are followed by up to two digits. The</a> |
| 4993 |
whole operation is performed by a <code>do-while</code> construct that checks that |
| 4994 |
there is a valid variable name, a <code>=</code> sign, and an expression. The |
| 4995 |
<code>do-while</code> construct terminates if the next token isn't a comma. The variable |
| 4996 |
<code>$Varname</code> is used to store the initial variable name, while we store |
| 4997 |
in the variable <code>$varname</code> the lowercase version of the variable name. |
| 4998 |
The last thing we do is to check whether there is a trailing comment. |
| 4999 |
In case there, we simply ignore itl; otherwise we print a warning message. |
| 5000 |
|
| 5001 |
<pre><a name="NWCUvTi-2NFa6I-1" href="#NWDCUvTi-1d"><dfn><process <tt>var</tt> command>=</dfn></a> <b>(<a href="#NWDCUvTi-r"><-U</a>)</b> |
| 5002 |
do{ |
| 5003 |
s/\s*//; |
| 5004 |
PrintErrorMessage("no identifier found after token var",$lc) |
| 5005 |
if $_ !~ s/^([^\W\d_]\d{0,4})//i; |
| 5006 |
my $Varname = $1; |
| 5007 |
my $varname = lc($Varname); |
| 5008 |
if (exists $ConstTable{$varname}) { |
| 5009 |
PrintErrorMessage("Redefinition of constant $varname",$lc); |
| 5010 |
} |
| 5011 |
s/\s*//; #remove leading white space |
| 5012 |
PrintErrorMessage("did not find expected = sign",$lc) |
| 5013 |
if $_ !~ s/^[=]//i; |
| 5014 |
my $val = expr($lc); |
| 5015 |
$VarTable{$varname} = $val; |
| 5016 |
print OUT "%% $Varname = $val\n" if $comments_on; |
| 5017 |
}while (s/^,//); |
| 5018 |
chk_comment($lc); |
| 5019 |
s/\s*//; |
| 5020 |
if (/^[^%]/) { |
| 5021 |
PrintWarningMessage("Trailing text is ignored",$lc); |
| 5022 |
} |
| 5023 |
</pre> |
| 5024 |
|
| 5025 |
<ul> |
| 5026 |
<li><a href="#NWDCUvTi-2"><i><*></i></a>: <a href="#NWDCUvTi-2">D1</a> |
| 5027 |
<li><a href="#NWDCUvTi-4"><i><Check for command line arguments></i></a>: <a href="#NWDCUvTi-2">U1</a>, <a href="#NWDCUvTi-4">D2</a> |
| 5028 |
<li><a href="#NWDCUvTi-6"><i><Check if .m file exists></i></a>: <a href="#NWDCUvTi-4">U1</a>, <a href="#NWDCUvTi-6">D2</a> |
| 5029 |
<li><a href="#NWDCUvTi-8"><i><Define global variables></i></a>: <a href="#NWDCUvTi-2">U1</a>, <a href="#NWDCUvTi-8">D2</a> |
| 5030 |
<li><a href="#NWDCUvTi-1E"><i><generate plot area related commands></i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-1E">D2</a> |
| 5031 |
<li><a href="#NWDCUvTi-1H"><i><generate the rest of the code for the <tt>paper</tt> command></i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-1H">D2</a> |
| 5032 |
<li><a href="#NWDCUvTi-3"><i><package <tt>DummyFH</tt> ></i></a>: <a href="#NWDCUvTi-2">U1</a>, <a href="#NWDCUvTi-3">D2</a> |
| 5033 |
<li><a href="#NWDCUvTi-u"><i><process <tt>angle</tt> part of command></i></a>: <a href="#NWDCUvTi-t">U1</a>, <a href="#NWDCUvTi-u">D2</a> |
| 5034 |
<li><a href="#NWDCUvTi-1W"><i><process <tt>ArrowShape</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1W">D2</a> |
| 5035 |
<li><a href="#NWDCUvTi-1F"><i><process <tt>axis</tt> part></i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-1F">D2</a> |
| 5036 |
<li><a href="#NWDCUvTi-1O"><i><process <tt>circumcircleCenter</tt> case></i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1O">D2</a> |
| 5037 |
<li><a href="#NWDCUvTi-1c"><i><process <tt>const</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1c">D2</a> |
| 5038 |
<li><a href="#NWDCUvTi-s"><i><process <tt>dasharray</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-s">D2</a> |
| 5039 |
<li><a href="#NWDCUvTi-t"><i><process <tt>drawAngleArcOrArrow</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-t">D2</a> |
| 5040 |
<li><a href="#NWDCUvTi-w"><i><process <tt>drawcircle</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-w">D2</a> |
| 5041 |
<li><a href="#NWDCUvTi-x"><i><process <tt>drawcircumcircle</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-x">D2</a> |
| 5042 |
<li><a href="#NWDCUvTi-y"><i><process <tt>drawexcircle</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-y">D2</a> |
| 5043 |
<li><a href="#NWDCUvTi-z"><i><process <tt>drawincircle</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-z">D2</a> |
| 5044 |
<li><a href="#NWDCUvTi-10"><i><process <tt>drawPerpendicular</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-10">D2</a> |
| 5045 |
<li><a href="#NWDCUvTi-11"><i><process <tt>drawpoint</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-11">D2</a> |
| 5046 |
<li><a href="#NWDCUvTi-12"><i><process <tt>drawRightAngle</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-12">D2</a> |
| 5047 |
<li><a href="#NWDCUvTi-13"><i><process <tt>drawsquare</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-13">D2</a> |
| 5048 |
<li><a href="#NWDCUvTi-1Q"><i><process <tt>ExcircleCenter</tt> case></i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1Q">D2</a> |
| 5049 |
<li><a href="#NWDCUvTi-1P"><i><process <tt>IncircleCenter</tt> case></i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1P">D2</a> |
| 5050 |
<li><a href="#NWDCUvTi-14"><i><process <tt>inputfile*</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-14">D2</a> |
| 5051 |
<li><a href="#NWDCUvTi-15"><i><process <tt>inputfile</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-15">D2</a> |
| 5052 |
<li><a href="#NWDCUvTi-1L"><i><process <tt>intersection</tt> case></i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1L">D2</a> |
| 5053 |
<li><a href="#NWDCUvTi-16"><i><process <tt>linethickness</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-16">D2</a> |
| 5054 |
<li><a href="#NWDCUvTi-1M"><i><process <tt>midpoint</tt> case></i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1M">D2</a> |
| 5055 |
<li><a href="#NWDCUvTi-17"><i><process <tt>paper</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-17">D2</a> |
| 5056 |
<li><a href="#NWDCUvTi-1K"><i><process <tt>perpendicular</tt> case></i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1K">D2</a> |
| 5057 |
<li><a href="#NWDCUvTi-1I"><i><process <tt>point/point*</tt> commands></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1I">D2</a> |
| 5058 |
<li><a href="#NWDCUvTi-1N"><i><process <tt>pointonline</tt> case></i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1N">D2</a> |
| 5059 |
<li><a href="#NWDCUvTi-1X"><i><process <tt>PointSymbol</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1X">D2</a> |
| 5060 |
<li><a href="#NWDCUvTi-1S"><i><process <tt>polar</tt> case></i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1S">D2</a>, <a href="#NWDCUvTi-1a">U3</a> |
| 5061 |
<li><a href="#NWDCUvTi-v"><i><process <tt>radius</tt> part of command></i></a>: <a href="#NWDCUvTi-t">U1</a>, <a href="#NWDCUvTi-v">D2</a> |
| 5062 |
<li><a href="#NWDCUvTi-1T"><i><process <tt>rotate</tt> case></i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1T">D2</a> |
| 5063 |
<li><a href="#NWDCUvTi-1R"><i><process <tt>shift</tt> case></i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1R">D2</a>, <a href="#NWDCUvTi-1a">U3</a> |
| 5064 |
<li><a href="#NWDCUvTi-1B"><i><process <tt>showAngle</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1B">D2</a> |
| 5065 |
<li><a href="#NWDCUvTi-1C"><i><process <tt>showArea</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1C">D2</a> |
| 5066 |
<li><a href="#NWDCUvTi-1D"><i><process <tt>showLength</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1D">D2</a> |
| 5067 |
<li><a href="#NWDCUvTi-1Y"><i><process <tt>system</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1Y">D2</a> |
| 5068 |
<li><a href="#NWDCUvTi-1Z"><i><process <tt>text</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1Z">D2</a> |
| 5069 |
<li><a href="#NWDCUvTi-1G"><i><process <tt>ticks</tt> part></i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-1G">D2</a> |
| 5070 |
<li><a href="#NWDCUvTi-18"><i><process <tt>unit</tt> part></i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-18">D2</a> |
| 5071 |
<li><a href="#NWDCUvTi-1d"><i><process <tt>var</tt> command></i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1d">D2</a> |
| 5072 |
<li><a href="#NWDCUvTi-1U"><i><process <tt>vector</tt> case></i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1U">D2</a> |
| 5073 |
<li><a href="#NWDCUvTi-19"><i><process <tt>xrange</tt> part></i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-19">D2</a> |
| 5074 |
<li><a href="#NWDCUvTi-1A"><i><process <tt>yrange</tt> part></i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-1A">D2</a> |
| 5075 |
<li><a href="#NWDCUvTi-5"><i><Process command line arguments></i></a>: <a href="#NWDCUvTi-4">U1</a>, <a href="#NWDCUvTi-5">D2</a> |
| 5076 |
<li><a href="#NWDCUvTi-1J"><i><process coordinates></i></a>: <a href="#NWDCUvTi-1I">U1</a>, <a href="#NWDCUvTi-1J">D2</a> |
| 5077 |
<li><a href="#NWDCUvTi-1a"><i><process coordinates part of text command></i></a>: <a href="#NWDCUvTi-1Z">U1</a>, <a href="#NWDCUvTi-1a">D2</a> |
| 5078 |
<li><a href="#NWDCUvTi-7"><i><process file></i></a>: <a href="#NWDCUvTi-2">U1</a>, <a href="#NWDCUvTi-7">D2</a> |
| 5079 |
<li><a href="#NWDCUvTi-r"><i><process input line></i></a>: <a href="#NWDCUvTi-q">U1</a>, <a href="#NWDCUvTi-r">D2</a> |
| 5080 |
<li><a href="#NWDCUvTi-1b"><i><process optional part of text command></i></a>: <a href="#NWDCUvTi-1Z">U1</a>, <a href="#NWDCUvTi-1b">D2</a> |
| 5081 |
<li><a href="#NWDCUvTi-1V"><i><process optional point shape part></i></a>: <a href="#NWDCUvTi-1I">U1</a>, <a href="#NWDCUvTi-1V">D2</a> |
| 5082 |
<li><a href="#NWDCUvTi-W"><i><subroutine <tt>Angle</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-W">D2</a> |
| 5083 |
<li><a href="#NWDCUvTi-K"><i><subroutine <tt>chk_comma</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-K">D2</a> |
| 5084 |
<li><a href="#NWDCUvTi-L"><i><subroutine <tt>chk_comment</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-L">D2</a> |
| 5085 |
<li><a href="#NWDCUvTi-G"><i><subroutine <tt>chk_lcb</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-G">D2</a> |
| 5086 |
<li><a href="#NWDCUvTi-E"><i><subroutine <tt>chk_lparen</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-E">D2</a> |
| 5087 |
<li><a href="#NWDCUvTi-I"><i><subroutine <tt>chk_lsb</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-I">D2</a> |
| 5088 |
<li><a href="#NWDCUvTi-H"><i><subroutine <tt>chk_rcb</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-H">D2</a> |
| 5089 |
<li><a href="#NWDCUvTi-F"><i><subroutine <tt>chk_rparen</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-F">D2</a> |
| 5090 |
<li><a href="#NWDCUvTi-J"><i><subroutine <tt>chk_rsb</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-J">D2</a> |
| 5091 |
<li><a href="#NWDCUvTi-S"><i><subroutine <tt>circumCircleCenter</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-S">D2</a> |
| 5092 |
<li><a href="#NWDCUvTi-T"><i><subroutine <tt>ComputeDist</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-T">D2</a> |
| 5093 |
<li><a href="#NWDCUvTi-d"><i><subroutine <tt>drawAngleArc</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-d">D2</a> |
| 5094 |
<li><a href="#NWDCUvTi-e"><i><subroutine <tt>drawAngleArrow</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-e">D2</a> |
| 5095 |
<li><a href="#NWDCUvTi-Z"><i><subroutine <tt>drawarrows</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-Z">D2</a> |
| 5096 |
<li><a href="#NWDCUvTi-b"><i><subroutine <tt>drawCurve</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-b">D2</a> |
| 5097 |
<li><a href="#NWDCUvTi-Y"><i><subroutine <tt>DrawLineOrArrow</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-Y">D2</a> |
| 5098 |
<li><a href="#NWDCUvTi-a"><i><subroutine <tt>drawlines</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-a">D2</a> |
| 5099 |
<li><a href="#NWDCUvTi-c"><i><subroutine <tt>drawpoints</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-c">D2</a> |
| 5100 |
<li><a href="#NWDCUvTi-m"><i><subroutine <tt>drawsquare</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-m">D2</a> |
| 5101 |
<li><a href="#NWDCUvTi-X"><i><subroutine <tt>excircle</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-X">D2</a> |
| 5102 |
<li><a href="#NWDCUvTi-f"><i><subroutine <tt>expr</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-f">D2</a> |
| 5103 |
<li><a href="#NWDCUvTi-N"><i><subroutine <tt>get_point</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-N">D2</a> |
| 5104 |
<li><a href="#NWDCUvTi-j"><i><subroutine <tt>get_string</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-j">D2</a> |
| 5105 |
<li><a href="#NWDCUvTi-V"><i><subroutine <tt>IncircleCenter</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-V">D2</a> |
| 5106 |
<li><a href="#NWDCUvTi-U"><i><subroutine <tt>intersection4points</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-U">D2</a> |
| 5107 |
<li><a href="#NWDCUvTi-k"><i><subroutine <tt>is_tainted</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-k">D2</a> |
| 5108 |
<li><a href="#NWDCUvTi-P"><i><subroutine <tt>Length</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-P">D2</a> |
| 5109 |
<li><a href="#NWDCUvTi-g"><i><subroutine <tt>memberOf</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-g">D2</a> |
| 5110 |
<li><a href="#NWDCUvTi-h"><i><subroutine <tt>midpoint</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-h">D2</a> |
| 5111 |
<li><a href="#NWDCUvTi-A"><i><subroutine <tt>mpp</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-A">D2</a> |
| 5112 |
<li><a href="#NWDCUvTi-l"><i><subroutine <tt>noOfDigits</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-l">D2</a> |
| 5113 |
<li><a href="#NWDCUvTi-O"><i><subroutine <tt>perpendicular</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-O">D2</a> |
| 5114 |
<li><a href="#NWDCUvTi-R"><i><subroutine <tt>pointOnLine</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-R">D2</a> |
| 5115 |
<li><a href="#NWDCUvTi-M"><i><subroutine <tt>print_headers</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-M">D2</a> |
| 5116 |
<li><a href="#NWDCUvTi-B"><i><subroutine <tt>PrintErrorMessage</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-B">D2</a> |
| 5117 |
<li><a href="#NWDCUvTi-D"><i><subroutine <tt>PrintFatalError</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-D">D2</a> |
| 5118 |
<li><a href="#NWDCUvTi-C"><i><subroutine <tt>PrintWarningMessage</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-C">D2</a> |
| 5119 |
<li><a href="#NWDCUvTi-q"><i><subroutine <tt>process_input</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-q">D2</a> |
| 5120 |
<li><a href="#NWDCUvTi-p"><i><subroutine <tt>setLineThickness</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-p">D2</a> |
| 5121 |
<li><a href="#NWDCUvTi-o"><i><subroutine <tt>sp2X</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-o">D2</a> |
| 5122 |
<li><a href="#NWDCUvTi-i"><i><subroutine <tt>tand</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-i">D2</a> |
| 5123 |
<li><a href="#NWDCUvTi-Q"><i><subroutine <tt>triangleArea</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-Q">D2</a> |
| 5124 |
<li><a href="#NWDCUvTi-n"><i><subroutine <tt>X2sp</tt> ></i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-n">D2</a> |
| 5125 |
<li><a href="#NWDCUvTi-9"><i><subroutine definitions></i></a>: <a href="#NWDCUvTi-2">U1</a>, <a href="#NWDCUvTi-9">D2</a> |
| 5126 |
</ul> |
| 5127 |
</body></html> |
| 5128 |
|