1 #!/usr/bin/env python3 |
1 #!/usr/bin/env python3 |
2 from parse import parse_ldraw_code |
2 from parse import parse_ldraw_code |
|
3 from geometry import * |
3 |
4 |
4 def read_ldraw(file, *, libraries): |
5 def read_ldraw(file, *, libraries): |
5 result = list() |
6 result = list() |
6 for line in file: |
7 for line in file: |
7 result.append(parse_ldraw_code(line)) |
8 result.append(parse_ldraw_code(line)) |
8 return result |
9 return result |
9 |
10 |
|
11 def hairline_score(smallest_angle): |
|
12 from math import log10 |
|
13 return max(0, -log10(smallest_angle)) |
|
14 |
10 if __name__ == '__main__': |
15 if __name__ == '__main__': |
11 from sys import argv |
16 from sys import argv |
12 libraries = [{'path': '/home/teemu/ldraw', 'role': 'official'}] |
17 libraries = [{'path': '/home/teemu/ldraw', 'role': 'official'}] |
13 with open(argv[1], 'r') as file: |
18 with open(argv[1], 'r') as file: |
14 model = read_ldraw(file, libraries = libraries) |
19 model = read_ldraw(file, libraries = libraries) |
15 for entry in model: |
20 min_angle_tup = (1e12,) |
|
21 for line_number, entry in enumerate(model, 1): |
16 if hasattr(entry, 'geometry') and len(entry.geometry) >= 3: |
22 if hasattr(entry, 'geometry') and len(entry.geometry) >= 3: |
17 print(repr(entry)) |
23 if hairline_score(entry.geometry.smallest_angle) >= 2.0: |
18 print(entry.geometry.area()) |
24 print(str.format( |
19 #print(entry.textual_representation().strip(), end = '\r\n') |
25 'Hairline {type} at line {line_number}', |
|
26 type = entry.typename(), |
|
27 line_number = line_number, |
|
28 )) |
|
29 print(entry.textual_representation()) |
|
30 print('-' * 25) |