From c843c99b1127be9d90d24d56518dca1acb2f726a Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Mon, 24 Feb 2020 17:23:09 +0800 Subject: [PATCH] refactor --- src/_impl/_triangulate_impl.scad | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/_impl/_triangulate_impl.scad b/src/_impl/_triangulate_impl.scad index 1f23d2e3..fc1eee35 100644 --- a/src/_impl/_triangulate_impl.scad +++ b/src/_impl/_triangulate_impl.scad @@ -9,6 +9,9 @@ function _triangulate_in_triangle(p0, p1, p2, p) = ) (c0 > 0 && c1 > 0 && c2 > 0) || (c0 < 0 && c1 < 0 && c2 < 0); +function _triangulate_determinant_2x2(matrix) = + matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]; + function _triangulate_snipable(shape_pts, u, v, w, n, indices, epsilon = 0.0001) = let( a = shape_pts[indices[u]], @@ -19,9 +22,14 @@ function _triangulate_snipable(shape_pts, u, v, w, n, indices, epsilon = 0.0001) bx = b[0], by = b[1], cx = c[0], - cy = c[1] + cy = c[1], + determinant = _triangulate_determinant_2x2([ + [bx - ax, by - ay], + [cx - ax, cy - ay] + ]) ) - epsilon > (((bx - ax) * (cy - ay)) - ((by - ay) * (cx - ax))) ? + + epsilon > determinant ? false : _triangulate_snipable_sub(shape_pts, n, u, v, w, a, b, c, indices); function _triangulate_snipable_sub(shape_pts, n, u, v, w, a, b, c, indices, p = 0) =