Calculate the perimeter of irregular shapes