Line merging algorithm

Hi all,
I have quite a few of merging lines after running a Kangaroo wool thread simulation.
What I want to do is to change the multiple overlap lines into single lines to calculate the final path’s total length.
I have used Kangaroo’s “RemoveDuplicateLines” button. But the issue is, when the t value is too low, there still be some duplicate lines overlap on one path. If I set to a high t value, it will result in lines are not connected…
I wonder if there is a magical algorithmn that can resolve it nicely?

How to refine the merging (271.3 KB)

Try with this:

Hi Daniel, thanks for your prompt reply, I have try the topologizer button, although it connects all the lines but it also deform them and the lines don’t look as smooth as they was…Did I miss something so it result in this effect?

I wonder if there is any plug-in can do as I expact:
It could loop through every line and find the intersection points, then it trims the part that out of the intersection points. I guess it must involes scripting, using the native GH components might not be able to achieve it…

Q_How to refine the merging lines (275.6 KB)