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

#!/usr/bin/env python3
from parse import parse_ldraw_code
from geometry import *

def read_ldraw(file, *, libraries):
    result = list()
    for line in file:
        result.append(parse_ldraw_code(line))
    return result

def hairline_score(smallest_angle):
    from math import log10
    return max(0, -log10(smallest_angle))

if __name__ == '__main__':
    from sys import argv
    libraries = [{'path': '/home/teemu/ldraw', 'role': 'official'}]
    with open(argv[1], 'r') as file:
        model = read_ldraw(file, libraries = libraries)
        min_angle_tup = (1e12,)
        for line_number, entry in enumerate(model, 1):
            if hasattr(entry, 'geometry') and len(entry.geometry) >= 3:
                if hairline_score(entry.geometry.smallest_angle) >= 2.0:
                    print(str.format(
                        'Hairline {type} at line {line_number}',
                        type = entry.typename(),
                        line_number = line_number,
                    ))
                    print(entry.textual_representation())
                    print('-' * 25)

mercurial