Ejemplo n.º 1
0
def find_best_pair_center(msg):
    global current_position
    red = ColorRGBA(1.0, 0, 0, 1.0)
    green = ColorRGBA(0, 1.0, 0, 1.0)
    green_buoy = []
    red_buoy = []
    ans = []
    min_dist = 100

    for marker in msg.markers:
        if (marker.color == red):
            red_buoy.append([marker.pose.position.x, marker.pose.position.y])
        if (marker.color == green):
            green_buoy.append([marker.pose.position.x, marker.pose.position.y])
    for i in red_buoy:
        for j in green_buoy:
            dist = distance(i, j)
            if (dist > 1.0 and dist < channel_width
                    and distance(current_position, center_of_points(
                        (i, j))) < min_dist):
                ans = [i, j]

    if (not ans):
        return [False, [0, 0]]
    else:
        return [True, ans]
Ejemplo n.º 2
0
def find_closest_buoy(msg, color):
    global current_position, green_buoy, red_buoy
    buoy = []
    for marker in msg.markers:
        if ((not buoy) and (marker.color == color)):
            buoy = [marker.pose.position.x, marker.pose.position.y]
        elif (buoy):
            if (distance((marker.pose.position.x, marker.pose.position.y),
                         current_position) < distance(buoy, current_position)
                    and (marker.color == color)):
                buoy = [marker.pose.position.x, marker.pose.position.y]

    if (not buoy):
        return [False, [0, 0]]
    else:
        return [True, buoy]
Ejemplo n.º 3
0
def find_closest_buoy(msg,color):
    global current_position,green_buoy,red_buoy
    buoy = []
    for marker in msg.markers:
        if ((not buoy) and (marker.color == color)):
            buoy = [marker.pose.position.x,marker.pose.position.y]
        elif (buoy):
            if (distance((marker.pose.position.x,marker.pose.position.y),current_position) < distance(buoy,current_position) and (marker.color == color)):
                buoy = [marker.pose.position.x,marker.pose.position.y]
    
    if (not buoy):
        return [False,[0,0]]
    else:
        return [True,buoy]
Ejemplo n.º 4
0
def find_best_pair_center(msg):
    global current_position
    red = ColorRGBA(1.0,0,0,1.0)
    green = ColorRGBA(0,1.0,0,1.0)
    green_buoy = []
    red_buoy = []
    ans = []
    min_dist = 100
    
    for marker in msg.markers:
        if (marker.color == red):
            red_buoy.append([marker.pose.position.x,marker.pose.position.y])
        if (marker.color == green):
            green_buoy.append([marker.pose.position.x,marker.pose.position.y])
    for i in red_buoy:
        for j in green_buoy:
            dist = distance(i,j)
            if (dist > 1.0 and dist < channel_width and distance(current_position,center_of_points((i,j))) < min_dist):
                ans = [i,j]
    
    if (not ans):
        return [False,[0,0]]
    else:
        return [True,ans]
Ejemplo n.º 5
0
    def enter_cursor_mode(self):
        player = self.container.player

        if self.container.input_mode is GameState.MAIN_LOOK:
            x = player[PositionComponent].x
            y = player[PositionComponent].y
        elif self.container.input_mode is GameState.MAIN_FIRE:
            entities = [
                e for e in self.container.entities
                if CombatComponent in e and PositionComponent in e
                and VisibleComponent in e and e is not self.container.player
            ]
            if len(entities) > 0:
                entities.sort(key=lambda e: distance(self.container.player, e))
                entity = entities[0]
                x = entity[PositionComponent].x
                y = entity[PositionComponent].y
            else:
                x = player[PositionComponent].x
                y = player[PositionComponent].y
        elif self.container.input_mode is GameState.MAIN_SWAP:
            entities = [
                e for e in self.container.entities
                if PositionComponent in e and RandomNumberComponent in e
                and VisibleComponent in e and e is not self.container.player
            ]
            if len(entities) > 0:
                entities.sort(key=lambda e: e[RandomNumberComponent].number)
                entity = entities[0]
                x = entity[PositionComponent].x
                y = entity[PositionComponent].y
            else:
                x = player[PositionComponent].x
                y = player[PositionComponent].y
        else:
            assert False

        self.container.entities.append(make_cursor(x, y))
        self.check_target()
Ejemplo n.º 6
0
 def get_distance_to_tu(self, tu_location):
     #location of transportation unit
     return helper_functions.distance(
         (tu_location[0], tu_location[1]),
         (self.start_lat, self.start_lon)) * self.factor_ride
Ejemplo n.º 7
0
 def get_distance_ride(self):
     return helper_functions.distance(
         (self.start_lat, self.start_lon),
         (self.end_lat, self.end_lon)) * self.factor_ride
Ejemplo n.º 8
0
 def closest_distance_local(self, point: Vector) -> Float:
     dis = self._radius - distance(point, self._mid)
     return abs(dis)
Ejemplo n.º 9
0
 def sign_distance_local(self, point: Vector) -> Float:
     p = self._surface.closest_point_local(point)
     return -distance(p, point) if self._surface.is_inside_local(
         point) else distance(p, point)
Ejemplo n.º 10
0
 def closest_distance_local(self, point: Vector) -> Float:
     return distance(point, self.closest_point_local(point))