Procházet zdrojové kódy

visibility: implement path and values functions

Bastien Sevajol před 6 roky
rodič
revize
d8f8639d4f
2 změnil soubory, kde provedl 18 přidání a 4 odebrání
  1. 16 0
      synergine2_xyz/physics.py
  2. 2 4
      tests/test_physics.py

+ 16 - 0
synergine2_xyz/physics.py Zobrazit soubor

@@ -8,6 +8,7 @@ from synergine2.config import Config
8 8
 from synergine2.share import shared
9 9
 from synergine2_xyz.map import TMXMap, XYZTile
10 10
 from synergine2_xyz.subjects import XYZSubject
11
+from synergine2_xyz.utils import get_line_xy_path
11 12
 from synergine2_xyz.xyz import get_neighbor_positions
12 13
 
13 14
 
@@ -58,6 +59,21 @@ class VisibilityMatrix(object):
58 59
         # Force shared data update
59 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 78
 class Physics(object):
63 79
     visibility_matrix = VisibilityMatrix

+ 2 - 4
tests/test_physics.py Zobrazit soubor

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