Join only curves that end tangent to each other

Hi all,

I have a set of curves as shown. I’m looking to join only those curves that are continuously tangent with each other, so the joined curves will flow without “sharp” corners (in situations where multiple curves would join tangent to each other, it doesn’t matter to me which one it ends up picking). So far I’ve found the starting and ending tangencies of the curves as vectors (in the attached file) intending to check the equality of the outward-aiming vectors against the inward-aiming vectors, but I can’t figure out how to structure the data in a way that facilitates the curves joining without repeating segments. Does anyone have ideas? Thanks in advance for any help.

EDIT: On reflecting on the problem I think I might be trying to brute-force something that would be better solved at maybe the coding level as described by David here:

Does anyone know of such a tool?

tangent curve joiner WIP (14.8 KB)