Collisions of intersecting lines

And I did it like this)

But that’s not exactly what I meant. I meant that if the distance (X) is less than the distance (Y) then the bridge continues to connect into one.