-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
35 lines (26 loc) · 791 Bytes
/
util.py
File metadata and controls
35 lines (26 loc) · 791 Bytes
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
def get_cell_adjacency(cell, shape):
r, c = cell
num_rows, num_cols = shape
adjacency = dict()
if r > 0:
adjacency['t'] = (r - 1, c)
if r < num_rows - 1:
adjacency['b'] = (r + 1, c)
if c > 0:
adjacency['l'] = (r, c - 1)
if c < num_cols - 1:
adjacency['r'] = (r, c + 1)
return adjacency
inverse_direction_map = {
'r': 'l',
'l': 'r',
't': 'b',
'b': 't'
}
def has_valid_connection(module1, module2, direction):
inverse_direction = inverse_direction_map[direction]
m1_inverted = set()
for conn in module1["connections"][direction]:
m1_inverted.add(conn[::-1])
m2_connections = set(module2["connections"][inverse_direction])
return bool(m1_inverted.intersection(m2_connections))