ldcheck.py

changeset 13
12d4ddc4bfd8
parent 9
fea8e9ae6f29
child 17
327da5d00360
--- a/ldcheck.py	Fri Jan 19 13:41:23 2018 +0200
+++ b/ldcheck.py	Sun Jan 21 15:03:38 2018 +0200
@@ -7,6 +7,7 @@
 from colours import load_colours
 from geometry import *
 from pathlib import Path
+import linetypes
 
 from os.path import realpath
 script_directory = Path(realpath(__file__)).parent
@@ -47,6 +48,15 @@
     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)
+
 if __name__ == '__main__':
     from sys import argv
     config = load_config('ldcheck.cfg')
@@ -54,8 +64,9 @@
         with ldconfig_ldr_path.open() as ldconfig_ldr:
             load_colours(ldconfig_ldr)
     with open(argv[1], 'r') as file:
-        model = read_ldraw(file, config = config)
-        for line_number, entry in enumerate(model, 1):
+        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:
@@ -66,4 +77,4 @@
                         line_number = line_number,
                     ))
                     print(entry.textual_representation())
-                    print('-' * 25)
\ No newline at end of file
+                    print('-' * 25)

mercurial