tests/concave.py

Mon, 22 Jan 2018 12:22:01 +0200

author
Santeri Piippo
date
Mon, 22 Jan 2018 12:22:01 +0200
changeset 14
d383f319f35b
parent 13
12d4ddc4bfd8
child 16
09cc89622262
permissions
-rw-r--r--

transform_to_xy implemented and concave test online

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 quadrilateral')

def bowtie_quadrilateral_test(model):
    ...

def skew_test(model):
    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])
            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},
}

mercurial