sub getArcEnd { my ($x, $y, $x2, $y2, $start, $extent) = @_; # -------------------------------------- # PATCH # handle denormalized bounding boxes if ($x2 < $x) { my $tmp = $x; $x=$x2; $x2=$tmp; } if ($y2 < $y) { my $tmp = $y; $y=$y2; $y2=$tmp; } # -------------------------------------- # $x, $y, $x2, $y2 can be the bounding box of an # ellipse (not just a circle) so calculate vertical # and horizontal radius separately my $radiusX = ($x2 - $x)/2; my $centerX = $x + $radiusX; my $radiusY = ($y2 - $y)/2; my $centerY = $y + $radiusY; # Tk expects the starting angle and length of the # arc (extent) to be in degrees but cos and sin expect # them in radian my $radians = deg2rad($start + $extent); # [ x coord of arc end point, y coord of arc end point ] # the coordinate system for Tk::Canvas makes "down" # positive so we need to subtract the Y component # rather than add it. return [ $centerX + $radiusX*cos($radians) , $centerY - $radiusY*sin($radians) ]; }