Continuous spline with Mesh to Curve node

I’m using mesh to curve and want continuous lines to be a single spline.
I use split edges before mesh to curve to prevent that:


where the outer lines are a single spline

But regardless of if I’m using split edges or not, each line becomes its own spline, which is not efficient with a high verts count.
(using merge by distance does decrease verbs count, but not to the minimum and leave internal faces)

I know I can select all the vertical edges with a dot product and use merge by distance on that selection (after split edges and before mesh to curve) and the same with the horizontal ones, which will remove the internal faces and with resample curve after the mesh to curve set to two samples will result in the minimal vents count, But this is too specific and will only work in this case, which is a simplified version of my node tree. I need to do it not specifically on the verticals and the horizontals, but on every angle.

I assume it’s possible to go with repeat zone edge by edge, calculating it’s angle, selecting all the other edges with the same angle and then merging by distance for that selection, with resample curve set to two samples after the repeat zone.
Is there a more efficient way of doing so?