diff --git a/cameo/fped2stl.pl b/cameo/fped2stl.pl index 51204f4..63120ba 100755 --- a/cameo/fped2stl.pl +++ b/cameo/fped2stl.pl @@ -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;