Browse Source

get_values_for_path_as_dict

Bastien Sevajol 6 years ago
parent
commit
36d750ffb8
1 changed files with 14 additions and 0 deletions
  1. 14 0
      synergine2_xyz/physics.py

+ 14 - 0
synergine2_xyz/physics.py View File

96
                 values.append(matrix[y][x][value_name_position])
96
                 values.append(matrix[y][x][value_name_position])
97
         return values
97
         return values
98
 
98
 
99
+    def get_values_for_path_as_dict(
100
+        self,
101
+        name: str,
102
+        path_positions: typing.List[typing.Tuple[int, int]],
103
+        value_name: str=None,
104
+    ) -> typing.Dict[int, typing.Dict[int, typing.Any]]:
105
+        values_as_dict = {}  # type: typing.Dict[int, typing.Dict[int, typing.Any]]
106
+        values = self.get_values_for_path(name, path_positions, value_name)
107
+
108
+        for position, value in zip(path_positions, values):
109
+            values_as_dict.setdefault(position[0], {})[position[1]] = value
110
+
111
+        return values_as_dict
112
+
99
     def get_value(self, matrix_name: str, x: int, y: int, value_name: str) -> float:
113
     def get_value(self, matrix_name: str, x: int, y: int, value_name: str) -> float:
100
         matrix = self.get_matrix(matrix_name)
114
         matrix = self.get_matrix(matrix_name)
101
         values = matrix[y][x]
115
         values = matrix[y][x]