algorithmic modeling for Rhino
Hi,
I have a question below:
This kind of situation occurs me from time to time an mapping one list to nested one makes the script reading confusing as I usually introduce 3rd list that looks like this:
List<int[]> mapping = new List<int[]>{ new int[2]{0,0},new int[2]{0,1} ... new int[2]{n,n} };
When first integer is index of list index, and second integer is index of element inside list.
When I want to select 5th element from nested list it looks like this:
Object NthElement = NestedList[ mapping[5][0] ] mapping[5][1];
Any suggestions for selecting nth element from nested list without introducing this mapping thing would be very helpful.
Thank you.
Tags:
Thank you for a reply.
I was also thinking datatrees.
And for general c#. The similar solution would be only something like dictionaries?
Following your example:
DataTree<int> tree = new DataTree<int>();
tree.Add(0, new GH_Path(0));
tree.Add(1, new GH_Path(0));
tree.Add(2, new GH_Path(1));
tree.Add(3, new GH_Path(1));
What I want to know is what is the index of tree.Branch(1)[0] in a flattened list, which is 2 in this case?
It looks like the only way to know the index of tree.Branch(1)[0] in a flattened list which is 2 in this case. Is to loop through each branch and count items like this:
int count = 0;
for (int i = 0; i < tree.BranchCount; i++)
{
for (int j = 0; j < tree.Branch(i).Count; j++){
Rhino.RhinoApp.WriteLine( (count + j).ToString() + "index of datatree in a flattened list" );
}
count += v.Branch(i).Count; //Count indexes in a "flattened list" I was looking for this property but it seems that it is possible to do this through looping
}
if there is a property to know the index without counting, it would be good to know.
But then how dataTrees are better from simple arrays?
The only thing I would like to do:
I have a datatree or array.
And I know an item indices for instance: tree.Branch(i)[j]
The property or method I am searching for is how to know index of item in a flattened list when knowing only i and j indices in array.
Looping is confusing, but works well after multiple tries.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by