From 1634403e281da815184d556f653e95fa0a855949 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Thu, 23 Sep 2021 07:46:45 +0800 Subject: [PATCH] refactor --- .../_impl/_geom_platonic_polyhedra.scad | 14 ++++---- src/experimental/_impl/_geom_prj2sphere.scad | 1 - src/experimental/_impl/_geom_pts_faces.scad | 34 ------------------- 3 files changed, 6 insertions(+), 43 deletions(-) delete mode 100644 src/experimental/_impl/_geom_prj2sphere.scad delete mode 100644 src/experimental/_impl/_geom_pts_faces.scad diff --git a/src/experimental/_impl/_geom_platonic_polyhedra.scad b/src/experimental/_impl/_geom_platonic_polyhedra.scad index 2283f241..ac386593 100644 --- a/src/experimental/_impl/_geom_platonic_polyhedra.scad +++ b/src/experimental/_impl/_geom_platonic_polyhedra.scad @@ -37,17 +37,14 @@ function _geom_pts_faces(points, radius) = [m_pts[1], faces]; function _geom_info(tris, radius, detail) = - let( - points = detail == 0 ? [for(tri = tris) each tri] : [ - for(tri = tris) - each [for(t = tri_subdivide(tri, detail)) each t] - ] - ) - _geom_pts_faces(points, radius); + _geom_pts_faces([ + for(tri = tris) + each [for(t = tri_subdivide(tri, detail)) each t] + ], radius); function _geom_info_quick(tris, radius, detail) = let( - points = detail == 0 ? [for(tri = tris) each _geom_prj2sphere(tri, radius)] : [ + points = [ for(tri = tris) each [for(t = tri_subdivide(tri, detail)) each _geom_prj2sphere(t, radius)] ], @@ -56,6 +53,7 @@ function _geom_info_quick(tris, radius, detail) = [points, faces]; function _geom_platonic_polyhedra(points, faces, radius, detail, quick_mode) = + detail == 0 ? [_geom_prj2sphere(points, radius), faces] : let( tris = [ for(face = faces) diff --git a/src/experimental/_impl/_geom_prj2sphere.scad b/src/experimental/_impl/_geom_prj2sphere.scad deleted file mode 100644 index 0b19bbea..00000000 --- a/src/experimental/_impl/_geom_prj2sphere.scad +++ /dev/null @@ -1 +0,0 @@ -function _geom_prj2sphere(t, r) = [for(p = t) p / norm(p) * r]; \ No newline at end of file diff --git a/src/experimental/_impl/_geom_pts_faces.scad b/src/experimental/_impl/_geom_pts_faces.scad deleted file mode 100644 index 3ecb7af5..00000000 --- a/src/experimental/_impl/_geom_pts_faces.scad +++ /dev/null @@ -1,34 +0,0 @@ -use <__comm__/_pt3_hash.scad>; -use ; -use ; -use ; - -function _pimap_pts(radius, points, leng, hash, m, deduped_pts = [], n = -1, i = 0) = - i == leng ? [m, deduped_pts] : - let(v = hashmap_get(m, points[i], hash = hash)) - is_undef(v) ? - _pimap_pts(radius, points, leng, hash, hashmap_put(m, points[i], n + 1, hash = hash), concat(deduped_pts, [points[i] / norm(points[i]) * radius]), n + 1, i + 1) : - _pimap_pts(radius, points, leng, hash, m, deduped_pts, n, i + 1); - -function _geom_pts_faces(points, radius) = - let( - number_of_buckets = ceil(sqrt(len(points)) * 1.5), - hash = function(p) _pt3_hash(p), - leng = len(points), - m_pts = _pimap_pts( - radius, - points, - leng, - hash, - hashmap(number_of_buckets = number_of_buckets) - ), - faces = [ - for(i = [0:3:leng - 3]) - [ - hashmap_get(m_pts[0], points[i], hash = hash), - hashmap_get(m_pts[0], points[i + 1], hash = hash), - hashmap_get(m_pts[0], points[i + 2], hash = hash) - ] - ] - ) - [m_pts[1], faces]; \ No newline at end of file