12 our $output_layer= '*';
15 our $ps_page_shift= 615;
16 our $ps_page_xmul= 765.354;
17 our $ps_page_ymul= 538.583;
23 our $drawers= 'arsclmnog';
24 our %chdraw_emap= qw(A ARScg
38 while (@ARGV && $ARGV[0] =~ m/^\-/) {
39 last if $ARGV[0] eq '-';
44 if (s/^D(\d+)//) { $debug= $1; }
45 elsif (s/^D//) { $debug++; }
46 elsif (s/^q//) { $quiet=1; }
47 elsif (s/^l(\d+|\*)//) { $output_layer=$1; }
48 elsif (s/^S([0-9.]+)$//) { $scale= $1 * 1.0; }
49 elsif (s/^P(\d+)x(\d+)$//) { $page_x= $1; $page_y= $2; }
50 elsif (s/^GL//) { $subsegcmapreq=1; }
51 elsif (s/^GR(.*)$//) {
55 $sscmf= new IO::File $sscmfn, 'r'
56 or die "$sscmfn: cannot open: $!\n";
58 m,^\s*(\w+/(?:[a-z]+\d+))\s+(\S.*\S)\s*$,
59 or die "$sscmfn:$.: syntax error in subseg cmap\n";
62 $sscmf->error and die "$sscmfn: error reading: $!\n";
65 ((?:[a-z]|\*|\?|\[[a-z][-a-z]*\])*?)
66 (\~?) (\d*) (\=*|\-+|\++) (\d*|\*)
68 my ($ee,$g,$n,$d,$c,$v,$cc) = ($1,$2,$3,$4,$5,$6,$7);
69 my ($eo, $invert, $lfn, $ccc, $sense,$limit);
70 $g =~ s/\?/\./g; $g =~ s/\*/\.\*/g;
71 die '-[eE]GND[=]* not allowed' if $v eq '*' && length $d;
72 $d= $output_layer if !length $d;
75 $c= '=' if !length $c;
76 if (length $v && $v ne '*') {
77 die '-[eE]GN[D]CCV not allowed' if length $c > 1;
81 die '-[eE]GN+/-* not allowed' if $v eq '*';
83 $limit= ($sense * $d) + length($c) - 1;
85 ($output_layer eq '*' ? $d
86 : $_[0]) * $sense >= $limit
90 $lfn= sub { !$invert; };
92 $limit= length($c) - 1;
95 ($output_layer eq '*' ? 1
96 : abs($_[0] - $d) <= $limit)
100 #print STDERR "output layer $output_layer; asking re $_[0] rel $d lim $limit invert $invert result $lfn_result\n";
105 foreach $c (split //, $cc) {
107 die "bad -e option $c" unless defined $chdraw_emap{$c};
108 $ccc .= $chdraw_emap{$c};
110 die "bad -E option $c" unless $c =~ m/[$drawers]/i;
115 $eo->{LayerCheck}= $lfn;
116 $eo->{DrawMods}= $ccc;
117 #print STDERR "created eo $eo re $eo->{GlobRe} n=$n d=$d v=$v c=$c limit=$limit cc=$cc\n";
120 die "-S option must come right at the start and have numeric arg";
122 die "unknown option -$_";
127 our $ptscale= 72/25.4 / $scale;
130 our $psu_edgelw= 0.5;
131 our $psu_ticklw= 0.1;
132 our $psu_ticksperu= 1;
133 our $psu_ticklen= 5.0;
135 our $psu_sleeperlen= 17;
136 our $psu_sleeperlw= 15;
137 our $psu_raillw= 1.0;
138 our $psu_thinlw= 1.0;
139 our $psu_subseglw= 2.0;
142 our $lmu_marktpt= 11;
143 our $lmu_txtboxtxty= $lmu_marktpt * 0.300;
144 our $lmu_txtboxh= $lmu_marktpt * 1.100;
145 our $lmu_txtboxpadx= $lmu_marktpt * 0.335;
146 our $lmu_txtboxoff= $lmu_marklw / 2;
147 our $lmu_txtboxlw= 1;
149 our $olu_left= 10 * $scale;
150 our $olu_right= 217 * $scale - $olu_left;
151 our $olu_bottom= 20 * $scale;
152 our $olu_top= 270 * $scale - $olu_bottom;
155 our $olu_textheight= 15;
156 our $olu_textallowperc= $lmu_marktpt * 5.0/11;
158 our $pi= atan2(0,-1);
162 return 27 unless defined $radius;
163 $radius= abs($radius);
164 return ($radius >= 450 ? 33 :
165 $radius >= 400 ? 35 :
168 sub allwidth ($) { return allwidth2($_[0]) * 0.5; }
170 our $allwidthmax= allwidth(0);
171 our $allwidthmin= allwidth(undef);
174 # $ctx->{CmdLog}= undef } not in defobj
175 # $ctx->{CmdLog}[]= [ command args ] } in defobj
176 # $ctx->{LocsMade}[]{Id}= $id
177 # $ctx->{LocsMade}[]{Neg}= 1 or 0
178 # $ctx->{Loc}{$id}{X}
179 # $ctx->{Loc}{$id}{Y}
180 # $ctx->{Loc}{$id}{A}
181 # $ctx->{Loc}{$id}{LayerKind}
182 # $ctx->{Trans}{X} # transformation. is ev representing
183 # $ctx->{Trans}{Y} # new origin. (is applied at _input_
184 # $ctx->{Trans}{A} # not at plot-time)
185 # $ctx->{Trans}{R} # but multiply all y coords by this!
186 # $ctx->{Draw} # sequence of one or more chrs from uc $drawers
187 # # possibly including X meaning never draw
188 # # anything now (eg in defobj)
189 # $ctx->{DrawMap} # =$fn s.t.
190 # # &$fn($drawchrs_spec_by_layer_cmdline)
191 # # = $drawchrs_we_should_use_due_to_obj_etc
192 # $ctx->{SegName} # initial segment name (at start of object or file)
193 # $ctx->{Layer}{Level}
194 # $ctx->{Layer}{Kind}
198 # $objs{$id}{Part} # 1 iff object is a part
200 # $eopts[]{GlobRe} # regexp for K
201 # $eopts[]{LayerCheck} # =$fn where &$fn($l) is true iff layer matches
202 # $eopts[]{DrawMods} # modifier chars for drawing
204 # @segments= ( $csss0, $dist0, $csss1, $dist1, ..., $csssn )
206 # $subsegcmap{$csss} = "$green $blue"
207 # # $csss is canonical subseg spec; always has '/'
211 our @al; # current cmd
216 our $param; # for parametric_curve
220 # Operate on Enhanced Vectors which are a location (coordinates) and a
221 # direction at that location. Representation is a hash with members X
222 # Y and A (angle of the direction in radians, anticlockwise from
223 # East). May be absolute, or interpreted as relative, according to
226 # Each function's first argument is a hashref whose X Y A members will
227 # be created or overwritten; this hashref will be returned (so you can
228 # use it `functionally' by passing {}). The other arguments may be ev
229 # hashrefs, or other info. The results are in general undefined if
230 # one of the arguments is the same hash as the result.
232 sub ev_byang ($$;$) {
233 # ev_byang(R, ANG,[LEN])
234 # result is evec LEN (default=1.0) from origin pointing in direction ANG
235 my ($res,$ang,$len)=@_;
236 $len=1.0 unless defined $len;
237 $res->{X}= $len * cos($ang);
238 $res->{Y}= $len * sin($ang);
242 sub ev_compose ($$$) {
243 # ev_compose(SUM_R, A,B);
244 # appends B to A, result is end of new B
245 # (B's X is forwards from end of A, Y is translating left from end of A)
246 # A may have a member R, which if provided then it should be 1.0 or -1.0,
247 # and B's Y and A will be multiplied by R first (ie, we can reflect);
248 my ($sum,$a,$b) = @_;
250 $r= defined $a->{R} ? $a->{R} : 1.0;
251 $sum->{X}= $a->{X} + $b->{X} * cos($a->{A}) - $r * $b->{Y} * sin($a->{A});
252 $sum->{Y}= $a->{Y} + $r * $b->{Y} * cos($a->{A}) + $b->{X} * sin($a->{A});
253 $sum->{A}= $a->{A} + $r * $b->{A};
256 sub ev_decompose ($$$) {
257 # ev_decompose(B_R, A,SUM)
258 # computes B_R s.t. ev_compose({}, A, B_R) gives SUM
261 $r= defined $a->{R} ? $a->{R} : 1.0;
262 $brx= $sum->{X} - $a->{X};
263 $bry= $r * ($sum->{Y} - $a->{Y});
264 $b->{X}= $brx * cos($a->{A}) + $bry * sin($a->{A});
265 $b->{Y}= $bry * cos($a->{A}) - $brx * sin($a->{A});
266 $b->{A}= $r * ($sum->{A} - $a->{A});
269 sub ev_lincomb ($$$$) {
270 # ev_linkcomb(RES,A,B,P)
271 # gives P*A + (1-P)*B
272 my ($r,$a,$b,$p) = @_;
274 map { $r->{$_} = $q * $a->{$_} + $p * $b->{$_} } qw(X Y A);
277 sub a_normalise ($$) {
279 # adds or subtracts 2*$pi to/from A until it is in [ Z , Z+2*$pi >
282 $r= $z + fmod($a - $z, 2.0*$pi);
283 $r += 2*$pi if $r < $z;
286 sub ev_bearing ($$) {
288 # returns bearing of B from A
289 # value returned is in [ A->{A}, A->{A} + 2*$pi >
290 # A->{A} and B->{A} are otherwise ignored
293 $r= atan2($b->{Y} - $a->{Y},
295 $r= a_normalise($r,$a->{A});
299 sub v_rotateright ($) {
301 # returns image of A rotated 90 deg clockwise
303 return { X => $a->{Y}, Y => -$a->{X} };
305 sub v_dotproduct ($$) {
308 return $a->{X} * $b->{X} + $a->{Y} * $b->{Y};
310 sub v_scalarmult ($$) {
312 # multiplies V by scalar S and returns product
314 return { X => $s * $v->{X}, Y => $s * $v->{Y} };
318 # vector sum of all inputs
321 $r= { X => 0.0, Y => 0.0 };
322 foreach $i (@i) { $r->{X} += $i->{X}; $r->{Y} += $i->{Y}; }
325 sub v_subtract ($$) {
327 # returns vector from A to B, ie B - A
329 return { X => $b->{X} - $a->{X},
330 Y => $b->{Y} - $a->{Y} };
336 my ($x,$y) = ($v->{X}, $v->{Y});
337 return sqrt($x*$x + $y*$y);
341 # returns distance from A to B
342 return v_len(v_subtract($_[0],$_[1]));
347 $$limr= $now unless defined $$limr && $$limr <= $now;
351 $$limr= $now unless defined $$limr && $$limr >= $now;
355 my ($converter,$defaulter)=@_;
357 return &$defaulter unless @al;
359 $v= &$converter($spec);
360 dv('canf ','$spec',$spec, '$v',$v);
363 sub can ($) { my ($c)=@_; canf($c, sub { die "too few args"; }); }
364 sub cano ($$) { my ($c,$def)=@_; canf($c, sub { return $def }); }
366 sub signum ($) { return ($_[0] > 0) - ($_[0] < 0); }
370 my ($min_x, $max_x, $min_y, $max_y);
372 foreach $loc (values %$objhash) {
373 upd_min(\$min_x, $loc->{X} - abs($allwidthmax * sin($loc->{A})));
374 upd_max(\$max_x, $loc->{X} + abs($allwidthmax * sin($loc->{A})));
375 upd_min(\$min_y, $loc->{Y} - abs($allwidthmax * cos($loc->{A})));
376 upd_max(\$max_y, $loc->{Y} + abs($allwidthmax * cos($loc->{A})));
378 return ($min_x, $max_x, $min_y, $max_y);
381 our %units_len= qw(- mm mm 1 cm 10 m 1000);
382 our %units_ang= qw(- d r 1); $units_ang{'d'}= 2*$pi / 360;
384 sub cva_len ($) { my ($sp)=@_; cva_units($sp,\%units_len); }
385 sub cva_identity ($) { my ($sp)=@_; $sp; }
386 sub cva_ang ($) { my ($sp)=@_; cva_units($sp,\%units_ang); }
387 sub cva_absang ($) { input_absang(cva_ang($_[0])) }
391 $sp =~ m/^([-0-9eE.]*[0-9.])([A-Za-z]*)$/
392 or die "lexically invalid quantity";
394 $u=$ua->{'-'} unless length $u;
395 defined $ua->{$u} or die "unknown unit $u";
397 print DEBUG "cva_units($sp,)=$r ($n $u $ua->{$u})\n";
402 die "invalid id" unless $sp =~ m/^[a-z][_0-9A-Za-z]*$/;
407 my ($id,$r,$d,$k,$neg,$na,$obj_id,$vflip,$locs);
408 if ($sp =~ s/^(\^?)(\w+)\!//) {
411 die "invalid obj $obj_id in loc" unless exists $objs{$obj_id};
412 $locs= $objs{$obj_id}{Loc};
417 $neg= $sp =~ s/^\-//;
419 die "unknown $id" unless defined $locs->{$id};
422 foreach $k (sort keys %$r) { $d .= " $k=$r->{$k}"; }
423 printf DEBUG "%s\n", $d;
425 $r= { X => $r->{X}, Y => -$r->{Y}, A => -$r->{A} };
429 $na= a_normalise($na,0);
430 $r= { X => $r->{X}, Y => $r->{Y}, A => $na };
437 $neg = $sp =~ s/^\-//;
439 die "duplicate $id" if exists $ctx->{Loc}{$id};
440 $ctx->{Loc}{$id}{LayerKind}= $ctx->{Layer}{Kind};
441 push @{ $ctx->{LocsMade} }, {
445 return $ctx->{Loc}{$id};
447 sub cva_cmd ($) { return cva_idstr($_[0]); }
450 return $sp if grep { $_ eq $sp } @$el;
451 die "invalid option (permitted: @$el)";
453 sub cvam_enum { my (@e) = @_; return sub { cva__enum($_[0],\@e); }; }
457 $nl= can(\&cva_idnew);
458 $i->{X}= can(\&cva_len);
459 $i->{Y}= can(\&cva_len);
460 $i->{A}= can(\&cva_ang);
461 ev_compose($nl, $ctx->{Trans}, $i);
464 my ($from,$to,$len,$right,$turn);
465 $from= can(\&cva_idex);
466 $to= can(\&cva_idnew);
467 $len= cano(\&cva_len,0);
468 $right= cano(\&cva_len,0) * $ctx->{Trans}{R};
469 $turn= cano(\&cva_ang, 0) * $ctx->{Trans}{R};
470 my ($u)= ev_compose({}, $from, { X => $len, Y => -$right, A => 0 });
471 ev_compose($to, $u, { X => 0, Y => 0, A => $turn });
476 $pfx . ($pfx =~ m/\}$|\]$/ ? '' : '->');
480 return 'undef' if !defined $v;
481 return $v if $v !~ m/\W/ && $v =~ m/[A-Z]/ && $v =~ m/^[a-z_]/i;
482 return $v if $v =~ m/^[0-9.]+/;
483 $v =~ s/[\\\']/\\$&/g;
487 sub dv1_kind ($$$$$$$) {
488 my ($pfx,$expr,$ref,$ref_exp,$ixfmt,$ixesfn,$ixmapfn) = @_;
490 return 0 if $ref ne $ref_exp;
492 foreach $ix (&$ixesfn) {
494 my ($v)= &$ixmapfn($ix);
495 #print STDERR "dv1_kind($pfx,$expr,$ref,$ref_exp,$ixmapfn) ix=$ix v=$v\n";
496 dv1($pfx,$expr.sprintf($ixfmt,dv__evr($ix)),$v);
499 printf DEBUG "%s%s= $ixfmt\n", $pfx, $expr, ' ';
504 return 0 unless $debug;
505 my ($pfx,$expr,$v) = @_;
508 #print STDERR "dv1 >$pfx|$ref<\n";
510 printf DEBUG "%s%s= %s\n", $pfx,$expr, dv__evr($v);
512 } elsif ($ref eq 'SCALAR') {
513 dv1($pfx, ($expr =~ m/^\$/ ? "\$$expr" : '${'.$expr.'}'), $$v);
516 $expr.='->' unless $expr =~ m/\]$|\}$/;
517 return if dv1_kind($pfx,$expr,$ref,'ARRAY','[%s]',
518 sub { ($[ .. $#$v) },
519 sub { $v->[$_[0]] });
520 return if dv1_kind($pfx,$expr,$ref,'HASH','{%s}',
521 sub { sort keys %$v },
522 sub { $v->{$_[0]} });
523 printf DEBUG "%s%s is %s\n", $pfx, $expr, $ref;
535 sub o ($) { $o .= $_[0]; }
536 sub ol ($) { $ol .= $_[0]; }
538 return if $subsegcmapreq;
539 print $o, $ol, " showpage\n"
546 sub o_path_begin () {
548 $o_path_verb= 'moveto';
550 sub o_path_point ($) {
552 o(" $pt $o_path_verb\n");
553 $o_path_verb= 'lineto';
555 sub o_path_stroke ($) {
557 o(" $width setlinewidth stroke\n");
559 sub o_path_strokeonly () {
564 my ($a,$b,$width)=@_;
568 o_path_stroke($width);
571 sub current_draw () {
573 $r= $ctx->{Draw} =~ m/X/ ? '' : $ctx->{Draw};
577 sub psu_coords ($$$) {
578 my ($ends,$inunit,$across)=@_;
579 # $ends->[0]{X} etc.; $inunit 0 to 1 (but go to 1.5);
580 # $across in mm, +ve to right.
581 my (%ea_zo, $zo, $prop);
582 $ea_zo{X}=$ea_zo{Y}=0;
583 foreach $zo (qw(0 1)) {
584 $prop= $zo ? $inunit : (1.0 - $inunit);
585 $ea_zo{X} += $prop * ($ends->[$zo]{X} - $across * sin($ends->[0]{A}));
586 $ea_zo{Y} += $prop * ($ends->[$zo]{Y} + $across * cos($ends->[0]{A}));
588 # dv("psu_coords ", '$ends',$ends, '$inunit',$inunit, '$across',$across,
589 # '\\%ea_zo', \%ea_zo);
590 return $ea_zo{X}." ".$ea_zo{Y};
593 sub parametric__o_pt ($) {
595 o_path_point("$pt->{X} $pt->{Y}");
598 sub segment_used_len ($) {
600 return if @segments < 3;
601 $segments[1] -= $used;
602 return if $segments[1] > 0;
603 @segments= @segments[2..-1];
606 sub parametric_segment ($$$$$) {
607 my ($p0,$p1,$lenperp,$minradius,$calcfn) = @_;
608 # makes $p (global) go from $p0 to $p1 ($p1>$p0)
609 # $lenperp is the length of one unit p, ie the curve
610 # must have a uniform `density' in parameter space
611 # $calcfn is invoked with $p set and should return a loc
612 # (ie, ref to X =>, Y =>, A =>).
613 my ($pa,$pb,@ends,$side,$ppu,$e,$v,$tick,$draw,$allwidth);
614 return unless $ctx->{Draw} =~ m/[ARSCG]/;
615 $ppu= $psu_ulen/$lenperp;
616 $allwidth= allwidth($minradius);
617 my ($railctr)=($psu_gauge + $psu_raillw)*0.5;
618 my ($tickend)=($allwidth - $psu_ticklen);
619 my ($tickpitch)=($psu_ulen / $psu_ticksperu);
620 my ($sleeperctr)=($psu_ulen*0.5);
621 my ($sleeperend)=($psu_sleeperlen*0.5);
622 print DEBUG "ps $p0 $p1 $lenperp ($ppu)\n";
623 $draw= current_draw();
625 my ($pt,$going,$red);
627 o(" $psu_subseglw setlinewidth\n");
631 if ($subsegcmapreq) {
632 next if $subsegcmap{$segments[0]}++;
633 print "$segments[0]\n" or die $!;
634 } elsif (exists $subsegcmap{$segments[0]}) {
635 $red= $pt->{A} / (2*$pi);
639 $red= sprintf("%f", $red);
640 o(" $red $subsegcmap{$segments[0]} setrgbcolor\n");
642 die "unknown subsegment colour for $segments[0]\n";
645 parametric__o_pt($pt);
649 segment_used_len($psu_ulen);
651 parametric__o_pt($pt);
654 segment_used_len(($p1-($param-$ppu)) * $lenperp);
656 parametric__o_pt(&$calcfn);
661 o(" $psu_thinlw setlinewidth\n");
663 for ($param=$p0; $param<$p1; $param += $ppu) {
664 parametric__o_pt(&$calcfn);
667 parametric__o_pt(&$calcfn);
670 return unless $draw =~ m/[ARS]/;
671 for ($pa= $p0; $pa<$p1; $pa=$pb) {
673 $param= $pa; $ends[0]= @ends ? $ends[1] : &$calcfn;
674 $param= $pb; $ends[1]= &$calcfn;
675 #print DEBUG "pa $pa $ends[0]{X} $ends[0]{Y} $ends[0]{A}\n";
676 #print DEBUG "pb $pb $ends[1]{X} $ends[1]{Y} $ends[1]{A}\n";
677 $e= $pb<=$p1 ? 1.0 : ($p1-$pa)/$ppu;
680 o_path_point(psu_coords(\@ends,0,-$allwidth));
681 o_path_point(psu_coords(\@ends,0,$allwidth));
682 o_path_point(psu_coords(\@ends,$e,$allwidth));
683 o_path_point(psu_coords(\@ends,$e,-$allwidth));
684 o(" closepath clip\n");
685 foreach $side qw(-1 1) {
687 o_line(psu_coords(\@ends,0,$side*$railctr),
688 psu_coords(\@ends,1.5,$side*$railctr),
693 o_line(psu_coords(\@ends,$sleeperctr,-$sleeperend),
694 psu_coords(\@ends,$sleeperctr,+$sleeperend),
699 foreach $side qw(-1 1) {
700 o_line(psu_coords(\@ends,0,$side*$allwidth),
701 psu_coords(\@ends,1.5,$side*$allwidth),
703 for ($tick=0; $tick<1.5; $tick+=$tickpitch/$psu_ulen) {
704 o_line(psu_coords(\@ends,$tick,$side*$allwidth),
705 psu_coords(\@ends,$tick,$side*$tickend),
715 my ($to, $ctr,$from, $radius,$delta) = @_;
716 # does parametric_segment to draw an arc centred on $ctr
717 # ($ctr->{A} ignored)
718 # from $from with radius $radius (this must be consistent!)
719 # and directionally-subtending an angle $delta.
720 # sets $to->... to be the other end, and returns $to
722 $to->{A}= $beta= $from->{A} + $delta;
723 $to->{X}= $ctr->{X} - $radius * sin($beta);
724 $to->{Y}= $ctr->{Y} + $radius * cos($beta);
725 return if abs($delta*$radius) < 1e-9;
726 parametric_segment(0.0,1.0, abs($radius*$delta), $radius, sub {
727 my ($beta) = $from->{A} + $delta * $param;
728 return { X => $ctr->{X} - $radius * sin($beta),
729 Y => $ctr->{Y} + $radius * cos($beta),
734 # joins_xxx all take $results, $from, $to, $minradius
735 # where $results->[]{Path}{K} etc. and $results->[]{SolKinds}[]
737 sub joins_twoarcs ($$$$) {
738 my ($results, $from,$to,$minradius) = @_;
739 # two circular arcs of equal maximum possible radius
740 # algorithm courtesy of Simon Tatham (`Railway problem',
741 # pers.comm. to ijackson@chiark 23.1.2004)
742 my ($sigma,$distfact, $theta,$phi, $a,$b,$c,$d, $m,$r, $radius);
743 my ($cvec,$cfrom,$cto,$midpt, $delta1,$delta2, $path,$reverse);
744 $sigma= ev_bearing($from,$to);
745 $distfact= v_dist($from,$to);
746 $theta= 0.5 * $pi - ($from->{A} - $sigma);
747 $phi= 0.5 * $pi - ($to->{A} + $pi - $sigma);
748 $a= 2 * (1 + cos($theta - $phi));
749 $b= 2 * (cos($theta) - cos($phi));
751 $d= sqrt($b*$b - 4*$a*$c);
752 o("% twoarcs theta=".ang2deg($theta)." phi=".ang2deg($phi).
753 " ${a}r^2 + ${b}r + ${c} = 0\n");
754 foreach $m (qw(-1 1)) {
756 o("% twoarcs $m insoluble\n");
759 $r= -0.5 * (-$b + $m*$d) / $a;
760 $radius= -$r * $distfact;
761 o("% twoarcs $m radius $radius ");
762 if (abs($radius) < $minradius) { o("too-small\n"); next; }
763 $cfrom= ev_compose({}, $from, { X=>0, Y=>-$radius, A=>-0.5*$pi });
764 $cto= ev_compose({}, $to, { X=>0, Y=> $radius, A=> 0.5*$pi });
765 $midpt= ev_lincomb({}, $cfrom, $cto, 0.5);
766 $reverse= signum($r);
771 $delta1= ev_bearing($cfrom, $midpt) - $cfrom->{A};
772 $delta2= ev_bearing($cto, $midpt) - $cto->{A};
773 o("ok deltas ".ang2deg($delta1)." ".ang2deg($delta2)."\n");
779 $path= [{ T=>Arc, F=>$from, C=>$cfrom, R=> $radius, D=>$delta1 },
780 { T=>Arc, F=>$to, C=>$cto, R=>-$radius, D=>$delta2 }];
781 push @$results, { Path => $path,
782 SolKinds => [ 'twoarcs', 'cross' ] };
786 sub joins_arcsline ($$$$) {
787 my ($results, $from,$to,$minradius) = @_;
788 # two circular arcs of specified radius
789 # with an intervening straight
790 my ($lr,$inv, $c,$d,$alpha,$t,$k,$l,$rpmsina,$rcosa,$linelen, $path);
791 if ($minradius<=1e-6) { o("% arcsline no-radius\n"); return; }
792 foreach $lr (qw(-1 +1)) {
793 foreach $inv (qw(-1 +1)) {
794 $c=ev_compose({},$from,{X=>0,Y=>-$lr*$minradius, A=>0 });
795 $d=ev_compose({},$to,{X=>0, Y=>-$inv*$lr*$minradius, A=>$pi });
797 o("% arcsline $lr $inv t=$t ");
798 if ($t < 1e-6) { o("concentric"); next; }
799 $c->{A}= $d->{A}= ev_bearing($c,$d);
800 o("bearing ".ang2deg($c->{A}));
803 $k= ev_compose({}, $c, { X=>0, Y=>$lr*$minradius, A=>0 });
804 $l= ev_compose({}, $d, { X=>0, Y=>$lr*$minradius, A=>0 });
807 my ($cosalpha) = 2.0 * $minradius / $t;
808 if ($cosalpha > (1.0 - 1e-6)) { o(" too-close\n"); next; }
809 $alpha= acos($cosalpha);
810 $rpmsina= $lr * $minradius * sin($alpha);
811 $rcosa= $minradius * $cosalpha;
812 $k= ev_compose({}, $c, { X=>$rcosa, Y=>$rpmsina, A=>0 });
813 $l= ev_compose({}, $d, { X=>-$rcosa, Y=>-$rpmsina, A=>0 });
814 $k->{A}= $l->{A}= ev_bearing($k,$l);
815 o(" alpha=".ang2deg($alpha)." kl^=".ang2deg($k->{A})."\n");
816 $linelen= v_dist($k,$l);
818 $path= [{ T => Arc, F => $from, C => $c,
820 D => -$lr * a_normalise
821 ($lr * ($from->{A} - $k->{A}), 0) },
822 { T => Line, A => $k, B => $l, L => $linelen },
823 { T => Arc, F => $l, C => $d,
824 R => $inv*$lr*$minradius,
825 D => -$lr*$inv * a_normalise
826 (-$lr*$inv * ($to->{A} - $l->{A}), 0) }];
829 SolKinds => [ 'arcsline', ($inv<0 ? 'cross' : 'loop') ] };
834 sub joins_arcline ($$$$) {
835 my ($results, $from,$to,$minradius) = @_;
836 # one circular arc and a straight line
837 my ($swap,$echoice,$path, $ap,$bp,$av,$bv, $e,$f, $ae,$af,$afae);
838 my ($dak,$ak,$kj,$k,$j,$aja,$jl,$l,$jc,$lc,$c,$rj,$rb);
839 foreach $swap (qw(-1 +1)) {
840 foreach $echoice (qw(0 1)) {
841 $ap= $from; $bp= { %$to }; $bp->{A} += $pi;
842 ($ap,$bp)= ($bp,$ap) if $swap<0;
843 $av= ev_byang({}, $ap->{A});
844 $bv= ev_byang({}, $bp->{A});
845 $e= ev_byang({}, 0.5 * ($ap->{A} + $bp->{A} + $echoice * $pi));
846 $f= v_rotateright($e);
847 o("% arcline $swap $echoice e ".loc2dbg($e)."\n");
848 $ae= v_dotproduct($av,$e);
849 $af= v_dotproduct($av,$f);
850 o("% arcline $swap $echoice a.e=$ae a.f=$af ");
851 if (abs($ae) < 1e-6) { o(" singular\n"); next; }
853 o("a.f/a.e=$afae\n");
854 $dak= v_dotproduct(v_subtract($ap,$bp), $e);
855 $ak= v_scalarmult($dak, $e);
856 $kj= v_scalarmult($dak * $afae, $f);
859 $aja= v_dotproduct(v_subtract($ap,$j), $av);
860 o("% arcline $swap $echoice d_ak=$dak aj.a=$aja ");
861 if ($aja < 0) { o(" backwards aj\n"); next; }
862 $jl= v_scalarmult(0.5, v_subtract($j, $bp));
863 $lc= v_scalarmult(-v_dotproduct($jl, $f) * $afae, $e);
866 $rj= v_dotproduct(v_subtract($j,$c), v_rotateright($av));
867 $rb= v_dotproduct(v_subtract($c,$bp), v_rotateright($bv));
868 o("r_j=$rj r_b=$rb ");
869 if ($rj * $rb < 0) { o(" backwards b\n"); next; }
870 if (abs($rj) < $minradius) { o(" too-small\n"); next; }
874 $path= [{ T => Line, A => $ap, B => $j, L => $aja },
875 { T => Arc, F => $j, C => $c, R => $rj,
876 D => -signum($rj) * a_normalise
877 (-signum($rj) * ($bp->{A} + $pi - $j->{A}), 0) }];
878 $path= [ reverse @$path ] if $swap<0;
879 push @$results, { Path => $path, SolKinds => [ 'arcline' ] };
885 my ($from,$to,$minradius);
886 my (@results,$result);
887 my ($path,$segment,$bestpath,$len,$scores,$bestscores,@bends,$skl);
888 my ($crit,$cs,$i,$cmp);
889 $from= can(\&cva_idex);
890 $to= can(\&cva_idex);
891 $minradius= can(\&cva_len);
892 o("% join ".loc2dbg($from)."..".loc2dbg($to)." $minradius\n");
893 joins_twoarcs(\@results, $from,$to,$minradius);
894 joins_arcsline(\@results, $from,$to,$minradius);
895 joins_arcline(\@results, $from,$to,$minradius);
896 foreach $result (@results) {
897 $path= $result->{Path};
898 $skl= $result->{SolKinds};
899 o("% possible path @$skl $path\n");
902 foreach $segment (@$path) {
903 if ($segment->{T} eq Arc) {
904 o("% Arc C ".loc2dbg($segment->{C}).
905 " R $segment->{R} D ".ang2deg($segment->{D})."\n");
906 $len += abs($segment->{R} * $segment->{D});
907 push @bends, -abs($segment->{R}) * $segment->{D}; # right +ve
908 } elsif ($segment->{T} eq Line) {
909 o("% Line A ".loc2dbg($segment->{A}).
910 " B ".loc2dbg($segment->{A})." L $segment->{L}\n");
911 $len += abs($segment->{L});
913 die "unknown segment $segment->{T}";
916 o("% length $len bends @bends.\n");
918 foreach $crit (@al, 'short') {
919 if ($crit eq 'long') { $cs= $len; }
920 elsif ($crit eq 'short') { $cs= -$len; }
921 elsif ($crit =~ m/^(begin|end|)(left|right)$/) {
922 if ($1 eq 'begin') { $cs= $bends[0]; }
923 elsif ($1 eq 'end') { $cs= $bends[$#bends]; }
924 else { $cs=0; map { $cs += $_ } @bends; }
925 $cs= -$cs if $2 eq 'left';
926 } elsif ($crit =~ m/^(\!?)(twoarcs|arcs?line|cross|loop)$/) {
927 $cs= !!(grep { $2 eq $_ } @$skl) != ($1 eq '!');
929 die "unknown sort criterion $crit";
933 o("% scores @$scores\n");
934 if (defined $bestpath) {
935 for ($i=0,$cmp=0; !$cmp && $i<@$scores; $i++) {
936 $cmp= $scores->[$i] <=> $bestscores->[$i];
941 $bestscores= $scores;
943 die "no solution" unless defined $bestpath;
944 o("% chose path $bestpath @al\n");
946 foreach $segment (@$bestpath) {
947 if ($segment->{T} eq 'Arc') {
948 arc({}, $segment->{C},$segment->{F},$segment->{R},$segment->{D});
949 } elsif ($segment->{T} eq 'Line') {
950 line($segment->{A}, $segment->{B}, $segment->{L});
952 die "unknown segment";
958 my ($from,$to,$len) = @_;
959 parametric_segment(0.0, 1.0, abs($len) + 1e-6, undef, sub {
960 ev_lincomb({}, $from, $to, $param);
965 my ($from,$to,$radius,$len,$upto,$ctr,$beta,$ang,$how,$sign_r);
966 $from= can(\&cva_idex);
967 $to= can(\&cva_idnew);
968 printf DEBUG "from $from->{X} $from->{Y} $from->{A}\n";
969 $how= can(cvam_enum(qw(len upto ang uptoang parallel)));
970 if ($how eq 'len') { $len= can(\&cva_len); }
971 elsif ($how =~ m/ang$/) { $ang= can(\&cva_ang); }
972 elsif ($how eq 'parallel' || $how eq 'upto') { $upto= can(\&cva_idex); }
973 $radius= cano(\&cva_len, 'Inf'); # +ve is right hand bend
974 if ($radius eq 'Inf') {
975 # print DEBUG "extend inf $len\n";
976 if ($how eq 'upto') {
977 $len= ($upto->{X} - $from->{X}) * cos($from->{A})
978 + ($upto->{Y} - $from->{Y}) * sin($from->{A});
979 } elsif ($how eq 'len') {
981 die "len of straight spec by angle";
983 printf DEBUG "len $len\n";
984 $to->{X}= $from->{X} + $len * cos($from->{A});
985 $to->{Y}= $from->{Y} + $len * sin($from->{A});
986 $to->{A}= $from->{A};
987 line($from,$to,$len);
989 my ($sign_r, $sign_ang, $ctr, $beta_interval, $beta, $delta);
990 print DEBUG "radius >$radius<\n";
991 $radius *= $ctx->{Trans}{R};
992 $sign_r= signum($radius);
994 $ctr->{X}= $from->{X} + $radius * sin($from->{A});
995 $ctr->{Y}= $from->{Y} - $radius * cos($from->{A});
996 if ($how eq 'upto') {
997 $beta= atan2(-$sign_r * ($upto->{X} - $ctr->{X}),
998 $sign_r * ($upto->{Y} - $ctr->{Y}));
1000 } elsif ($how eq 'parallel') {
1002 $beta_interval= 1.0;
1003 } elsif ($how eq 'uptoang') {
1004 $beta= input_absang($ang);
1005 $beta_interval= 2.0;
1006 } elsif ($how eq 'len') {
1007 $sign_ang= signum($len);
1008 $beta= $from->{A} - $sign_r * $len / abs($radius);
1009 $beta_interval= 2.0;
1011 $sign_ang= signum($ang);
1012 $beta= $from->{A} - $sign_r * $ang;
1013 $beta_interval= 2.0;
1015 printf DEBUG "ctr->{Y}=$ctr->{Y} radius=$radius beta=$beta\n";
1016 $beta += $sign_ang * $sign_r * 4.0 * $pi;
1018 $delta= $beta - $from->{A};
1019 last if $sign_ang * $sign_r * $delta <= 0;
1020 $beta -= $sign_ang * $sign_r * $beta_interval * $pi;
1022 printf DEBUG "ctr->{Y}=$ctr->{Y} radius=$radius beta=$beta\n";
1023 arc($to, ,$ctr,$from, $radius,$delta);
1025 printf DEBUG "to $to->{X} $to->{Y} $to->{A}\n";
1030 return "$loc->{X} $loc->{Y} ".ang2deg($loc->{A});
1033 return $_[0] * 180 / $pi;
1035 sub input_absang ($) {
1036 return $_[0] * $ctx->{Trans}{R} + $ctx->{Trans}{A};
1038 sub input_abscoords ($$) {
1040 ($in->{X}, $in->{Y}) = @_;
1042 $out= ev_compose({}, $ctx->{Trans}, $in);
1043 return ($out->{X}, $out->{Y});
1047 my ($ctx_save) = @_;
1049 Trans => { X => 0.0, Y => 0.0, A => 0.0, R => 1.0 },
1051 DrawMap => sub { $_[0]; },
1054 %{ $ctx->{Layer} }= %{ $ctx_save->{Layer} }
1055 if defined $ctx_save;
1061 sub cmd_defobj { cmd__defobj(0); }
1062 sub cmd_defpart { cmd__defobj(1); }
1063 sub cmd__defobj ($) {
1066 $id= can(\&cva_idstr);
1067 die "nested defobj" if $defobj_save;
1068 die "repeated defobj" if exists $objs{$id};
1070 $defobj_ispart= $ispart;
1071 newctx($defobj_save);
1072 $ctx->{CmdLog}= [ ];
1073 $ctx->{InDefObj}= $id;
1074 $ctx->{Draw}= $defobj_save->{Draw}.'X';
1075 $ctx->{DrawMap}= sub { ''; };
1076 $ctx->{Layer}= { Level => 5, Kind => '' };
1077 $segments[0] =~ m,/, or die;
1078 $ctx->{SegName}= $`;
1083 $id= $ctx->{InDefObj};
1084 die "unmatched enddef" unless defined $id;
1085 foreach $bit (qw(CmdLog Loc)) {
1086 $objs{$id}{$bit}= $ctx->{$bit};
1088 $objs{$id}{Part}= $defobj_ispart;
1090 $defobj_save= undef;
1091 $defobj_ispart= undef;
1094 sub cmd__runobj ($) {
1098 dv("cmd__runobj $obj_id ",'$ctx',$ctx);
1099 foreach $c (@{ $objs{$obj_id}{CmdLog} }) {
1101 next if $al[0] eq 'enddef';
1106 sub layer_draw ($$) {
1111 } elsif ($k eq 's') {
1113 } elsif ($k eq 'l') {
1118 foreach $eo (@eopts) {
1119 #print STDERR "$. layer $k$l eo $eo re $eo->{GlobRe} then $eo->{DrawMods} now $r\n";
1120 next unless $k =~ m/^$eo->{GlobRe}$/;
1121 #print STDERR "$. layer $k$l eo re $eo->{GlobRe} match\n";
1122 next unless &{ $eo->{LayerCheck} }($l);
1123 #print STDERR "$. layer $k$l eo re $eo->{GlobRe} checked\n";
1124 foreach $cc (split //, $eo->{DrawMods}) {
1126 $r .= $cc if $cc =~ m/[A-Z]/;
1129 #print STDERR "layer $k$l gives $r (before map)\n";
1130 $r= &{ $ctx->{DrawMap} }($r);
1136 $kl= can(\&cva_identity);
1137 $kl =~ m/^([A-Za-z_]*)(\d*|\=|\*)$/ or die "invalid layer spec";
1139 $l= $output_layer if $l eq '*';
1140 $l= $ctx->{Layer}{Level} if $l =~ m/^\=?$/;
1141 $ctx->{Layer}{Kind}= $k;
1142 $ctx->{Layer}{Level}= $l;
1143 $ctx->{Draw}= layer_draw($k,$l);
1146 sub cmd_part { cmd__obj(Part); }
1147 sub cmd_obj { cmd__obj(1); }
1148 sub cmd_objflip { cmd__obj(-1); }
1152 my ($obj_id, $ctx_save, $pfx, $actual, $formal_id, $formal, $formcv);
1153 my ($part_name, $ctx_inobj, $obj, $id, $newid, $newpt);
1155 $part_name= can(\&cva_idstr);
1156 $how= (@al && $al[0] =~ s/^\^//) ? -1 : +1;
1158 $obj_id= can(\&cva_idstr);
1159 if (defined $part_name) {
1160 $formal_id= can(\&cva_idstr);
1161 $actual= cano(\&cva_idex, undef);
1162 if (!defined $actual) {
1163 $actual= cva_idex("${part_name}_${formal_id}");
1166 $actual= can(\&cva_idex);
1167 $formal_id= can(\&cva_idstr);
1169 $obj= $objs{$obj_id};
1170 dv("cmd__obj ",'$obj',$obj);
1171 die "unknown obj $obj_id" unless $obj;
1172 $formal= $obj->{Loc}{$formal_id};
1173 die "unknown formal $formal_id" unless $formal;
1176 $how *= $ctx_save->{Trans}{R};
1177 $ctx->{Trans}{R}= $how;
1178 $ctx->{Trans}{A}= $actual->{A} - $formal->{A}/$how;
1179 $formcv= ev_compose({}, $ctx->{Trans},$formal);
1180 $ctx->{Trans}{X}= $actual->{X} - $formcv->{X};
1181 $ctx->{Trans}{Y}= $actual->{Y} - $formcv->{Y};
1182 if (defined $part_name) {
1183 $ctx->{InRunObj}= $ctx_save->{InRunObj}."${part_name}:";
1185 $ctx->{InRunObj}= $ctx_save->{InRunObj}."${obj_id}::";
1187 $ctx->{DrawMap}= sub {
1189 $i= &{ $ctx_save->{DrawMap} }($i);
1199 $ctx->{Draw}= &{ $ctx->{DrawMap} }($ctx_save->{Draw});
1200 cmd__runobj($obj_id);
1201 if (defined $part_name) {
1202 $pfx= $part_name.'_';
1204 if (@al && $al[0] eq '=') {
1205 $pfx= ''; shift @al;
1207 $pfx= cano(\&cva_idstr,undef);
1213 foreach $id (keys %{ $ctx_inobj->{Loc} }) {
1214 next if $id eq $formal_id;
1216 next if exists $ctx_save->{Loc}{$newid};
1217 $newpt= cva_idnew($newid);
1218 %$newpt= %{ $ctx_inobj->{Loc}{$id} };
1221 if (defined $part_name) {
1222 my ($formalr_id, $actualr_id, $formalr, $actualr);
1224 die "part results come in pairs\n" unless @al>=2;
1225 ($formalr_id, $actualr_id, @al) = @al;
1226 if ($actualr_id =~ s/^\-//) {
1227 $formalr_id= "-$formalr_id";
1228 $formalr_id =~ s/^\-\-//;
1231 local ($ctx) = $ctx_inobj;
1232 $formalr= cva_idex($formalr_id);
1234 $actualr= cva_idnew($actualr_id);
1235 %$actualr= %$formalr;
1242 dv("cmd__do $ctx @al ",'$ctx',$ctx);
1243 $cmd= can(\&cva_cmd);
1244 my ($lm,$id,$loc,$io,$ad,$draw,$thendrawre);
1245 $io= defined $ctx->{InDefObj} ? "$ctx->{InDefObj}!" : $ctx->{InRunObj};
1246 o("%L cmd $io $cmd @al\n");
1247 $ctx->{LocsMade}= [ ];
1252 die "too many args" if @al;
1253 foreach $lm (@{ $ctx->{LocsMade} }) {
1255 $loc= $ctx->{Loc}{$id};
1256 $loc->{A} += $pi if $lm->{Neg};
1257 $ad= ang2deg($loc->{A});
1258 ol("%L point $io$id ".loc2dbg($loc)." ($lm->{Neg})\n");
1259 $draw= layer_draw($loc->{LayerKind}, $ctx->{Layer}{Level});
1260 if ($draw =~ m/[LM]/) {
1262 " $loc->{X} $loc->{Y} translate $ad rotate\n");
1263 if ($draw =~ m/M/) {
1264 ol(" 0 $allwidthmin newpath moveto\n".
1265 " 0 -$allwidthmin lineto\n".
1266 " $lmu_marklw setlinewidth stroke\n");
1268 if ($draw =~ m/L/) {
1269 ol(" /s ($id) def\n".
1271 " /sx5 s stringwidth pop\n".
1272 " 0.5 mul $lmu_txtboxpadx add def\n".
1273 " -90 rotate 0 $lmu_txtboxoff translate newpath\n".
1274 " sx5 neg 0 moveto\n".
1275 " sx5 neg $lmu_txtboxh lineto\n".
1276 " sx5 $lmu_txtboxh lineto\n".
1277 " sx5 0 lineto closepath\n".
1278 " gsave 1 setgray fill grestore\n".
1279 " $lmu_txtboxlw setlinewidth stroke\n".
1280 " sx5 neg $lmu_txtboxpadx add $lmu_txtboxtxty\n".
1281 " moveto s show\n");
1288 sub cmd_showlibrary {
1289 my ($obj_id, $y, $x, $ctx_save, $width, $height);
1290 my ($max_x, $min_x, $max_y, $min_y, $nxty, $obj, $loc, $pat, $got, $glob);
1292 $x=$olu_left; $y=$olu_bottom; undef $nxty;
1294 foreach $obj_id (sort keys %objs) {
1296 foreach $glob (@al) {
1298 $got= !($pat =~ s/^\!//);
1299 die "bad pat" if $pat =~ m/[^0-9a-zA-Z_*?]/;
1300 $pat =~ s/\*/\.*/g; $pat =~ s/\?/./g;
1301 last if $obj_id =~ m/^$pat$/;
1305 $obj= $objs{$obj_id};
1306 next unless $obj->{Part};
1307 ($min_x, $max_x, $min_y, $max_y) = bbox($obj->{Loc});
1311 $width= $max_x - $min_x;
1312 $height= $max_y - $min_y;
1313 if ($width < $height) {
1314 $ctx->{Trans}{A}= 0;
1315 $ctx->{Trans}{X}= $x - $min_x;
1316 $ctx->{Trans}{Y}= $y - $min_y + $olu_textheight;
1318 ($width,$height)=($height,$width);
1319 $ctx->{Trans}{A}= 0.5 * $pi;
1320 $ctx->{Trans}{X}= $x + $max_y;
1321 $ctx->{Trans}{Y}= $y - $min_x + $olu_textheight;
1323 $adj= length($obj_id) * $olu_textallowperc - $width;
1326 $ctx->{Trans}{X} += 0.5 * $adj;
1327 if ($x + $width > $olu_right && defined $nxty) {
1331 } elsif ($y + $height > $olu_top && $y > $olu_bottom) {
1333 $x= $olu_left; $y= $olu_bottom;
1340 $ctx->{InRunObj}= $ctx_save->{InRunObj}."${obj_id}//";
1341 $ctx->{Draw}= $ctx_save->{Draw};
1342 cmd__runobj($obj_id);
1344 " /s ($obj_id) def\n".
1346 ($x + 0.5*$width)." ".($y - $olu_textheight)." moveto\n".
1347 " s stringwidth pop -0.5 mul 0 rmoveto\n".
1348 " s show grestore\n");
1349 $x += $width + $olu_gap_x;
1350 upd_max(\$nxty, $y + $height + $olu_gap_y + $olu_textheight);
1361 " /lf /Courier-New findfont $lmu_marktpt scalefont def\n".
1362 " $ps_page_shift 0 translate 90 rotate\n");
1364 if ($page_x || $page_y) {
1365 o(" /Courier-New findfont 15 scalefont setfont\n".
1366 " 30 30 moveto (${page_x}x${page_y}) show\n");
1369 o(" -$ps_page_xmul $page_x mul -$ps_page_ymul $page_y mul translate\n".
1370 " $ptscale $ptscale scale\n");
1374 open DEBUG, ($debug ? ">&2" : ">/dev/null") or die $!;
1377 select(DEBUG); $|=1;
1378 select(STDOUT); $|=1;
1388 chomp; s/^\s+//; s/\s+$//;
1389 @al= split /\s+/, $_;
1391 print DEBUG "=== @al\n";
1392 last if $al[0] eq 'eof';
1393 push @{ $ctx->{CmdLog} }, [ @al ] if exists $ctx->{CmdLog};
1398 my ($min_x, $max_x, $min_y, $max_y) = bbox($ctx->{Loc});
1400 if (defined $min_x) {
1401 $bboxstr= sprintf("width %.2d (%.2d..%2.d)\n".
1402 "height %.2d (%.2d..%2.d)\n",
1403 $max_x - $min_x, $min_x, $max_x,
1404 $max_y - $min_y, $min_y, $max_y);
1406 $bboxstr= "no locs, no bbox\n";
1408 if (!$quiet) { print STDERR $bboxstr; }
1409 $bboxstr =~ s/^/\%L bbox /mg;
1410 o($bboxstr) or die $!;
1413 my ($tick_x, $tick_y, $ticklen);
1415 printf(" gsave 0.5 setgray 0.33 setlinewidth\n".
1417 " newpath moveto\n".
1418 " -%d 0 rmoveto %d 0 rlineto\n".
1419 " -%d -%d rmoveto 0 %d rlineto stroke\n".
1421 $ticklen, $ticklen*2, $ticklen, $ticklen, $ticklen*2)
1423 for ($tick_x= $min_x; $tick_x < $max_x; $tick_x += 150) {
1424 for ($tick_y= $min_y; $tick_y < $max_y; $tick_y += 150) {
1425 printf(" %f %f regmark\n",
1430 printf(" grestore\n")