Skip Menu |

This queue is for tickets about the Tk CPAN distribution.

Report information
The Basics
Id: 2016
Status: resolved
Priority: 0/
Queue: Tk

People
Owner: Nobody in particular
Requestors: stremcha [...] siliconlogic.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 804.025



Subject: $canvas->bbox bug?
Perl version: This is perl, v5.6.1 built for i386-linux perl-tk version: # $tk_version and $tk_patchLevel are reset by pTk when a mainwindow # is created, $VERSION is checked by bootstrap $Tk::version = '8.0'; $Tk::patchLevel = '8.0'; $Tk::VERSION = '800.024'; The bbox returned on an item in a canvas appears to have it's max coordinates 1 too large. For instance, if I create a rectangle with coordinates (100, 200, 300, 400), the bounding box returned by bbox is (99, 199, 302, 402) whereas I would expect (99, 199, 301, 401). Here's an example program, in case the attachment didn't work. #!/usr/bin/perl -w use Tk; ###################################################################### ###################################################################### # $main = MainWindow->new; $main->title("bbox test"); $canvas = $main->Canvas( -width => 500, -height => 500 ); @rect_coords = (100, 200, 300, 400); $rect_id = $canvas->createRectangle( @rect_coords, -fill => "green", -tags => "test_box" ); @box = $canvas->bbox($rect_id); for($i=0; $i<=$#box; $i++) { printf("rect_coords[%d] = %d\n", $i, $rect_coords[$i]); } printf("\n"); for($i=0; $i<=$#box; $i++) { printf("box[%d] = %d\n", $i, $box[$i]); } $canvas->pack(); MainLoop;
#!/usr/bin/perl -w use Tk; ###################################################################### ###################################################################### # $main = MainWindow->new; $main->title("bbox test"); $canvas = $main->Canvas( -width => 500, -height => 500 ); @rect_coords = (100, 200, 300, 400); $rect_id = $canvas->createRectangle( @rect_coords, -fill => "green", -tags => "test_box" ); @box = $canvas->bbox($rect_id); for($i=0; $i<=$#box; $i++) { printf("rect_coords[%d] = %d\n", $i, $rect_coords[$i]); } printf("\n"); for($i=0; $i<=$#box; $i++) { printf("box[%d] = %d\n", $i, $box[$i]); } $canvas->pack(); MainLoop; #################################################################
This is not a bug. bbox returns the bbox required to draw the shape. Lines have finite width (by default 1) and so to see the right and bottom edges bbox needs to be greater than the coordinates of those edges.
From: stremcha [...] siliconlogic.com
This bbox behavior is inconsistent with the latest tk packages (i.e. tk8.2, tk8.3 - not sure about tk8.1). For instance, the following similar code gives the bounding box results that I expected: 99, 199, 301, 401. ------------------------------------------------------------------------------------------------------------------------ #!/usr/bin/wish8.3 ###################################################################### wm title . "bbox_test" canvas .my_canvas -width 500 -height 500 set rect_id [.my_canvas create rect 100 200 300 400 -fill green] set box [.my_canvas bbox $rect_id] puts "bbox\[0\]: [lindex $box 0]" puts "bbox\[1\]: [lindex $box 1]" puts "bbox\[2\]: [lindex $box 2]" puts "bbox\[3\]: [lindex $box 3]" pack .my_canvas ################################################################# Earlier versions of tk (tk8.0 for instance) behaved the same as the current perl-tk, but it has been "fixed". I know that one person's bug is another's feature, but IMHO the behavior of the current tk is what more people would want and is more useful - to wit, more intuitive. If you want to leave the functionality the way it is, at least I wanted you to recognize that it doesn't match the "other" tk. I hope that someday both might agree. Thanks for your consideration. Tim [guest - Fri Jan 31 18:48:15 2003]: Show quoted text
> Perl version: This is perl, v5.6.1 built for i386-linux > perl-tk version: > # $tk_version and $tk_patchLevel are reset by pTk when a mainwindow > # is created, $VERSION is checked by bootstrap > $Tk::version = '8.0'; > $Tk::patchLevel = '8.0'; > $Tk::VERSION = '800.024'; > > The bbox returned on an item in a canvas appears to have it's max > coordinates 1 too large. > For instance, if I create a rectangle with coordinates (100, 200, 300, > 400), the bounding box > returned by bbox is (99, 199, 302, 402) whereas I would expect (99, > 199, 301, 401). > > Here's an example program, in case the attachment didn't work. > #!/usr/bin/perl -w > > use Tk; > > ###################################################################### > ###################################################################### > # > $main = MainWindow->new; > > $main->title("bbox test"); > > $canvas = $main->Canvas( > -width => 500, > -height => 500 > ); > > @rect_coords = (100, 200, 300, 400); > > $rect_id = $canvas->createRectangle( > @rect_coords, > -fill => "green", > -tags => "test_box" > ); > > @box = $canvas->bbox($rect_id); > > for($i=0; $i<=$#box; $i++) { > printf("rect_coords[%d] = %d\n", $i, $rect_coords[$i]); > } > > printf("\n"); > for($i=0; $i<=$#box; $i++) { > printf("box[%d] = %d\n", $i, $box[$i]); > } > > $canvas->pack(); > MainLoop; >