chiark / gitweb /
realtime: print all movpos positions on entering Run
[trains.git] / layout / genoverlayinfo
1 #!/usr/bin/perl
2
3 use IO::Handle;
4
5 @ARGV==5 or die;
6 ($plandatac,$forui,$matrixinfo, $height,$psdpi)=@ARGV;
7
8 open M, $matrixinfo or die $!;
9 $!=0; @matrix= <M>;
10 @matrix==6 or die $!;
11 map { die "$_ ?" unless m/^[-0-9.]+$/; } @matrix;
12 M->error and die $!;
13 close M or die $!;
14
15 # inverting the matrix ??
16 $d= 0;
17 for ($i=0; $i<4; $i+=2) {
18     $d += $matrix[$i]*$matrix[$i];
19 }
20 $d= 1/$d;
21 for ($i=0; $i<4; $i++) {
22     $matrix[$i] *= $d;
23 }
24 $matrix[1] *= -1;
25 $matrix[2] *= -1;
26
27 print STDERR "matrix: ",join(" ",map { $_+0 } @matrix),"\n";
28
29 open C, $plandatac or die $!;
30 for (;;) {
31     $!=0; defined($_=<C>) or die $!;
32     next unless m,^/\* region\: (\d+)\.\.\d+ (\d+)\.\.\d+ \*/$,;
33     $crop_x= $1;
34     $crop_y= $2;
35     last;
36 }
37 close C;
38
39 open U, $forui or die $!;
40 while (<U>) {
41     chomp;
42     next unless m/^[^\#]/;
43     m/^(layout-subseg-end \w+ \w \w) ([0-9.]+) ([0-9.]+)$/ or die "$_ ?";
44     ($lhs, $xup,$yup) = ($1,$2,$3);
45
46     $xup -= $matrix[4];
47     $yup -= $matrix[5];
48
49     $x = $xup*$matrix[0] + $yup*$matrix[2];
50     $y = $xup*$matrix[1] + $yup*$matrix[3];
51
52     $x *= $psdpi / 72.0;
53     $y *= $psdpi / 72.0;
54
55     $y= $height - $y;
56
57     $x -= $crop_x;
58     $y -= $crop_y;
59
60     printf "%s %f %f\n", $lhs, $x, $y or die $!;
61 }
62 U->error and die $!;
63 close U or die $!;