Grasshopper

algorithmic modeling for Rhino

Hey guys, I think I just have ran into weird behavior of insert list component. Provided a list of indices where consecutive numbers of indices are 3 4 5. However, the component inserts them skipping through by one each time. In my understanding in the final list under indices 3 4 5 should be zeros. Is it a bug or I miss something? Thanks in advance.

Views: 3416

Replies to This Discussion

I seems not like a bug to me. Take a look at the attached screengrab.

In my understanding it supposed to be this way:

If I'm wrong, then I'm really confused. Can you please explain me the logic? Thanks

Thanks for explaining, although I still can't wrap my head around it. IMHO it is very confusing behavior. When I specify indices, I expect to see 0 at those indices in the final list. If I specify indices 3 4 5, in the final list there should be 0 at indices 3 4 5 in the final list. For example, this is the case in Javascript.

Indeed very confusing, plus it seems to stack on multiple inserts, which confuses it even further. For example the 0 that was supposed to be inserted at nr 3 of the list got inserted at nr 4 because you previously inserted a 0 at nr 1.....

I have no idea what my item index is doing in the example below....

If Wrap=True, indices beyond the list will be cycled back into it. You can insert without wrapping using any index between and including zero and the length of the list.

Insertion works in a reversed fashion. First the indices are wrapped into the valid domain (assuming W=True), then, starting at the highest index, the first item is inserted into the existing list. Then the item with the second highest index is inserted into the list and so on. This means that if you first insert an item at index=8 and then insert an item at index=6, the first item will be bumped up to index=9.

If you want to add three items to the end of your list, the indices you're after are 11, 11, and 11.

Remember that this component isn't about constructing lists, it's about inserting items into an existing list. If you were to only insert a single item, then the behaviour is fairly obvious, the confusing part here is how to deal with inserting multiple items. There's a number of different ways you could approach this:

  1. Item+Index pairs are inserted in the order they are specified into a list. The indices as specified are not adjusted to take into account the fact that the list grows during this process. 
  2. Item+Index pairs are inserted in sorted order (lowest index first). The indices as specified are not adjusted to take into account the fact that the list grows during this process. 
  3. Item+Index pairs are inserted in sorted order, and the remaining indices are incremented whenever they happen to be at or above the current insertion index.

I chose #3 because I didn't want the order in which items were provided to matter, and because I though that insertion indices were most likely created through some sort of algorithm. For this algorithm to take into account the changes to the list during the insertion process seemed like a lot of responsibility to dump onto the user.

For example imagine you have a collection of values and you want to insert an item after a specific occurrence of one value, and a different item before an occurrence of another value. To make it more specific, imagine we have a list of textual characters {"a", "+", "b", " ", "=", " ", "c"}, which is just the individual characters in "a+b = c". We want to modify this to look like "a + b != c". That means inserting a space before the "+", another space after the "+", and an exclamation mark before the "=". It's much easier to figure out the indices you need within the current list than it would be to figure out the adjusted indices in the final list.

Of course it could be very useful to have a list constructor component as well, where you can specify the target indices of various items. I'm more than happy to add such a component, but I'd like to know how you expect it to behave. Do you start with an existing list or is it just individual items? What happens when two items have the same index, does the earlier one get overwritten with the later one?

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service