Force a redraw
Set a reasonable error threshold
Fix (or at least try to fix) discontinuities at spline cut points
Error_threshold is either ridiculously high or comparing it squared is a dumb idea