From 6468746766f69553a0f78f240cafd443b39cc1b0 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 18 Apr 2021 11:03:07 +0800 Subject: [PATCH] performance improved --- src/experimental/_impl/_tri_delaunay_impl.scad | 9 ++++++--- src/experimental/tri_delaunay.scad | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/experimental/_impl/_tri_delaunay_impl.scad b/src/experimental/_impl/_tri_delaunay_impl.scad index 83598727..5adac1e7 100644 --- a/src/experimental/_impl/_tri_delaunay_impl.scad +++ b/src/experimental/_impl/_tri_delaunay_impl.scad @@ -13,7 +13,7 @@ use ; function cc_center(cc) = cc[0]; function cc_rr(cc) = cc[2]; -function delaunay_init(center, width, height) = +function delaunay_init(center, width, height, leng_points) = let( halfW = width * 0.5, halfH = height * 0.5, @@ -25,15 +25,18 @@ function delaunay_init(center, width, height) = ], t1 = [0, 1, 3], // indices t2 = [2, 3, 1], + number_of_buckets = leng_points * 0.5, triangles = hashmap([ [t1, [t2, undef, undef]], [t2, [t1, undef, undef]] - ] + ], + number_of_buckets = number_of_buckets ), circles = hashmap([ [t1, tri_circumcircle([for(i = t1) coords[i]])], [t2, tri_circumcircle([for(i = t2) coords[i]])] - ] + ], + number_of_buckets = number_of_buckets ) ) [coords, triangles, circles]; diff --git a/src/experimental/tri_delaunay.scad b/src/experimental/tri_delaunay.scad index d1afa7cb..a555388f 100644 --- a/src/experimental/tri_delaunay.scad +++ b/src/experimental/tri_delaunay.scad @@ -15,7 +15,8 @@ function tri_delaunay(points, ret = "TRI_INDICES") = center = [max_x + min_x, max_y + min_y] / 2, width = abs(max_x - center[0]) * 4, height = abs(max_y - center[1]) * 4, - d = _tri_delaunay(delaunay_init(center, width, height), points, len(points)) + leng_pts = len(points), + d = _tri_delaunay(delaunay_init(center, width, height, leng_pts), points, leng_pts) ) ret == "TRI_INDICES" ? tri_delaunay_indices(d) : ret == "TRI_SHAPES" ? tri_delaunay_shapes(d) :