icub-tech-iit / urdf-modifiers

BSD 3-Clause "New" or "Revised" License
15 stars 4 forks source link

Fix TODOs in geometry.py #4

Closed GrmanRodriguez closed 2 years ago

GrmanRodriguez commented 2 years ago

This PR addresses the TODOs in geometry.py regarding the use of enums.

A doctring has been added to explain LimbMeta, which has been renamed to ContainsBasedOnKeyMeta for clarity.

In case it's not clear what this metaclass does, it modifies the function that is called when one checks for a if __ in __ condition. For example, in:

class MyEnum(Enum):
    APPLES = 1
    ORANGES = 2

We would get the following:

'APPLES' in MyEnum # false
1 in MyEnum # true

The ContainsBasedOnKeyMeta changes the behavior to:

'APPLES' in MyEnum # true
1 in MyEnum # false

Which is useful when, for example, trying to parse a file and turn its content into an enum.

With this change we don't really care about the value of the enums, so we can use the enum.auto() function to automatically assign values to the enums (in the end we only care about the keys).