Function name isn't so important I thought TO - like closest point to...
My function uses vl-sort function witch should remove duplicates when reaching solution point, so (length ptlstsort) shouldn't be always 4 - that was the main point of my code... But now I see that recursion isn't so good approach as there are cases when length should be 4 and already met opportunities for solution : line with mid or circle, ellipse with center...
Oh yea.. for some reason I thought VL-Sort would always return a list of the same length.
If I am understanding this correctly, you are dividing the curve into 4 points, the start point, 1/3, 2/3 and the end point. Then sorting this list by the descending distance from the test point and recursing the function between the furthest point and the second furthest point in a divide-and-concur type approach.
It might take a very long time before the function reaches a local minimum and two distances in the list will be the same because the real number that represents the parameter at the point can be very accurate. You may need to see if the two
distances parameters differ by some tolerance.
The other problem is when the actual furthest point is not between the first and second test points. See attached case: