-
Notifications
You must be signed in to change notification settings - Fork 2
/
box.py
59 lines (40 loc) · 1.31 KB
/
box.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from typing import Iterable
from math import floor
def box_product(stream1: Iterable, stream2: Iterable):
for element2 in stream2:
for element1 in stream1:
yield [element1, element2]
def box_pairing(length1: int, length2: int, index1: int, index2: int):
return index1 + index2 * length1
def box_unpairing(length1: int, length2: int, index: int):
index1 = index % length1 # modulo operation
index2 = floor(index / length1) # integer division
return [index1, index2]
def box_plot():
from general import pairing_function_plot
points = [box_unpairing(3, 2, i) for i in range(6)]
arrows = [
[0, 0, 1, 0],
[1, 0, 2, 0],
[2, 0, 0, 1],
[0, 1, 1, 1],
[1, 1, 2, 1],
]
return pairing_function_plot(points, arrows)
def bad_plot():
from general import pairing_function_plot
points = [[0, 0], [1, 0], [2, 0], [3, 0]]
arrows = [
[0, 0, 1, 0],
[1, 0, 2, 0],
[2, 0, 3, 0],
[3, 0, 4, 0],
]
fig = pairing_function_plot(points, arrows)
ax = fig.axes[0]
extra_points = [[x, y + 1] for x in range(4) for y in range(3)]
ax.scatter(*zip(*extra_points), linestyle="None", marker='o', color='yellow')
return fig
if __name__ == '__main__':
box_plot().show()
bad_plot().show()