ldcheck.py

changeset 17
327da5d00360
parent 13
12d4ddc4bfd8
child 18
672ebc45685a
--- a/ldcheck.py	Mon Jan 22 13:51:13 2018 +0200
+++ b/ldcheck.py	Mon Jan 22 17:05:10 2018 +0200
@@ -35,27 +35,27 @@
 
 def find_ldconfig_ldr_paths(config):
     for library_path in library_paths(config):
-        ldconfig_paths = [
-            library_path / 'LDConfig.ldr',
-            library_path / 'ldconfig.ldr',
+        yield from [
+            library_path / path
+            for path in ['LDConfig.ldr', 'ldconfig.ldr']
+            if (library_path / path).is_file()
         ]
-        for path in ldconfig_paths:
-            print(path)
-            if path.is_file():
-                yield path
 
 def hairline_score(smallest_angle):
     from math import log10
     return max(0, -log10(smallest_angle))
 
 class Model:
-	def __init__(self, body):
-		self.body = body
-	@property
-	def quadrilaterals(self):
-		yield from filter(
-			lambda element: isinstance(element, linetypes.Quadrilateral),
-			self.body)
+    def __init__(self, body):
+        self.body = body
+        self.body_offset = 0
+    @property
+    def quadrilaterals(self):
+        yield from [
+            element
+            for element in self.body
+            if isinstance(element, linetypes.Quadrilateral)
+        ]
 
 if __name__ == '__main__':
     from sys import argv
@@ -66,15 +66,7 @@
     with open(argv[1], 'r') as file:
         model_body = read_ldraw(file, config = config)
         model = Model(body = model_body)
-        for line_number, entry in enumerate(model_body, 1):
-            if hasattr(entry, 'colour'):
-                print(repr(entry.colour))
-            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)
+        from testsuite import load_tests, check_model, format_report
+        test_suite = load_tests()
+        report = check_model(model, test_suite)
+        print(format_report(report, model, test_suite))

mercurial