ldverify.py

Thu, 21 Dec 2017 10:46:41 +0200

author
Santeri Piippo
date
Thu, 21 Dec 2017 10:46:41 +0200
changeset 7
0ab0d61ccee8
parent 6
6da1e81c5652
child 8
303c51137cb2
permissions
-rwxr-xr-x

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
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
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
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
11 def hairline_score(smallest_angle):
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
12 from math import log10
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
13 return max(0, -log10(smallest_angle))
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
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
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
20 min_angle_tup = (1e12,)
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
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
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
23 if hairline_score(entry.geometry.smallest_angle) >= 2.0:
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
24 print(str.format(
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
25 'Hairline {type} at line {line_number}',
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
26 type = entry.typename(),
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
27 line_number = line_number,
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
28 ))
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
29 print(entry.textual_representation())
0ab0d61ccee8 Smallest angles
Santeri Piippo
parents: 6
diff changeset
30 print('-' * 25)

mercurial