Suppose segments AB and CD intersect. Point B is replaced by the intersection point, defined B'. Point C is replaced by a point C' on the line B'D. The maximum distance of B'C' is given by the parameter d. If the distance l B'D is less than 2d, the distance B'C' is l/2.
remove.intersections(P, d = 50)
The points, as a 2-column matrix
Criterion for maximum distance when points are inserted
A new closed path without intersections