Start of polygon intersection code