It is common to store objects or information about them in randomly-indexable arrays, and then to support maximum-performance selection by allowing the index to be used. We want these arrays indexable by simple ints for speed, but this quickly leads to APIs in which there are multiple int arguments in a function call, each intended to select a different kind of object. A common error when there is a series of identical argument types is to put them in the wrong order. To avoid that, we define unique index types here for accessing each category to help stay out of trouble.
More...
It is common to store objects or information about them in randomly-indexable arrays, and then to support maximum-performance selection by allowing the index to be used. We want these arrays indexable by simple ints for speed, but this quickly leads to APIs in which there are multiple int arguments in a function call, each intended to select a different kind of object. A common error when there is a series of identical argument types is to put them in the wrong order. To avoid that, we define unique index types here for accessing each category to help stay out of trouble.
A unique index type is just a type-safe non-negative int, augmented with a "NaN" value called InvalidBLAH where BLAH is the type name. For most uses it will behave like an int, and it has an implicit conversion to int. Importantly though, it has no implicit conversion from int so you can't pass a plain int or any other Index type to an argument expecting a certain Index type.
◆ MobodIndex
This is the approved abbeviation for MobilizedBodyIndex. Feel free to use it if you get tired of typing or seeing the full name.
◆ GroundIndex()
This is the MobilizedBodyIndex corresponding to the unique Ground body; its index is always zero.