Browse Source

visibility: implement path and values functions

Bastien Sevajol 6 years ago
parent
commit
d8f8639d4f
2 changed files with 18 additions and 4 deletions
  1. 16 0
      synergine2_xyz/physics.py
  2. 2 4
      tests/test_physics.py

+ 16 - 0
synergine2_xyz/physics.py View File

8
 from synergine2.share import shared
8
 from synergine2.share import shared
9
 from synergine2_xyz.map import TMXMap, XYZTile
9
 from synergine2_xyz.map import TMXMap, XYZTile
10
 from synergine2_xyz.subjects import XYZSubject
10
 from synergine2_xyz.subjects import XYZSubject
11
+from synergine2_xyz.utils import get_line_xy_path
11
 from synergine2_xyz.xyz import get_neighbor_positions
12
 from synergine2_xyz.xyz import get_neighbor_positions
12
 
13
 
13
 
14
 
58
         # Force shared data update
59
         # Force shared data update
59
         self._matrixes = dict(self._matrixes)
60
         self._matrixes = dict(self._matrixes)
60
 
61
 
62
+    def get_path_positions(
63
+        self,
64
+        from_: typing.Tuple[int, int],
65
+        to: typing.Tuple[int, int],
66
+    ) -> typing.List[typing.Tuple[int, int]]:
67
+        return get_line_xy_path(from_, to)
68
+
69
+    def get_values_for_path(self, name: str, height: float, path_positions: typing.List[typing.Tuple[int, int]]):
70
+        values = []
71
+        matrix = self.get_matrix(name, height)
72
+        for path_position in path_positions:
73
+            x, y = path_position
74
+            values.append(matrix[y][x])
75
+        return values
76
+
61
 
77
 
62
 class Physics(object):
78
 class Physics(object):
63
     visibility_matrix = VisibilityMatrix
79
     visibility_matrix = VisibilityMatrix

+ 2 - 4
tests/test_physics.py View File

26
         assert [0.7, 0.0, 0.0] == matrix[0]
26
         assert [0.7, 0.0, 0.0] == matrix[0]
27
         assert [0.0, 0.0, 0.5] == matrix[1]
27
         assert [0.0, 0.0, 0.5] == matrix[1]
28
 
28
 
29
-    @pytest.mark.skip(reason='Not implemented yet')
30
     def test_get_path_positions(self):
29
     def test_get_path_positions(self):
31
         visibility = VisibilityMatrix()
30
         visibility = VisibilityMatrix()
32
         visibility.initialize_empty_matrix('testing', height=0.5, matrix_width=3, matrix_height=2)
31
         visibility.initialize_empty_matrix('testing', height=0.5, matrix_width=3, matrix_height=2)
34
         visibility.update_matrix('testing', height=0.5, x=0, y=0, value=0.7)
33
         visibility.update_matrix('testing', height=0.5, x=0, y=0, value=0.7)
35
 
34
 
36
         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))
37
-        assert [(0, 0), (0, 1), (1, 2)] == path_positions
36
+        assert [(0, 0), (1, 0), (2, 1)] == path_positions
38
 
37
 
39
-    @pytest.mark.skip(reason='Not implemented yet')
40
     def test_get_path_values(self):
38
     def test_get_path_values(self):
41
         visibility = VisibilityMatrix()
39
         visibility = VisibilityMatrix()
42
         visibility.initialize_empty_matrix('testing', height=0.5, matrix_width=3, matrix_height=2)
40
         visibility.initialize_empty_matrix('testing', height=0.5, matrix_width=3, matrix_height=2)
44
         visibility.update_matrix('testing', height=0.5, x=0, y=0, value=0.7)
42
         visibility.update_matrix('testing', height=0.5, x=0, y=0, value=0.7)
45
 
43
 
46
         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))
47
-        path_values = visibility.get_values_for_path(path_positions=path_positions)
45
+        path_values = visibility.get_values_for_path('testing', height=0.5, path_positions=path_positions)
48
         assert [0.7, 0.0, 0.5] == path_values
46
         assert [0.7, 0.0, 0.5] == path_values