checking for canvas bounds before line drawing