Least squares fit of a rectangle to a given shape/boundary - A MATLAB function