tests/concave.py

Mon, 22 Jan 2018 17:05:10 +0200

author
Santeri Piippo
date
Mon, 22 Jan 2018 17:05:10 +0200
changeset 17
327da5d00360
parent 16
09cc89622262
child 18
672ebc45685a
permissions
-rw-r--r--

Added code to run the test suite.

13
12d4ddc4bfd8 Got the skew test working
Santeri Piippo
parents: 12
diff changeset
1 from math import acos, degrees, radians, pi as π
12d4ddc4bfd8 Got the skew test working
Santeri Piippo
parents: 12
diff changeset
2 from testsuite import warning, error
12
eb74680a5e43 commit work done on test suites...
Santeri Piippo
parents:
diff changeset
3 from geometry import *
eb74680a5e43 commit work done on test suites...
Santeri Piippo
parents:
diff changeset
4
eb74680a5e43 commit work done on test suites...
Santeri Piippo
parents:
diff changeset
5 def sign_consistency(container):
eb74680a5e43 commit work done on test suites...
Santeri Piippo
parents:
diff changeset
6 # Returns whether all elements in container have the same sign
eb74680a5e43 commit work done on test suites...
Santeri Piippo
parents:
diff changeset
7 return min(container) * max(container) >= 0
eb74680a5e43 commit work done on test suites...
Santeri Piippo
parents:
diff changeset
8
eb74680a5e43 commit work done on test suites...
Santeri Piippo
parents:
diff changeset
9 def concave_test(model):
13
12d4ddc4bfd8 Got the skew test working
Santeri Piippo
parents: 12
diff changeset
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
eb74680a5e43 commit work done on test suites...
Santeri Piippo
parents:
diff changeset
12 z_scores = [
eb74680a5e43 commit work done on test suites...
Santeri Piippo
parents:
diff changeset
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
eb74680a5e43 commit work done on test suites...
Santeri Piippo
parents:
diff changeset
15 ]
eb74680a5e43 commit work done on test suites...
Santeri Piippo
parents:
diff changeset
16 if not sign_consistency(z_scores):
16
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
17 yield error(quadrilateral, 'concave-error')
13
12d4ddc4bfd8 Got the skew test working
Santeri Piippo
parents: 12
diff changeset
18
12d4ddc4bfd8 Got the skew test working
Santeri Piippo
parents: 12
diff changeset
19 def skew_test(model):
16
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
20 ''' Test for non-coplanar quadrilaterals. '''
13
12d4ddc4bfd8 Got the skew test working
Santeri Piippo
parents: 12
diff changeset
21 for quadrilateral in model.quadrilaterals:
14
d383f319f35b transform_to_xy implemented and concave test online
Santeri Piippo
parents: 13
diff changeset
22 for triangles in split_quadrilateral(quadrilateral.geometry):
d383f319f35b transform_to_xy implemented and concave test online
Santeri Piippo
parents: 13
diff changeset
23 plane_1 = triangle_plane_normal(triangles[0])
d383f319f35b transform_to_xy implemented and concave test online
Santeri Piippo
parents: 13
diff changeset
24 plane_2 = triangle_plane_normal(triangles[1])
16
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
25 skew_angle = vector_angle(plane_1, plane_2, normalized = True)
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
26 if skew_angle > radians(0.1):
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
27 yield error(quadrilateral, 'skew-error',
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
28 skew_angle = skew_angle,
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
29 )
13
12d4ddc4bfd8 Got the skew test working
Santeri Piippo
parents: 12
diff changeset
30 break
14
d383f319f35b transform_to_xy implemented and concave test online
Santeri Piippo
parents: 13
diff changeset
31
d383f319f35b transform_to_xy implemented and concave test online
Santeri Piippo
parents: 13
diff changeset
32 manifest = {
16
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
33 'tests': {
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
34 'skew': skew_test,
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
35 'concave': concave_test,
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
36 },
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
37 'messages': {
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
38 'skew-error': lambda skew_angle:
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
39 str.format('Skew quadrilateral (plane angle {}°)',
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
40 '%.2f' % degrees(skew_angle),
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
41 ),
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
42 'concave-error': 'Concave quadrilateral',
09cc89622262 Commit work done on test loading
Santeri Piippo
parents: 14
diff changeset
43 },
14
d383f319f35b transform_to_xy implemented and concave test online
Santeri Piippo
parents: 13
diff changeset
44 }

mercurial