diff -r 12d4ddc4bfd8 -r d383f319f35b tests/concave.py --- a/tests/concave.py Sun Jan 21 15:03:38 2018 +0200 +++ b/tests/concave.py Mon Jan 22 12:22:01 2018 +0200 @@ -6,57 +6,31 @@ # Returns whether all elements in container have the same sign return min(container) * max(container) >= 0 -def transform_to_xy(geometry): - a, b, c = geometry.vertices[:3] - - def concave_test(model): for quadrilateral in model.quadrilaterals: - print([cross_product(v2 - v1, v3 - v1) for v1, v2, v3 in pairs(quadrilateral.geometry.vertices, count = 3)]) + geometry = transform_to_xy(quadrilateral.geometry) z_scores = [ cross_product(v2 - v1, v3 - v1).z - for v1, v2, v3 in pairs(quadrilateral.geometry.vertices, count = 3) + for v1, v2, v3 in pairs(geometry.vertices, count = 3) ] - print(z_scores) if not sign_consistency(z_scores): - yield warning(quadrilateral, 'Concave quadrilateral') + yield error(quadrilateral, 'Concave quadrilateral') def bowtie_quadrilateral_test(model): - for quadrilateral in model.quadrilaterals: - vertices = IndexRing(quadrilateral.geometry.vertices) - for i in (0, 1): - line1 = LineSegment(vertices[0 + i], vertices[1 + i]) - line2 = LineSegment(vertices[2 + i], vertices[3 + i]) - try: - line_intersection(line1, line2) - except NoIntersection: - pass - else: - yield error(quadrilateral, 'Bowtie quadrilateral') - break - -def vector_angle(vec_1, vec_2, normalized = False): - cosine = dot_product(vec_1, vec_2) - try: - cosine /= vec_1.length() * vec_2.length() - except ZeroDivisionError: - return 0 - angle = acos(cosine) - if normalized and angle > π / 2: - angle = π - angle - return angle + ... def skew_test(model): for quadrilateral in model.quadrilaterals: - vertices = IndexRing(quadrilateral.geometry.vertices) - for i in (0, 1): - a, b = vertices[0 + i], vertices[1 + i] - c, d = vertices[2 + i], vertices[3 + i] - plane_1 = cross_product(b - a, d - a) - plane_2 = cross_product(d - c, b - c) + for triangles in split_quadrilateral(quadrilateral.geometry): + plane_1 = triangle_plane_normal(triangles[0]) + plane_2 = triangle_plane_normal(triangles[1]) angle = vector_angle(plane_1, plane_2, normalized = True) if angle > radians(0.1): yield error(quadrilateral, 'Skew quadrilateral (plane angle {}°)', '%.3f' % degrees(angle)) break + +manifest = { + 'tests': {skew_test, concave_test}, +}