Perimeter of a piecewise rectangular figure