I’m no expert, but two thoughts came to my mind when I saw this.
A) If you are making a polycurve out of several lines,does it matter what order they are in when you join them to make a polycurve? I know there are ways to sort the lines by going clockwise or counter-clockwise so that the end of one line and the beginning of the next line are touching each other.
B) Would it be helpful to convert your curves into NURBS curves with a degree of 1? That way they are still straight lines, but are also just one line?
https://primer.dynamobim.org/05_Geometry-for-Computational-Design/5-4_curves.html