From 2c2d6b2d40353a86cbb582ca9957e70391dd36f3 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Mon, 2 Jun 2014 08:44:12 +0200 Subject: [PATCH] clean triangulation subfunctions Get ride of the logical operator and use cleaner bounding notation. Add exclude_edges to is_acute. --- triangulation.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/triangulation.py b/triangulation.py index 1c5ebe8..816ae45 100644 --- a/triangulation.py +++ b/triangulation.py @@ -104,23 +104,20 @@ def in_triangle( p0, triangle, exclude_edges = False ): beta = ( (y(p3) - y(p1)) * (x(p0) - x(p3)) + (x(p1) - x(p3)) * (y(p0) - y(p3)) ) \ / ( (y(p2) - y(p3)) * (x(p1) - x(p3)) + (x(p3) - x(p2)) * (y(p1) - y(p3)) ) gamma = 1.0 - alpha - beta - # print alpha,beta,gamma if exclude_edges: - # If all of alpha, beta, and gamma are strictly greater than 0 and lower than 1, - # (and thus if any of them are lower or equal than 0 or greater than 1) + # If all of alpha, beta, and gamma are strictly in ]0,1[, # then the point p0 strictly lies within the triangle. - return any( x <= 0 or 1 <= x for x in (alpha, beta, gamma) ) + return all( 0 < x < 1 for x in (alpha, beta, gamma) ) else: - # If the inequality is strict, then the point may lies on an edge. - return any( x < 0 or 1 < x for x in (alpha, beta, gamma) ) + # If the inequality is not strict, then the point may lies on an edge. + return all( 0 <= x <= 1 for x in (alpha, beta, gamma) ) -def is_acute(triangle): +def is_acute(triangle, exclude_edges = False ): """Return True if the center of the circumcircle of the given triangle lies inside the triangle. That is if the triangle is acute.""" - return in_triangle( circumcircle(triangle)[0], triangle ) - + return in_triangle( circumcircle(triangle)[0], triangle, exclude_edges ) def bounds( vertices ):