Kaynağa Gözat

Add check of possible position or not

Bastien Sevajol 8 yıl önce
ebeveyn
işleme
8978ffdf95
1 değiştirilmiş dosya ile 32 ekleme ve 0 silme
  1. 32 0
      synergine2/xyz.py

+ 32 - 0
synergine2/xyz.py Dosyayı Görüntüle

3
 from math import degrees
3
 from math import degrees
4
 from math import acos
4
 from math import acos
5
 
5
 
6
+from synergine2.exceptions import SynergineException
6
 from synergine2.simulation import SubjectMechanism, Subjects, Subject
7
 from synergine2.simulation import SubjectMechanism, Subjects, Subject
7
 from synergine2.simulation import Simulation as BaseSimulation
8
 from synergine2.simulation import Simulation as BaseSimulation
8
 
9
 
81
 }
82
 }
82
 
83
 
83
 
84
 
85
+class XYZException(SynergineException):
86
+    pass
87
+
88
+
89
+class PositionNotPossible(XYZException):
90
+    pass
91
+
92
+
84
 def get_degree_from_north(a, b):
93
 def get_degree_from_north(a, b):
85
     if a == b:
94
     if a == b:
86
         return 0
95
         return 0
130
     direction_round_decimals = 0
139
     direction_round_decimals = 0
131
     distance_round_decimals = 2
140
     distance_round_decimals = 2
132
 
141
 
142
+    def have_to_check_position_is_possible(self) -> bool:
143
+        return True
144
+
133
     def get_for_position(
145
     def get_for_position(
134
             self,
146
             self,
135
             position,
147
             position,
145
                 if subject == exclude_subject:
157
                 if subject == exclude_subject:
146
                     continue
158
                     continue
147
 
159
 
160
+                if self.have_to_check_position_is_possible() and not simulation.is_possible_position(subject.position):
161
+                    continue
162
+
148
                 distance = round(
163
                 distance = round(
149
                     self.get_distance_of(
164
                     self.get_distance_of(
150
                         position=position,
165
                         position=position,
196
         # TODO: init xyz with given list
211
         # TODO: init xyz with given list
197
         self.xyz = {}
212
         self.xyz = {}
198
 
213
 
214
+    def have_to_check_position_is_possible(self) -> bool:
215
+        return True
216
+
199
     def remove(self, value: XYZSubjectMixin):
217
     def remove(self, value: XYZSubjectMixin):
200
         super().remove(value)
218
         super().remove(value)
201
         del self.xyz[value.position]
219
         del self.xyz[value.position]
202
 
220
 
203
     def append(self, p_object: XYZSubjectMixin):
221
     def append(self, p_object: XYZSubjectMixin):
204
         super().append(p_object)
222
         super().append(p_object)
223
+
224
+        if self.have_to_check_position_is_possible() \
225
+           and not self.simulation.is_possible_subject_position(p_object, p_object.position):
226
+            raise PositionNotPossible('Position {} for {} is not possible'.format(
227
+                p_object.position,
228
+                p_object,
229
+            ))
230
+
205
         self.xyz[p_object.position] = p_object
231
         self.xyz[p_object.position] = p_object
206
 
232
 
207
 
233
 
208
 class XYZSimulation(BaseSimulation):
234
 class XYZSimulation(BaseSimulation):
209
     accepted_subject_class = XYZSubjects
235
     accepted_subject_class = XYZSubjects
210
 
236
 
237
+    def is_possible_subject_position(self, subject: XYZSubjectMixin, position: tuple) -> bool:
238
+        return self.is_possible_position(position)
239
+
240
+    def is_possible_position(self, position: tuple) -> bool:
241
+        return True
242
+
211
 
243
 
212
 def get_direction_from_north_degree(degree: float):
244
 def get_direction_from_north_degree(degree: float):
213
     for range, direction in DIRECTION_FROM_NORTH_DEGREES.items():
245
     for range, direction in DIRECTION_FROM_NORTH_DEGREES.items():