Added polygon clipping code, which will be needed for optimizing this stuff.
Added line-line intersection.