I think this approach can't handle certain cases where a path is retraced in opposite directions, like with the handwritten letter 't' or 'i'. Perhaps curvature integrals could be added as well to improve it.
Overall seems to work quite well!
It does ok if there is only a small part that retraces, but you're exactly right.
https://en.wikipedia.org/wiki/Line_integral#/media/File:Line...