瀏覽代碼

remove height property of Matrixes

Bastien Sevajol 6 年之前
父節點
當前提交
f65a188b05
共有 2 個文件被更改,包括 29 次插入30 次删除
  1. 11 12
      synergine2_xyz/physics.py
  2. 18 18
      tests/test_physics.py

+ 11 - 12
synergine2_xyz/physics.py 查看文件

@@ -37,23 +37,22 @@ class MoveCostComputer(object):
37 37
 
38 38
 
39 39
 class VisibilityMatrix(object):
40
-    _matrixes = shared.create('matrixes', value=lambda: {})  # type: typing.Dict[str, typing.Dict[float, typing.List[typing.List[float]]]]  # nopep8
40
+    _matrixes = shared.create('matrixes', value=lambda: {})  # type: typing.Dict[str, typing.List[typing.List[tuple]]]
41 41
 
42
-    def initialize_empty_matrix(self, name: str, height: float, matrix_width: int, matrix_height: int) -> None:
43
-        self._matrixes[name] = {}
44
-        self._matrixes[name][height] = []
42
+    def initialize_empty_matrix(self, name: str, matrix_width: int, matrix_height: int) -> None:
43
+        self._matrixes[name] = []
45 44
 
46 45
         for y in range(matrix_height):
47 46
             x_list = []
48 47
             for x in range(matrix_width):
49
-                x_list.append(0.0)
50
-            self._matrixes[name][height].append(x_list)
48
+                x_list.append((0.0,))
49
+            self._matrixes[name].append(x_list)
51 50
 
52
-    def get_matrix(self, name: str, height: float) -> typing.List[typing.List[float]]:
53
-        return self._matrixes[name][height]
51
+    def get_matrix(self, name: str) -> typing.List[typing.List[tuple]]:
52
+        return self._matrixes[name]
54 53
 
55
-    def update_matrix(self, name: str, height: float, x: int, y: int, value: float) -> None:
56
-        matrix = self.get_matrix(name, height)
54
+    def update_matrix(self, name: str, x: int, y: int, value: tuple) -> None:
55
+        matrix = self.get_matrix(name)
57 56
         matrix[y][x] = value
58 57
         # TODO: Test if working and needed ? This is not perf friendly ...
59 58
         # Force shared data update
@@ -66,9 +65,9 @@ class VisibilityMatrix(object):
66 65
     ) -> typing.List[typing.Tuple[int, int]]:
67 66
         return get_line_xy_path(from_, to)
68 67
 
69
-    def get_values_for_path(self, name: str, height: float, path_positions: typing.List[typing.Tuple[int, int]]):
68
+    def get_values_for_path(self, name: str, path_positions: typing.List[typing.Tuple[int, int]]):
70 69
         values = []
71
-        matrix = self.get_matrix(name, height)
70
+        matrix = self.get_matrix(name)
72 71
         for path_position in path_positions:
73 72
             x, y = path_position
74 73
             values.append(matrix[y][x])

+ 18 - 18
tests/test_physics.py 查看文件

@@ -8,39 +8,39 @@ from tests import BaseTest
8 8
 class TestVisibilityMatrix(BaseTest):
9 9
     def test_initialize_empty_matrix(self):
10 10
         visibility = VisibilityMatrix()
11
-        visibility.initialize_empty_matrix('testing', height=0.5, matrix_width=3, matrix_height=2)
12
-        matrix = visibility.get_matrix('testing', height=0.5)
11
+        visibility.initialize_empty_matrix('testing', matrix_width=3, matrix_height=2)
12
+        matrix = visibility.get_matrix('testing')
13 13
 
14 14
         assert isinstance(matrix, list)
15 15
 
16
-        assert [0.0, 0.0, 0.0] == matrix[0]
17
-        assert [0.0, 0.0, 0.0] == matrix[1]
16
+        assert [(0.0,), (0.0,), (0.0,)] == matrix[0]
17
+        assert [(0.0,), (0.0,), (0.0,)] == matrix[1]
18 18
 
19 19
     def test_update_matrix(self):
20 20
         visibility = VisibilityMatrix()
21
-        visibility.initialize_empty_matrix('testing', height=0.5, matrix_width=3, matrix_height=2)
22
-        visibility.update_matrix('testing', height=0.5, x=2, y=1, value=0.5)
23
-        visibility.update_matrix('testing', height=0.5, x=0, y=0, value=0.7)
24
-        matrix = visibility.get_matrix('testing', height=0.5)
21
+        visibility.initialize_empty_matrix('testing', matrix_width=3, matrix_height=2)
22
+        visibility.update_matrix('testing', x=2, y=1, value=(0.5,))
23
+        visibility.update_matrix('testing', x=0, y=0, value=(0.7,))
24
+        matrix = visibility.get_matrix('testing')
25 25
 
26
-        assert [0.7, 0.0, 0.0] == matrix[0]
27
-        assert [0.0, 0.0, 0.5] == matrix[1]
26
+        assert [(0.7,), (0.0,), (0.0,)] == matrix[0]
27
+        assert [(0.0,), (0.0,), (0.5,)] == matrix[1]
28 28
 
29 29
     def test_get_path_positions(self):
30 30
         visibility = VisibilityMatrix()
31
-        visibility.initialize_empty_matrix('testing', height=0.5, matrix_width=3, matrix_height=2)
32
-        visibility.update_matrix('testing', height=0.5, x=2, y=1, value=0.5)
33
-        visibility.update_matrix('testing', height=0.5, x=0, y=0, value=0.7)
31
+        visibility.initialize_empty_matrix('testing', matrix_width=3, matrix_height=2)
32
+        visibility.update_matrix('testing', x=2, y=1, value=(0.5,))
33
+        visibility.update_matrix('testing', x=0, y=0, value=(0.7,))
34 34
 
35 35
         path_positions = visibility.get_path_positions(from_=(0, 0), to=(2, 1))
36 36
         assert [(0, 0), (1, 0), (2, 1)] == path_positions
37 37
 
38 38
     def test_get_path_values(self):
39 39
         visibility = VisibilityMatrix()
40
-        visibility.initialize_empty_matrix('testing', height=0.5, matrix_width=3, matrix_height=2)
41
-        visibility.update_matrix('testing', height=0.5, x=2, y=1, value=0.5)
42
-        visibility.update_matrix('testing', height=0.5, x=0, y=0, value=0.7)
40
+        visibility.initialize_empty_matrix('testing', matrix_width=3, matrix_height=2)
41
+        visibility.update_matrix('testing', x=2, y=1, value=(0.5,))
42
+        visibility.update_matrix('testing', x=0, y=0, value=(0.7,))
43 43
 
44 44
         path_positions = visibility.get_path_positions(from_=(0, 0), to=(2, 1))
45
-        path_values = visibility.get_values_for_path('testing', height=0.5, path_positions=path_positions)
46
-        assert [0.7, 0.0, 0.5] == path_values
45
+        path_values = visibility.get_values_for_path('testing', path_positions=path_positions)
46
+        assert [(0.7,), (0.0,), (0.5,)] == path_values