> For the complete documentation index, see [llms.txt](https://gitbook.testingwaters.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.testingwaters.in/geometry-1/group-curves.md).

# Group curves

Design script definition that groups a list of shuffled curves into loops…

![](https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ld8QK19sjP1I9rhLouo%2F-LfOM0xCZDUh0S5wlS43%2F-LfOa89FIT_LUAEArzpW%2FgroupCurves-1.gif?alt=media\&token=078663a7-a606-43aa-9150-dcd877f3e949)

```d
def grpCrvs(crv:var[]..[])
    {
    	dis1 = (crv.StartPoint)<1>.DistanceTo(crv<2>)==0
        ||(crv.EndPoint)<1>.DistanceTo(crv<2>)==0;
    	ind1 = List.AllIndicesOf(dis1<1>,true);
    	bln1 = true;
    	ind2 = [Imperative]
    	{
    		while (bln1)
    		{
    			cnt1 = List.Count(ind1);
    			ind1 = grpIndx(ind1);
    			cnt2 = List.Count(ind1);
    			bln1 = cnt2!=cnt1;
    		}
    		return = ind1;
    	}
    	crv1 = List.GetItemAtIndex(crv,ind2);
    	return = crv1;
    };

    def grpIndx(ind:var[]..[])
    {
    	ind1 = List.SetIntersection(ind<1>,ind<2>);
    	cnt1 = List.Count(ind1<1><2>)>0;
    	ind2 = List.FilterByBoolMask(ind,cnt1<1>)["in"];
    	ind3 = List.UniqueItems(List.Flatten(ind2<1>,-1)<1>);
    	ind4 = List.UniqueItems(List.Sort(ind3<1>));
    	return = ind4;
    };
```

![](https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ld8QK19sjP1I9rhLouo%2F-LfOM0xCZDUh0S5wlS43%2F-LfOahDqLWKFrh_ba0qJ%2FgroupCurves-2.png?alt=media\&token=001823a8-f3ed-43e5-afad-e0559cf7cc18)
