Also allow chaining polylines before current polyline
Also allow chaining polylines before current polyline

This makes the algorithm twice as wordy! I've been having difficulty properly reducing the code duplication here. Of course it's obvious that there is duplication to a reader so hopefully the cognitive load for these 4 cases isn't all too high.
This change is necessary because the polyline that we're processing first isn't always the first polyline in a chain. It could be somewhere in the middle. If there are more than 2 endpoints coming together nearby it could then end up finishing the chains very far away from where they started, resulting in long edges across the print and thus very weird infill.

Contributes to issue CURA-7681.

Ultimaker/CuraEngine,Ultimaker/CuraEngine