class NodePath(object): @property def average_safety_level(self): if self.node_count != 0: return sum([node.safety_level.level_value for node in self.nodes]) / self.node_count else: return 0 @property def average_obstacle_safety_level(self): if self.node_count != 0: return sum([node.obstacle_safety_level.level_value for node in self.nodes]) / self.node_count else: return 0 @property def drawable_path(self): return self._path @property def nodes(self): return [vertex.attached_object for vertex in self._path.vertices] @property def length(self): return self._path.length @property def node_count(self): return self._path.vertex_count def __init__(self, nodes): self._create_path(nodes) def __getitem__(self, index): return self._path.vertices[index].attached_object def _create_path(self, nodes): self._path = Path() for node in nodes: self.append_node(node) def append_node(self, node): vertex = node.position.clone() vertex.attached_object = node self._path.add_vertex(vertex) def simplify(self, start_node_index, end_node_index): self._path.remove(start_node_index, end_node_index, exclusive = True)
def _create_path(self, segment_count, enclosing_circle, base_angle): path = Path() for angle in range(base_angle, base_angle + 360, int(360 / segment_count)): path.add_vertex(enclosing_circle.position_on_arc(angle)) path.close() return path
def _create_path(self, nodes): self._path = Path() for node in nodes: self.append_node(node)