Skip to content
Snippets Groups Projects
Commit 8ca6ebac authored by HENDRIX-ZT2's avatar HENDRIX-ZT2
Browse files

Refactor - extract argmax

parent 870c23b5
No related branches found
No related tags found
No related merge requests found
...@@ -235,6 +235,11 @@ class Armature: ...@@ -235,6 +235,11 @@ class Armature:
# return string identifiers # return string identifiers
return ids[forward_ind], ids[up_ind] return ids[forward_ind], ids[up_ind]
@staticmethod
def argmax(values):
"""Return the index of the max value in values"""
return max(zip(values, range(len(values))))[1]
def get_forward_axis(self, n_bone, axis_indices): def get_forward_axis(self, n_bone, axis_indices):
"""Helper function to get the forward axis of a bone""" """Helper function to get the forward axis of a bone"""
# check that n_block is indeed a bone # check that n_block is indeed a bone
...@@ -242,8 +247,8 @@ class Armature: ...@@ -242,8 +247,8 @@ class Armature:
return None return None
trans = n_bone.translation.as_tuple() trans = n_bone.translation.as_tuple()
trans_abs = tuple(abs(v) for v in trans) trans_abs = tuple(abs(v) for v in trans)
# do argmax # get the index of the coordinate with the biggest absolute value
max_coord_ind = max(zip(trans_abs, range(len(trans_abs))))[1] max_coord_ind = self.argmax(trans_abs)
# now check the sign # now check the sign
actual_value = trans[max_coord_ind] actual_value = trans[max_coord_ind]
# handle sign accordingly so negative indices map to the negative identifiers in list # handle sign accordingly so negative indices map to the negative identifiers in list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment