Fri, 19 Jan 2018 13:41:23 +0200
commit work done on test suites...
geometry.py | file | annotate | diff | comparison | revisions | |
tests/concave.py | file | annotate | diff | comparison | revisions | |
testsuite.py | file | annotate | diff | comparison | revisions |
--- a/geometry.py Tue Jan 16 17:29:40 2018 +0200 +++ b/geometry.py Fri Jan 19 13:41:23 2018 +0200 @@ -188,15 +188,18 @@ for v1, v2 in pairs(self.vertices): yield LineSegment(v1, v2) @property - def smallest_angle(self): - from math import acos, inf - min_angle = inf + def angles(self): + from math import acos for v1, v2, v3 in pairs(self.vertices, count = 3): vec1 = (position_vector(v3) - position_vector(v2)).normalized() vec2 = (position_vector(v1) - position_vector(v2)).normalized() cosine = dot_product(vec1, vec2) / vec1.length() / vec2.length() - min_angle = min(min_angle, angle_magnitude_key(acos(cosine))) - return min_angle + yield acos(cosine) + @property + def smallest_angle(self): + return min( + angle_magnitude_key(angle) + for angle in self.angles) @property def hairline_ratio(self): lengths = [line.length for line in self.perimeter_lines]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/concave.py Fri Jan 19 13:41:23 2018 +0200 @@ -0,0 +1,22 @@ +from math import degrees, pi as π +from testsuite import warning +from geometry import * + +def sign_consistency(container): + # Returns whether all elements in container have the same sign + return min(container) * max(container) >= 0 + +def transform_to_xy(geometry): + a, b, c = geometry.vertices[:3] + + +def concave_test(model): + for quadrilateral in model: + print([cross_product(v2 - v1, v3 - v1) for v1, v2, v3 in pairs(quadrilateral.geometry.vertices, count = 3)]) + z_scores = [ + cross_product(v2 - v1, v3 - v1).z + for v1, v2, v3 in pairs(quadrilateral.geometry.vertices, count = 3) + ] + print(z_scores) + if not sign_consistency(z_scores): + yield warning(quadrilateral, 'Concave quadrilateral') \ No newline at end of file