# ... intro stuff... labent($frm, 'X1', \$x1, 8); labent($frm, 'Y1', \$y1, 8); labent($frm, 'X2', \$x2, 8); labent($frm, 'Y2', \$y2, 8); labent($frm, 'Start', \$deg, 8); labent($frm, 'Extent', \$ext, 8); #------------------------------------ #PATCH 1 my $normal = 0; labent($frm, 'Normal', \$normal, 8); #------------------------------------ # ... more stuff ... sub random_args { $x1 = random_value(0, $cw); $x2 = random_value(0, $cw); $y1 = random_value(0, $ch); $y2 = random_value(0, $ch); $deg = random_value(0, 360); #------------------------------------ #PATCH 2 if ($normal) { $x2 = 2*$x1 - $x2 if $x2 < $x1; $y2 = 2*$y1 - $y2 if $y2 < $y1; } #------------------------------------ } #### 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) ]; }