I’m trying to see if its possible to combine a data tree with a 2D array of points. This is just to scratch an itch. I know its better/easier without using the array, so its probably an impractical question.
Is it possible to combine the i,j style for loop of x,y locations with a DataTree?
There were a couple of similar questions like this, but not quite the same (at least I think).
{
// algo
Interval uDomain = S.Domain(0);
Interval vDomain = S.Domain(1);
double Ustep = uDomain.Length / U; // 0 = U
double Vstep = vDomain.Length / V; // 1 = V
DataTree<Point3d>[,] pts = new DataTree<Point3d>[U + 1, V + 1];
for (int i = 0; i < U + 1; i++)
{
double u = Math.Round(uDomain.T0, tol) + (Ustep * i);
GH_Path paths = new GH_Path(i);
for (int j = 0; j < V + 1; j++)
{
double v = Math.Round(vDomain.T0, tol) + (Vstep * j);
SurfaceCurvature sc = S.CurvatureAt(u, v);
pts[i,j].Add(sc.Point, paths); //this line gets the error
}
}
// output
P = pts;
}
If yes then anything is possible (as far as it makes some sort of sense). In fact … er … hmm … a DT is a “kind” of Dictionary of Lists (kinda) meaning the obvious (since a List is a collection that could contain anything - like cats, dogs, aliens, arrays of proper Ducatis etc etc).
But why mix onions with bananas? (unless a Class is required for defining Properties that you want for some sort of stuff or do LINQ things … blah, blah). Plus have in mind that you must unbox a similar Tree after creation (that doesn’t make any sense at all).
DataTree<T> is already (kind of) a multidimensional collection! The Gh_Path acts as the index or address within tree data-structure.
What you wrote is I want a matrix of (Point3d) trees.
Which doesn’t make sense. Probably you want a single tree, structured like a matrix.
var pts = new DataTree<Point3d>();
[...]
pts.Add(sc.Point, new GH_Path(i, j))
Of course, for each tree item (=node), you can also store a matrix of Point3d inside. But you will need to decompose it later, because Grasshopper cannot deal with that properly. In this case, I would just create a custom data structure for the sake of readability.