1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-22 23:26:27 +02:00

cameo/fped2stl.pl: new options -x and -y to flip on X and Y axis

This commit is contained in:
Werner Almesberger 2013-11-02 18:03:49 -03:00
parent 4fa9e129ee
commit 5b70e92254

View File

@ -16,7 +16,7 @@ use POSIX;
sub usage
{
print STDERR "usage: $0 prefix [file ...]\n\n";
print STDERR "usage: $0 [-x] [-y] prefix [file ...]\n\n";
exit(1);
}
@ -59,7 +59,18 @@ print STDERR "$name $z ...\n";
}
&usage if $ARGV[0] =~ /^-[^0-9]/;
while ($ARGV[0] =~ /^-/) {
if ($ARGV[0] == "-x") {
$flip_x = 1;
} elsif ($ARGV[0] == "-y") {
$flip_y = 1;
} elsif ($ARGV[0] =~ /^-[^0-9]/) {
last;
} else {
&usage;
}
shift;
}
$pfx = shift @ARGV;
&usage unless defined $pfx;
@ -77,6 +88,28 @@ while (<>) {
next if $skip;
next if /^#/;
$s{$z} .= $_;
if (/^(-?[0-9]*\.[0-9]*)\s+(-?[0-9]*\.[0-9]*)/) {
$xmin = $1 if $1 < $xmin || !defined $xmin;
$xmax = $1 if $1 > $xmax || !defined $xmax;
$ymin = $2 if $2 < $ymin || !defined $ymin;
$ymax = $2 if $2 > $ymax || !defined $ymax;
}
}
for $z (keys %s) {
undef $t;
for $s (split(/\n/, $s{$z})) {
if ($s =~ /^(-?[0-9]*\.[0-9]*)\s+(-?[0-9]*\.[0-9]*)/) {
$s = (($xmax+$xmin)/2-$1)." $2" if $flip_y;
# re-scan, so that we can flip on both axes
die unless
$s =~ /^(-?[0-9]*\.[0-9]*)\s+(-?[0-9]*\.[0-9]*)/;
$s = "$1 ".(($ymax+$ymin)/2-$2) if $flip_x;
}
$t .= "$s\n";
}
$s{$z} = $t;
}
undef $last;