The variational cost of the change of direction in a planar curve and application to regularity of 2-dimensional sets