Order of joined curves and their pairing

I have three branches of rectangles, and I want to join their top and bottom line segments, respectively, into two parallel curves, and pair them if they belong to the same cluster of rectangles.

The workflow attached below does the above by adding the rectangles one by one (using the item selector (from the Ladybug Tools) highlighted in red in the first image below). (The custom preview lineweights component is from the HUMAN package).

It works for the first 47 rectangles (see the 2nd image below). However, it breaks when coming to the 48th, 49th, 54th, 58th…and many other rectangles, and the paring of the joined curves are not correct (see the 3nd image below). The error doesn’t seem to have any pattern so far.

I’m not sure what is causing this issue, and help is greatly appreciate.

problem with order of joined curves and their paring.gh (32.1 KB)

I tried a different approach, but still got error when moving to rectangle-pair 48…

problem with order of joined curves and their paring _v02.gh (33.1 KB)

Appreciate if anyone can kindly take a look of the issue posted above and advise the source of the problem. Thank you.


problem with order of joined curves and their paring _v02_re.gh (15.0 KB)