1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-12 01:34:12 +02:00

performance improved

This commit is contained in:
Justin Lin
2021-09-09 17:37:33 +08:00
parent 5e7b5f1691
commit ea36c97ac7

View File

@@ -1,11 +1,19 @@
use <__comm__/_pt3_hash.scad>; use <__comm__/_pt3_hash.scad>;
use <util/dedup.scad>; use <util/dedup.scad>;
use <util/map/hashmap.scad>; use <util/map/hashmap.scad>;
use <util/map/hashmap_put.scad>;
use <util/map/hashmap_get.scad>; use <util/map/hashmap_get.scad>;
use <experimental/tri_subdivide.scad>; use <experimental/tri_subdivide.scad>;
function _prj2sphere(t, r) = [for(p = t) p / norm(p) * r]; function _prj2sphere(t, r) = [for(p = t) p / norm(p) * r];
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_icosahedron(icosahedron_points, icosahedron_faces, tris, radius, detail) = function _geom_icosahedron(icosahedron_points, icosahedron_faces, tris, radius, detail) =
let( let(
points = detail == 0 ? [for(tri = tris) each tri] : [ points = detail == 0 ? [for(tri = tris) each tri] : [
@@ -13,23 +21,25 @@ function _geom_icosahedron(icosahedron_points, icosahedron_faces, tris, radius,
each [for(t = tri_subdivide(tri, detail)) each t] each [for(t = tri_subdivide(tri, detail)) each t]
], ],
number_of_buckets = ceil(sqrt(len(points)) * 1.5), number_of_buckets = ceil(sqrt(len(points)) * 1.5),
hash = _pt3_hash(number_of_buckets), hash = _pt3_hash(number_of_buckets),
deduped_pts = dedup(points, hash = hash, number_of_buckets = number_of_buckets), leng = len(points),
pts = [for(p = deduped_pts) p / norm(p) * radius], m_pts = _pimap_pts(
m = hashmap([ radius,
for(i = [0:len(deduped_pts) - 1]) points,
[deduped_pts[i], i] leng,
], hash = hash, number_of_buckets = number_of_buckets), hash,
hashmap(number_of_buckets = number_of_buckets)
),
faces = [ faces = [
for(i = [0:3:len(points) - 3]) for(i = [0:3:leng - 3])
[ [
hashmap_get(m, points[i], hash = hash), hashmap_get(m_pts[0], points[i], hash = hash),
hashmap_get(m, points[i + 1], hash = hash), hashmap_get(m_pts[0], points[i + 1], hash = hash),
hashmap_get(m, points[i + 2], hash = hash) hashmap_get(m_pts[0], points[i + 2], hash = hash)
] ]
] ]
) )
[pts, faces]; [m_pts[1], faces];
function _geom_icosahedron_quick(icosahedron_points, icosahedron_faces, tris, radius, detail) = function _geom_icosahedron_quick(icosahedron_points, icosahedron_faces, tris, radius, detail) =
let( let(