I figured it out. You don\'t consider if maxx == 0 or maxy == 0 in either of your cases. I\'m sure there\'s a better way to organize this code.