Mon, 22 Jan 2018 18:23:25 +0200
added matrix all zero test
from math import radians from testsuite import warning, error from geometry import * def sign_consistency(container): # Returns whether all elements in container have the same sign return min(container) * max(container) >= 0 def concave_test(model): for quadrilateral in model.quadrilaterals: geometry = transform_to_xy(quadrilateral.geometry) z_scores = [ cross_product(v2 - v1, v3 - v1).z for v1, v2, v3 in pairs(geometry.vertices, count = 3) ] if not sign_consistency(z_scores): yield error(quadrilateral, 'concave-error') def skew_test(model): ''' Test for non-coplanar quadrilaterals. ''' for quadrilateral in model.quadrilaterals: for triangles in split_quadrilateral(quadrilateral.geometry): plane_1 = triangle_plane_normal(triangles[0]) plane_2 = triangle_plane_normal(triangles[1]) skew_angle = vector_angle(plane_1, plane_2, normalized = True) if skew_angle > radians(0.1): yield error(quadrilateral, 'skew-error', skew_angle = skew_angle, ) break manifest = { 'tests': { 'skew': skew_test, 'concave': concave_test, }, 'messages': { 'skew-error': lambda skew_angle: str.format('skew quadrilateral (plane angle {})', degree_rep(skew_angle), ), 'concave-error': 'concave quadrilateral', }, }