algorithmic modeling for Rhino
Hi all,
I m trying to recognize changed input values to a generic parameter of my .gha.
This type of input gives me GH_Structure<IGH_Goo>, where I'm ultimately checking each data element to make sure it is the same.
Firstly - is there an elegant solution to check if two trees are the same? Note that I have to compare different objects (no shallow copies).
Secondly, in case 1. does not exist: How can I avoid the reflection of the type of the object in my IGH_Goo object? Reflection is just too expensive.
private bool isTreeDifferent(GH_Structure<IGH_Goo> tree1, GH_Structure<IGH_Goo> tree2)
{
bool isTreeDifferent = false;
if (tree1.DataCount != tree2.DataCount) isTreeDifferent = true;
else
{
for (int b = 0; b < tree1.DataCount; b++)
{
IGH_Goo el1 = tree2.ElementAt(b);
IGH_Goo el2 = tree1.ElementAt(b);
FieldInfo fi1 = el1.GetType().GetField("m_value", BindingFlags.NonPublic | BindingFlags.Instance);
FieldInfo fi2 = el2.GetType().GetField("m_value", BindingFlags.NonPublic | BindingFlags.Instance);
object o1 = fi1.GetValue(el1);
object o2 = fi2.GetValue(el2);
if (!o1.Equals(o2)) isTreeDifferent = true;
}
}
return isTreeDifferent;
}
This code works but is slow.
el1.Equals(el2) always yields 'false' .. Maybe this can be fixed in a future release, or a method 'GetValue' added to IGH_Goo..!?
Thanks a lot,
best
Rob
Tags:
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
© 2024 Created by Scott Davidson. Powered by