MCPcopy Create free account
hub / github.com/OpenBMB/AgentCPM-GUI / _get_direction

Function _get_direction

eval/utils/evaluator.py:99–136  ·  view source on GitHub ↗
(point1, point2)

Source from the content-addressed store, hash-verified

97
98
99def _get_direction(point1, point2):
100 try:
101 x1, y1 = point1["x"], point1["y"]
102 x2, y2 = point2["x"], point2["y"]
103
104 assert x1 is not None
105 assert x2 is not None
106 assert y1 is not None
107 assert y2 is not None
108
109 vector = (x2 - x1, y2 - y1)
110 vx, vy = vector
111 except Exception as e:
112 return "no direction"
113
114 directions = {
115 "up": (0, -1),
116 "down": (0, 1),
117 "left": (-1, 0),
118 "right": (1, 0)
119 }
120
121 vector_length = math.sqrt(vx ** 2 + vy ** 2)
122 if vector_length == 0:
123 return "no direction"
124 unit_vector = (vx / vector_length, vy / vector_length)
125
126 max_cosine = -float('inf')
127 closest_direction = None
128 for direction, dir_vector in directions.items():
129 dx, dy = dir_vector
130 dir_length = math.sqrt(dx ** 2 + dy ** 2)
131 cos_theta = (unit_vector[0] * dx + unit_vector[1] * dy) / dir_length
132 if cos_theta > max_cosine:
133 max_cosine = cos_theta
134 closest_direction = direction
135
136 return closest_direction
137
138def get_direction(point, to):
139 if isinstance(to, str):

Callers 2

get_directionFunction · 0.85
_parse_answer_Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected