Pair Nearest
Pair nearest while avoiding reverse pairing (unique pairs)
1
s = PolyCurve.ByJoinedCurves(List.Shuffle(
2
(Rectangle.ByWidthLength(10..20..#5,5).Translate
3
(0..40..#5,0..40..#5,0))).Explode());
4
5
def cns(cr:var[]..[], oc:var[]..[])
6
{
7
a = List.SetDifference(List.RestOfItems(cr),oc);
8
b = cr[0].DistanceTo(a);
9
c = List.SortByKey(a,b)["sorted list"];
10
return List.FirstItem(c);
11
};
12
13
s;
14
nearestPairs = [Imperative]
15
{
16
t = [];
17
i = 0;
18
while (List.Count(t)<List.Count(s))
19
{
20
d = cns(List.ShiftIndices(s,-i),t);
21
t = List.AddItemToEnd(d,t);
22
i = i + 1;
23
}
24
return List.Transpose([s,t]);
25
};
Copied!
nearestPairs.zip
3KB
Binary
Dynamo version 2.8
Last modified 1yr ago
Copy link