forked from gramaziokohler/workshop_swinburne_2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path501_linear_order.py
34 lines (25 loc) · 836 Bytes
/
501_linear_order.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
import functools
import random
from compas.geometry import Box
# random but repeatable ;)
random.seed(2666)
@functools.total_ordering
class BoxComparer(object):
def __init__(self, box, *args):
self.box = box
def __eq__(self, other):
return self.box.data == other.box.data
def __lt__(self, other):
return self.box.dimensions < other.box.dimensions
bricks = set()
for i in range(10):
w, h, d = random.random(), random.random(), random.random()
brick = Box.from_width_height_depth(w, h, d)
bricks.add(brick)
print('No sorting guaranteed (depends on implementation)')
for b in bricks:
print('{:.3f}, {:.3f}, {:.3f}'.format(*b.dimensions))
print()
print('Defined total ordering')
for b in sorted(bricks, key=BoxComparer):
print('{:.3f}, {:.3f}, {:.3f}'.format(*b.dimensions))