From e82667e6805ee00677ad222fd63810bb70cc0ad2 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 3 Nov 2013 23:21:43 -0300 Subject: [PATCH] cameo/fped2d2z.pl: new options -x and -y to flip on X and Y axis --- cameo/fped2d2z.pl | 52 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/cameo/fped2d2z.pl b/cameo/fped2d2z.pl index 01df3fd..6e45f29 100755 --- a/cameo/fped2d2z.pl +++ b/cameo/fped2d2z.pl @@ -2,8 +2,8 @@ # # fped2d2z.pl - Convert fped 2D stacks into 2.5D paths with Z information # -# Written 2012 by Werner Almesberger -# Copyright 2012 Werner Almesberger +# Written 2012, 2013 by Werner Almesberger +# Copyright 2012, 2013 Werner Almesberger # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,24 +14,34 @@ sub usage { - print STDERR "usage: $0 [-r|-t Zmax] [Zin=Zout ...] prefix ". + print STDERR "usage: $0 [-r [-x] [-y] |-t Zmax] [Zin=Zout ...] prefix ". "[file ...]\n\n"; print STDERR " Zin=Zout replace Zin with Zout\n"; print STDERR " -t Zmax set the top of the piece\n"; print STDERR " -r reverse Z stacking. Also swaps X and Y.\n"; + print STDERR " -x flip on the X axis\n"; + print STDERR " -y flip on the Y axis\n"; exit(1); } -if ($ARGV[0] eq "-r") { +while ($ARGV[0] =~ /^-/) { + if ($ARGV[0] eq "-r") { + $reverse = 1; + } elsif ($ARGV[0] eq "-t") { + shift @ARGV; + $top = $ARGV[0]; + } elsif ($ARGV[0] eq "-x") { + $flip_x = 1; + } elsif ($ARGV[0] eq "-y") { + $flip_y = 1; + } elsif ($ARGV[0] =~ /^-[^0-9]/) { + last; + } else { + &usage; + } shift @ARGV; - $reverse = 1; } -if ($ARGV[0] eq "-t") { - shift @ARGV; - $top = shift @ARGV; -} -&usage if $ARGV[0] =~ /^-[^0-9]/; while ($ARGV[0] =~ /=/) { $map{$`} = $'; @@ -50,10 +60,32 @@ while (<>) { $skip = 1; } next if $skip; + 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; + } $z{$z} .= $_; $zmax = $z if $z > $zmax || !defined $zmax; } +for $z (keys %z) { + undef $t; + for $s (split(/\n/, $z{$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"; + } + $z{$z} = "$t\n"; +} + if ($reverse) { for (keys %z) { ($t{$zmax-$_} = $z{$_}) =~