Avoid stack overflow by not using recursion.

When lots of polygons are being merged, this can exhaust the stack quickly.