ltview: Run perltidy -ce
authorAxel Jacobs <axel@jaloxa.eu>
Tue, 15 Apr 2014 21:54:53 +0100
changeset 80e97d9b1fb4f7
parent 79 0f5dabeed505
child 81 2708809b30b6
ltview: Run perltidy -ce
bin/ltview.pl
     1.1 --- a/bin/ltview.pl	Tue Apr 15 21:54:44 2014 +0100
     1.2 +++ b/bin/ltview.pl	Tue Apr 15 21:54:53 2014 +0100
     1.3 @@ -12,77 +12,81 @@
     1.4  use Math::Trig;
     1.5  use File::Temp qw/ tempdir /;
     1.6  
     1.7 -my $td     = tempdir( CLEANUP => 1 );
     1.8 -my $oct    = "$td/ltview.oct";
     1.9 -my $room   = "$td/room.rad";
    1.10 -my $box;                # Overall box dimensions
    1.11 -my $rif    = "$td/ltview.rif";
    1.12 -my $lumi   = "$td/lumi.rad";    # Fitting as given on cmd line, or generated by ies2rad
    1.13 -my $lumi2  = "$td/lumi2.rad";   # Fitting centred at origin
    1.14 -my $raddev = "x11";     # Default output device. Overwrite with -o
    1.15 -my $is_ies = 0;         # Input file is IES photometry, not a Radiance luminaire
    1.16 +my $td   = tempdir( CLEANUP => 1 );
    1.17 +my $oct  = "$td/ltview.oct";
    1.18 +my $room = "$td/room.rad";
    1.19 +my $box;    # Overall box dimensions
    1.20 +my $rif  = "$td/ltview.rif";
    1.21 +my $lumi   = "$td/lumi.rad";     # Fitting as given on cmd line, or generated by ies2rad
    1.22 +my $lumi2  = "$td/lumi2.rad";    # Fitting centred at origin
    1.23 +my $raddev = "x11";              # Default output device. Overwrite with -o
    1.24 +my $is_ies = 0;    # Input file is IES photometry, not a Radiance luminaire
    1.25  
    1.26  while (@ARGV) {
    1.27 -	$_ = $ARGV[0];
    1.28 -	if (m/-i/) {
    1.29 -		$is_ies = 1;
    1.30 -	} elsif (m/-o/) {   # output device (rvu -devices)
    1.31 -		$raddev = $ARGV[1];
    1.32 -		shift @ARGV;
    1.33 -	} elsif (m/-b/) {
    1.34 -		$box = $ARGV[1];    # Box dimensions
    1.35 -		shift @ARGV;
    1.36 -	} elsif (m/^-\w/) {
    1.37 -		die("ltview: Bad option: '$_'\n");
    1.38 -	} else {
    1.39 -		last;
    1.40 -	}
    1.41 -	shift @ARGV;
    1.42 +    $_ = $ARGV[0];
    1.43 +    if (m/-i/) {
    1.44 +        $is_ies = 1;
    1.45 +    } elsif (m/-o/) {    # output device (rvu -devices)
    1.46 +        $raddev = $ARGV[1];
    1.47 +        shift @ARGV;
    1.48 +    } elsif (m/-b/) {
    1.49 +        $box = $ARGV[1];    # Box dimensions
    1.50 +        shift @ARGV;
    1.51 +    } elsif (m/^-\w/) {
    1.52 +        die("ltview: Bad option: '$_'\n");
    1.53 +    } else {
    1.54 +        last;
    1.55 +    }
    1.56 +    shift @ARGV;
    1.57  }
    1.58  
    1.59  # We need exactly one Radiance luminaires or IES file
    1.60 -if (! $#ARGV == 0) {
    1.61 -	die("ltview: Need one Radiance luminaire or IES file.\n");
    1.62 -} elsif ($is_ies == 0) {
    1.63 -	# Input file is a Radiance luminaire
    1.64 -	$lumi = $ARGV[0];
    1.65 +if ( !$#ARGV == 0 ) {
    1.66 +    die("ltview: Need one Radiance luminaire or IES file.\n");
    1.67 +} elsif ( $is_ies == 0 ) {
    1.68 +
    1.69 +    # Input file is a Radiance luminaire
    1.70 +    $lumi = $ARGV[0];
    1.71  } else {
    1.72 -	# Input file is IES photometry
    1.73 -	system qq[ ies2rad -p $td -o lumi "$ARGV[0]" ];
    1.74 +
    1.75 +    # Input file is IES photometry
    1.76 +    system qq[ ies2rad -p $td -o lumi "$ARGV[0]" ];
    1.77  }
    1.78  
    1.79 -
    1.80  # Work out centre of luminaire
    1.81  my $dimstr = `getbbox -h "$lumi"`;
    1.82  chomp $dimstr;
    1.83 +
    1.84  # Values returned by getbbox are indented and delimited with multiple spaces.
    1.85  $dimstr =~ s/^\s+//;    # remove leading spaces
    1.86 -my @dims = split(/\s+/, $dimstr);    # convert to array
    1.87 +my @dims = split( /\s+/, $dimstr );    # convert to array
    1.88  
    1.89  # Find largest axes-aligned luminaire dimension
    1.90  # The box will be ten times as large, unless overwritten with -b option.
    1.91 -my @diffs = reverse sort { $a <=> $b } ($dims[1]-$dims[0], $dims[3]-$dims[2], $dims[5]-$dims[4]);
    1.92 +my @diffs = reverse sort { $a <=> $b }
    1.93 +  ( $dims[1] - $dims[0], $dims[3] - $dims[2], $dims[5] - $dims[4] );
    1.94  my $lsize = $diffs[0];
    1.95  
    1.96  # Centre fitting at origin
    1.97 -my $xtrans = -1.0 * ($dims[0] + $dims[1]) / 2;
    1.98 -my $ytrans = -1.0 * ($dims[2] + $dims[3]) / 2;
    1.99 -my $ztrans = -1.0 * ($dims[4] + $dims[5]) / 2;
   1.100 +my $xtrans = -1.0 * ( $dims[0] + $dims[1] ) / 2;
   1.101 +my $ytrans = -1.0 * ( $dims[2] + $dims[3] ) / 2;
   1.102 +my $ztrans = -1.0 * ( $dims[4] + $dims[5] ) / 2;
   1.103  system qq[ xform -t $xtrans $ytrans $ztrans "$lumi" > $lumi2 ];
   1.104  
   1.105 -
   1.106  # Make the enclosing box
   1.107  my $b2;
   1.108 -if (defined $box) {
   1.109 -	# Room dimensions are giving explicitly.
   1.110 -	$b2 = $box / 2;
   1.111 +if ( defined $box ) {
   1.112 +
   1.113 +    # Room dimensions are giving explicitly.
   1.114 +    $b2 = $box / 2;
   1.115  } else {
   1.116 -	# Box dimensions are ten times largest luminaire bbox dimensions.
   1.117 -	$b2 = $lsize * 10.0 / 2.0;
   1.118 +
   1.119 +    # Box dimensions are ten times largest luminaire bbox dimensions.
   1.120 +    $b2 = $lsize * 10.0 / 2.0;
   1.121  }
   1.122  
   1.123 -open(FH, ">$room") or
   1.124 -		die("ltview: Can't write to temporary file '$room'\n");
   1.125 +open( FH, ">$room" )
   1.126 +  or die("ltview: Can't write to temporary file '$room'\n");
   1.127  print FH <<EndOfRoom;
   1.128  void plastic wall_mat  0  0  5 .2 .2 .2 0 0
   1.129  
   1.130 @@ -97,19 +101,20 @@
   1.131  close(FH);
   1.132  
   1.133  my $scene = "$room $lumi2";
   1.134 +
   1.135  # Make this work under Windoze
   1.136  if ( $^O =~ /MSWin32/ ) {
   1.137 -	$scene =~ s{\\}{/}g;
   1.138 -	$oct =~ s{\\}{/}g;
   1.139 -	$raddev = "qt";
   1.140 +    $scene =~ s{\\}{/}g;
   1.141 +    $oct =~ s{\\}{/}g;
   1.142 +    $raddev = "qt";
   1.143  }
   1.144  
   1.145  # Tweak scene bounding box so we get a nice view covering all of the box, without
   1.146  # having a wasteful black border around it.  Must work for arbitrary box dims.
   1.147 -my $zone = 1.1 * $b2 * ( 1 + 1/tan(22.5*pi/180) );
   1.148 +my $zone = 1.1 * $b2 * ( 1 + 1 / tan( 22.5 * pi / 180 ) );
   1.149  
   1.150 -open(FH, ">$rif") or
   1.151 -		die("ltview: Can't write to temporary file '$rif'\n");
   1.152 +open( FH, ">$rif" )
   1.153 +  or die("ltview: Can't write to temporary file '$rif'\n");
   1.154  print FH <<EndOfRif;
   1.155  scene= $scene
   1.156  ZONE= Interior -$zone $zone  -$zone $zone  -$zone $zone