Collision index -1 purpose?

What is the purpose of having this index -1?

In my current definition I have a more complicated tree than in this example…

Shouldn’t this component show the indeces of collisions?

I can plug this into a List Item component and set Wrap to False, it works but doesn’t look pretty when a component goes orange…

-1 is because in that case there was no collision index.

I understood that but why isn’t it empty instead of -1?

What can you do with this -1?

It is just a way of saying it is an index that doesn’t exist or is new. My guess as to why it is -1 and not something like null is because the output type is integer list and integer lists cannot contain null values by default ( List< int > numbers = new List< int >(); ) without being a special type of nullable integer list ( List< int? > numbers = new List< int? >(); ). Or maybe the -1 is entirely intentional for some reason.

1 Like

besides this, working with nulls is highly controversial in programming. What it usually does not is telling you why its null and when it happend. Null can be also because some other things failed, while -1 clearly indicates its not returning an valid index, sort of…

So for that (technical) reason there is a Boolean output to sift the indices ?

Collision One|Many: Index of first obstacle that collides with the object

Don’t use graft to find the Index of first obstacle that collides with the object

And you can use it like this

Please. I have to use graft in my example above since in my application I have a tree as input.
I need to keep the tree structure, so don’t tell me to flatten my input!

Input:

C two line-like curves
O a tree with breps

Despite being called “Collision One/Many”, this component works with multiple inputs and provides a correct result.

Output:

I Index of first obstacle that collides with the object

path 0 both curves collide with an object
path 1 only the first curve collides
path 2 only the second curve collides

I know I can sift the indices but that’s not the question.

If someone knows an actual benefit of the -1 please reply. Thanks

This is not the problem but the answer if you want the index you must use flatten.
I think something like that is useful with animation and some cases when you want to know the first object collide

When I flatten I have no more tree structure. In my application some of the curves collide with multiple objects of different branches.

@Michael_Pryor and @TomTom have already told you why. GH uses integers, no nullable-integers. Integers are value types (rather than referenced type) an this means that if there is no number in a integer variable, it will have its default value, for integers is 0. The absence of a integer is 0. For convention in programming, index out of range are returned as -1.

But is the same thing to return -1 or return < empty> or < null> because you need to filter anyway. index >= 0 or IsNullOrEmpty(index) will give you the same information, if true then obstacles[index] collide with collider. And if you don’t need to filter and just use that index to select, you won’t be able to select with an empty/null value. But with a -1 it’s simpler.

1 Like

Thanks for this detailed explanation Dani, makes sense. I have a hard time when someone just tells me it is what it is. Now I understand. Thanks again!

Martin, You can restructure your tree after the collision; replace paths, or culling the tree statistics,item index maybe others – depending on the data structure.

and just to drive the point home to ensure you it is not a fluke, this is a common condition in many of these test and operation components which output index maps of the results.

1 Like