tests/concave.py

Mon, 22 Jan 2018 13:51:13 +0200

author
Santeri Piippo
date
Mon, 22 Jan 2018 13:51:13 +0200
changeset 16
09cc89622262
parent 14
d383f319f35b
child 18
672ebc45685a
permissions
-rw-r--r--

Commit work done on test loading

from math import acos, degrees, radians, pi as π
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 {}°)',
                '%.2f' % degrees(skew_angle),
            ),
        'concave-error': 'Concave quadrilateral',
    },
}

mercurial