Reorder Curves and Unify Curve Direction to Match Existing list of Curves In Order to Join Into Closed Polylines

Grasshopper definition (WIP) attached.

I’m really new to grasshopper so the order of my logic in the script might not make sense. Simply put: I’m trying to create a definition that creates a 3D voronoi pattern on an input surface from a different software. I’m having trouble joining two sets of curves to create closed poly-lines. The Brep Brep Intersection component gives me a list of disordered curves. These disordered curves also have what seem to be random curve directions exasperating the problem.

I want to join the green curves with the red curves to create closed poly-lines as shown below:

I know that the end points of the curves I want to join into closed poly-lines share the exact same coordinates. The idea is to get the end points of the curves and reorganize the disordered list to have the order of the ordered list so that I can join them into poly-lines. Image Below: The list on the left is the ordered list of curves (green curves). The list on the right is the list of the disorganized curves (red curves) If I could search every branch in list 2 searching for the exact values (not necessarily in the correct order because the start of a red curve does not necessarily correspond to the end of the adjacent curve) of branch {0;0} in list 1, then all of list 2 for branch {0;1} of list 1 ect. If this “searching” would return the branch in list 2 that matches the branch {0;0},{0;1}, ect., then I could reorder my original list of disordered curves to match my ordered list.

I apologize if this makes zero sense to you all. My vocabulary may not be sufficient to explain the problem I have encountered. I hope that the attached definition makes it more clear. Voronoi Thicken Open BREP.gh (88.3 KB)

I don’t have your plugin installed, so I can’t see your data structures, anyway if you just want your open polylines to be closed, try to change your bounding box setting.
Contacting your bounding box with the upper edge of your brep should create closed curves.

Voronoi Thicken Open BREP_re.gh (24.4 KB)

Thank you for the reply. This should work!