Incidentally, while I’m at it, I figured I’d post some tips about C#. I noticed your point sorting code is incredibly inefficient, traversing and updating the entire collection for each individual next sorted point.
This is much more efficient: sorting_points_improved.gh (8.4 KB)
private void RunScript(List<Point3d> points, string coordinate, ref object sortedPoints)
{
System.Comparison<Point3d> comparer = null;
if (coordinate.Equals("x", StringComparison.OrdinalIgnoreCase))
comparer = SortX;
else if (coordinate.Equals("y", StringComparison.OrdinalIgnoreCase))
comparer = SortY;
else if (coordinate.Equals("z", StringComparison.OrdinalIgnoreCase))
comparer = SortZ;
if (comparer == null)
{
Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "'coordinate' input must be either 'x', 'y', or 'z'.");
return;
}
points.Sort(comparer);
sortedPoints = points;
}
private int SortX(Point3d a, Point3d b) { return a.X.CompareTo(b.X); }
private int SortY(Point3d a, Point3d b) { return a.Y.CompareTo(b.Y); }
private int SortZ(Point3d a, Point3d b) { return a.Z.CompareTo(b.Z); }
Do note that there’s a slight functional difference between the old and this new code. The old sorter is stable, whereas the new one is not. If you have two points with exactly equal sorting keys, their ordering in the sorted list is now pretty much random, whereas before it was not.