Mon, 22 Jan 2018 21:21:53 +0200
Added command line option to list all checks.
22 | 1 | from math import radians |
13 | 2 | from testsuite import warning, error |
12 | 3 | from geometry import * |
4 | ||
5 | def sign_consistency(container): | |
6 | # Returns whether all elements in container have the same sign | |
7 | return min(container) * max(container) >= 0 | |
8 | ||
9 | def concave_test(model): | |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
22
diff
changeset
|
10 | ''' Checks that all quadrilaterals are convex. ''' |
13 | 11 | for quadrilateral in model.quadrilaterals: |
14
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
12 | geometry = transform_to_xy(quadrilateral.geometry) |
12 | 13 | z_scores = [ |
14 | cross_product(v2 - v1, v3 - v1).z | |
14
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
15 | for v1, v2, v3 in pairs(geometry.vertices, count = 3) |
12 | 16 | ] |
17 | if not sign_consistency(z_scores): | |
16 | 18 | yield error(quadrilateral, 'concave-error') |
13 | 19 | |
20 | def skew_test(model): | |
26
7c263b864371
Added command line option to list all checks.
Santeri Piippo
parents:
22
diff
changeset
|
21 | ''' Checks that all quadrilaterals are coplanar. ''' |
13 | 22 | for quadrilateral in model.quadrilaterals: |
14
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
23 | for triangles in split_quadrilateral(quadrilateral.geometry): |
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
24 | plane_1 = triangle_plane_normal(triangles[0]) |
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
25 | plane_2 = triangle_plane_normal(triangles[1]) |
16 | 26 | skew_angle = vector_angle(plane_1, plane_2, normalized = True) |
27 | if skew_angle > radians(0.1): | |
28 | yield error(quadrilateral, 'skew-error', | |
29 | skew_angle = skew_angle, | |
30 | ) | |
13 | 31 | break |
14
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
32 | |
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
33 | manifest = { |
16 | 34 | 'tests': { |
35 | 'skew': skew_test, | |
36 | 'concave': concave_test, | |
37 | }, | |
38 | 'messages': { | |
39 | 'skew-error': lambda skew_angle: | |
22 | 40 | str.format('skew quadrilateral (plane angle {})', |
41 | degree_rep(skew_angle), | |
16 | 42 | ), |
18 | 43 | 'concave-error': 'concave quadrilateral', |
16 | 44 | }, |
14
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
45 | } |