-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject_matching.py
More file actions
45 lines (33 loc) · 1.01 KB
/
object_matching.py
File metadata and controls
45 lines (33 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def match(obj_list, tar):
"""matches two objects based on the position closest to target"""
if not len(obj_list):
return -1
# Arbirtary initial distance
m = 10000
cnt = 0;
idx = -1
# Split on coordinate seperator for given coordinate
td = tar.split(":")
tx = int(td[0])
ty = int(td[1])
# Iterates through each current objects coordinates
for i in obj_list:
# see above
l = i["text"].split(":")
cx, cy = int(l[0]), int(l[1])
cur = dist(cx, cy, tx, ty)
if cur < m:
idx = cnt
m = cur
cnt += 1
return idx
def dist(cx, cy, x, y):
"""just a little distance function
(square root omitted for time considerations)"""
x = 2*(x - cx)
y = y - cy
# This is the minimum distance for something to be considered the
# same object, will need tuning before final value is decided
if (8 < x or 4 < y):
return 10001
return (x*x) + (y*y)