 # DataTree with 2D Array of Points (C#)

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;
}
``````

You mean in fact: declare the Type as Array? Like:

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).

Moral: When in Rome, do as the Romans do.

2 Likes

`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>();
[...]