$y_tmp never equals $y_end at the for loop, so one spurious line would get drawn where not for the substraction to $y_end here.
$x_tmp never equals $x_end at the for loop, so one spurious line would get drawn where not for the substraction to $x_end here.