Sorting Orthogonal Edges of Planar Surfaces... Need Tree Help

I’m trying to write a definition that sorts the edges of planar surfaces into North, South, East, West, Up and Down, like this:


I’m sorting the edges by which axis they’re parallel to, then flipping them all so their start and end points are aligned. Then, using a cluster that @DanielPiker and @Joseph_Oster recently showed me, I pick all the concave vertices, and use set components to sort and derive the start and end points of each of the six categories of lines.

And the points I get are the ones I want. In a simplified example, here are the starts and end of West lines:

But, of course, when I try to connect those points to recreate the lines, they’re not in the right order in their trees, and I get a mess:

Here is what I need help with:
This is my definition so far: Planar Surface Edge NSEWUD (120.1 KB)

  1. Is my overall strategy too complicated? Is there an easier way to accomplish my goal, with less spaghetti? Intuitively I’d thing the big sort would be necessary simply because of all the combinations and permutations, but maybe I’m wrong?

  2. How to I re-order the trees so those start and end points match up with each other when I try to re-create the lines? I tried trimming trees, it worked on only one set of points, so I assumed it was just luck and not the beginning of a universal fix. Can I just tweak the trees or do I need to reference geometry earlier in the definition? If so, how do I do that?

FYI, in my definition, every point labeled with a + is an end, with a - is a start. And all lines are flipped so that starts are in the negative unit vector direction from the start.


What do the concave vertices have to do with this?


Ah, I see that @HS_Kim has it already. Doesn’t look too complicated.

How about using Member Index?

Planar Surface Edge NSEWUD (31.6 KB)


Ok. Can I get a hint for what else I might try?

Lol. Good grief I wasted a lot of time. Thanks!