Condenses the duplicate grid algorithms into single algorithms (one for line, one for polygon), taking the best bits from both and adding tests