Przeglądaj źródła

remove height property of Matrixes

Bastien Sevajol 7 lat temu
rodzic
commit
f65a188b05
2 zmienionych plików z 29 dodań i 30 usunięć
  1. 11 12
      synergine2_xyz/physics.py
  2. 18 18
      tests/test_physics.py

+ 11 - 12
synergine2_xyz/physics.py Wyświetl plik

37
 
37
 
38
 
38
 
39
 class VisibilityMatrix(object):
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
         for y in range(matrix_height):
45
         for y in range(matrix_height):
47
             x_list = []
46
             x_list = []
48
             for x in range(matrix_width):
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
         matrix[y][x] = value
56
         matrix[y][x] = value
58
         # TODO: Test if working and needed ? This is not perf friendly ...
57
         # TODO: Test if working and needed ? This is not perf friendly ...
59
         # Force shared data update
58
         # Force shared data update
66
     ) -> typing.List[typing.Tuple[int, int]]:
65
     ) -> typing.List[typing.Tuple[int, int]]:
67
         return get_line_xy_path(from_, to)
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
         values = []
69
         values = []
71
-        matrix = self.get_matrix(name, height)
70
+        matrix = self.get_matrix(name)
72
         for path_position in path_positions:
71
         for path_position in path_positions:
73
             x, y = path_position
72
             x, y = path_position
74
             values.append(matrix[y][x])
73
             values.append(matrix[y][x])

+ 18 - 18
tests/test_physics.py Wyświetl plik

8
 class TestVisibilityMatrix(BaseTest):
8
 class TestVisibilityMatrix(BaseTest):
9
     def test_initialize_empty_matrix(self):
9
     def test_initialize_empty_matrix(self):
10
         visibility = VisibilityMatrix()
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
         assert isinstance(matrix, list)
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
     def test_update_matrix(self):
19
     def test_update_matrix(self):
20
         visibility = VisibilityMatrix()
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
     def test_get_path_positions(self):
29
     def test_get_path_positions(self):
30
         visibility = VisibilityMatrix()
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
         path_positions = visibility.get_path_positions(from_=(0, 0), to=(2, 1))
35
         path_positions = visibility.get_path_positions(from_=(0, 0), to=(2, 1))
36
         assert [(0, 0), (1, 0), (2, 1)] == path_positions
36
         assert [(0, 0), (1, 0), (2, 1)] == path_positions
37
 
37
 
38
     def test_get_path_values(self):
38
     def test_get_path_values(self):
39
         visibility = VisibilityMatrix()
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
         path_positions = visibility.get_path_positions(from_=(0, 0), to=(2, 1))
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