Пример #1
0
    def _calc_view_distance(self, space: Space, base_x: float, base_y: float) -> float:
        """
        Calculate the distance between the base point, represented by base_x and base_y, and the furthest
        viewable object. If no object is in sight, return None.
        :param space: which holds the visible objects.
        :param base_x: x coordinate of the base point.
        :param base_y: y coordinate of the base point.
        :return: a floating point value representing the distance if object is viewable, else None.
        """

        x, y = self._calc_ray_cast_point(base_x, base_y)

        query = space.segment_query_first((base_x, base_y), (x, y), 1, ShapeFilter())
        if query:
            return -self.sensor_half_height + distance_between_points(base_x,
                                                                      base_y,
                                                                      query.point.x,
                                                                      query.point.y)
        else:
            return None
 def _calc_view_distance(self, space: Space, base_x: float,
                         base_y: float) -> Optional[float]:
     """
     Calculate the distance between the base point, represented by base_x and base_y, and the furthest
     viewable object. If no object is in sight, return None.
     :param space: which holds the visible objects.
     :param base_x: x coordinate of the base point.
     :param base_y: y coordinate of the base point.
     :return: a floating point value representing the distance if object is viewable, else None.
     """
     x, y = self._calc_ray_cast_point(base_x, base_y)
     if DEBUG:
         line = create_line(x, y, base_x, base_y, RED, 5)
         self.robot.debug_shapes.append(line)
     query = space.segment_query_first((base_x, base_y), (x, y), 1,
                                       self.shape.filter)
     if query:
         return -self.sensor_half_height + distance_between_points(
             base_x, base_y, query.point.x, query.point.y)
     return None