Thu, 21 Dec 2017 10:46:41 +0200
Smallest angles
3
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
1 | #!/usr/bin/env python3 |
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
2 | from parse import parse_ldraw_code |
7 | 3 | from geometry import * |
3
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
4 | |
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
5 | def read_ldraw(file, *, libraries): |
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
6 | result = list() |
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
7 | for line in file: |
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
8 | result.append(parse_ldraw_code(line)) |
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
9 | return result |
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
10 | |
7 | 11 | def hairline_score(smallest_angle): |
12 | from math import log10 | |
13 | return max(0, -log10(smallest_angle)) | |
14 | ||
3
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
15 | if __name__ == '__main__': |
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
16 | from sys import argv |
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
17 | libraries = [{'path': '/home/teemu/ldraw', 'role': 'official'}] |
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
18 | with open(argv[1], 'r') as file: |
1dc58f44d556
Can now write dat files, added direct color handling
Santeri Piippo
parents:
diff
changeset
|
19 | model = read_ldraw(file, libraries = libraries) |
7 | 20 | min_angle_tup = (1e12,) |
21 | for line_number, entry in enumerate(model, 1): | |
6
6da1e81c5652
Added code to compute areas of triangles and quadrilaterals
Santeri Piippo
parents:
3
diff
changeset
|
22 | if hasattr(entry, 'geometry') and len(entry.geometry) >= 3: |
7 | 23 | if hairline_score(entry.geometry.smallest_angle) >= 2.0: |
24 | print(str.format( | |
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) |