chiark / gitweb /
bbox option (-b)
authorian <ian>
Fri, 30 Jan 2004 23:29:15 +0000 (23:29 +0000)
committerian <ian>
Fri, 30 Jan 2004 23:29:15 +0000 (23:29 +0000)
layout/layout

index 1eb8c3aee127828d2dd673a7a64230275097541a..3b44d8effa9f61b492a8f0fadc88a02f82aeb6af 100755 (executable)
@@ -177,6 +177,19 @@ sub cano ($$) { my ($c,$def)=@_; canf($c, sub { return $def }); }
 
 sub signum ($) { return ($_[0] > 0) - ($_[0] < 0); }
 
+sub bbox ($) {
+    my ($objhash) = @_;
+    my ($min_x, $max_x, $min_y, $max_y);
+    my ($loc);
+    foreach $loc (values %$objhash) {
+       upd_min(\$min_x, $loc->{X} - abs($psu_allwidth * sin($loc->{A})));
+       upd_max(\$max_x, $loc->{X} + abs($psu_allwidth * sin($loc->{A})));
+       upd_min(\$min_y, $loc->{Y} - abs($psu_allwidth * cos($loc->{A})));
+       upd_max(\$max_y, $loc->{Y} + abs($psu_allwidth * cos($loc->{A})));
+    }
+    return ($min_x, $max_x, $min_y, $max_y);
+}
+
 our %units_len= qw(- mm  mm 1  cm 10  m 1000);
 our %units_ang= qw(- d   r 1); $units_ang{'d'}= 2*$pi / 360;
 
@@ -799,13 +812,7 @@ sub cmd_showlibrary {
        }
        next unless $got;           
        $obj= $objs{$obj_id};
-       $max_x=$max_y=$min_x=$min_y=undef;
-       foreach $loc (values %{ $obj->{Loc} }) {
-           upd_min(\$min_x, $loc->{X} - abs($psu_allwidth * sin($loc->{A})));
-           upd_max(\$max_x, $loc->{X} + abs($psu_allwidth * sin($loc->{A})));
-           upd_min(\$min_y, $loc->{Y} - abs($psu_allwidth * cos($loc->{A})));
-           upd_max(\$max_y, $loc->{Y} + abs($psu_allwidth * cos($loc->{A})));
-       }
+       ($min_x, $max_x, $min_y, $max_y) = bbox($obj->{Loc});
        newctx();
 
        for (;;) {
@@ -882,6 +889,8 @@ our %chdraw_emap= qw(A ARSc
                     
 $ctx->{Draw}= uc $drawers;
 
+our $bbox=0;
+
 while (@ARGV && $ARGV[0] =~ m/^\-/) {
     last if $ARGV[0] eq '-';
     $_= shift @ARGV;
@@ -890,6 +899,7 @@ while (@ARGV && $ARGV[0] =~ m/^\-/) {
     while (length) {
        if (s/^D(\d+)//) { $debug= $1; }
        elsif (s/^D//) { $debug++; }
+       elsif (s/^b//) { $bbox=1; }
        elsif (s/^([Ee])([a-zA-Z]+)//) {
            my ($ee,$c);
            $ee= $1;
@@ -927,3 +937,16 @@ while (<>) {
 }
 
 oflushpage();
+
+if ($bbox) {
+    my ($min_x, $max_x, $min_y, $max_y) = bbox($ctx->{Loc});
+    if (defined $min_x) {
+       printf(STDERR
+              "width  %.2d (%.2d..%2.d)\n".
+              "height %.2d (%.2d..%2.d)\n",
+              $max_x - $min_x, $min_x, $max_x,
+              $max_y - $min_y, $min_y, $max_y);
+    } else {
+       print STDERR "no points, bbox\n";
+    }
+}