Mon, 22 Jan 2018 01:01:10 +0200
Condensed transform_to_xy
13 | 1 | from math import acos, degrees, radians, pi as π |
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): | |
13 | 10 | for quadrilateral in model.quadrilaterals: |
14
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
11 | geometry = transform_to_xy(quadrilateral.geometry) |
12 | 12 | z_scores = [ |
13 | cross_product(v2 - v1, v3 - v1).z | |
14
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
14 | for v1, v2, v3 in pairs(geometry.vertices, count = 3) |
12 | 15 | ] |
16 | if not sign_consistency(z_scores): | |
14
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
17 | yield error(quadrilateral, 'Concave quadrilateral') |
13 | 18 | |
19 | def bowtie_quadrilateral_test(model): | |
14
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
20 | ... |
13 | 21 | |
22 | def skew_test(model): | |
23 | for quadrilateral in model.quadrilaterals: | |
14
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
24 | for triangles in split_quadrilateral(quadrilateral.geometry): |
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
25 | plane_1 = triangle_plane_normal(triangles[0]) |
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
26 | plane_2 = triangle_plane_normal(triangles[1]) |
13 | 27 | angle = vector_angle(plane_1, plane_2, normalized = True) |
28 | if angle > radians(0.1): | |
29 | yield error(quadrilateral, | |
30 | 'Skew quadrilateral (plane angle {}°)', | |
31 | '%.3f' % degrees(angle)) | |
32 | break | |
14
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
33 | |
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
34 | manifest = { |
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
35 | 'tests': {skew_test, concave_test}, |
d383f319f35b
transform_to_xy implemented and concave test online
Santeri Piippo
parents:
13
diff
changeset
|
36 | } |