From 9609e8f25f7492a1823ba089d8153d7521203631 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sat, 17 Apr 2021 17:49:06 +0800 Subject: [PATCH] refactor --- src/experimental/_impl/_tri_delaunay_impl.scad | 13 +++---------- src/experimental/tri_delaunay.scad | 13 ++++++++++++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/experimental/_impl/_tri_delaunay_impl.scad b/src/experimental/_impl/_tri_delaunay_impl.scad index 91771ae5..abfb4bde 100644 --- a/src/experimental/_impl/_tri_delaunay_impl.scad +++ b/src/experimental/_impl/_tri_delaunay_impl.scad @@ -11,17 +11,10 @@ use ; function cc_center(cc) = cc[0]; function cc_rr(cc) = cc[2]; -function delaunay_init(points) = +function delaunay_init(center, width, height) = let( - xs = [for(p = points) p[0]], - ys = [for(p = points) p[1]], - max_x = max(xs), - min_x = min(xs), - max_y = max(ys), - min_y = min(ys), - center = [max_x + min_x, max_y + min_y] / 2, - halfW = abs(max_x - center[0]) * 2, - halfH = abs(max_y - center[1]) * 2, + halfW = width * 0.5, + halfH = height * 0.5, coords = [ center + [-halfW, -halfH], center + [-halfW, halfH], diff --git a/src/experimental/tri_delaunay.scad b/src/experimental/tri_delaunay.scad index 6e530eb1..4a71dde1 100644 --- a/src/experimental/tri_delaunay.scad +++ b/src/experimental/tri_delaunay.scad @@ -2,7 +2,18 @@ use ; // ret: "TRI_SHAPES", "TRI_INDICES", "DELAUNAY" function tri_delaunay(points, ret = "TRI_SHAPES") = - let(d = _tri_delaunay(delaunay_init(points), points, len(points))) + let( + xs = [for(p = points) p[0]], + ys = [for(p = points) p[1]], + max_x = max(xs), + min_x = min(xs), + max_y = max(ys), + min_y = min(ys), + 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)) + ) ret == "TRI_SHAPES" ? tri_delaunay_shapes(d) : ret == "TRI_INDICES" ? tri_delaunay_indices(d) : d; // "DELAUNAY": [coords(list), triangles(hashmap), circles(hashmap)] \ No newline at end of file