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

refactor: use built-in search

This commit is contained in:
Justin Lin
2022-04-01 09:52:32 +08:00
parent 7889c5608f
commit 1fb61fc3ec
3 changed files with 7 additions and 5 deletions

View File

@@ -4,7 +4,6 @@ use <../../util/map/hashmap_get.scad>;
use <../../util/map/hashmap_del.scad>;
use <../../util/map/hashmap_keys.scad>;
use <../../util/map/hashmap_put.scad>;
use <../../util/some.scad>;
use <../../util/has.scad>;
use <../../util/find_index.scad>;
@@ -199,7 +198,7 @@ function _delaunayBoundaries(d, badTriangles, boundaries, t, vi, _indices_hash)
triangles = delaunay_triangles(d),
opTri = hashmap_get(triangles, t, hash = _indices_hash)[vi]
)
some(badTriangles, function(tri) tri == opTri) ?
has(badTriangles, opTri) ?
let(
i = search([t], hashmap_get(triangles, opTri, hash = _indices_hash))[0],
nvi = (i + 1) % 3,

View File

@@ -12,14 +12,17 @@ function _dedup(elems, leng, buckets, eq, hash, bucket_numbers) =
)
_dedup_add(n_buckets_lt[end - 1], [end, elems[end]], eq, hash, bucket_numbers);
function _dedup_add(buckets, i_elem, eq, hash, bucket_numbers) =
let(
elem = i_elem[1],
b_idx = hash(elem) % bucket_numbers,
bucket = buckets[b_idx]
)
some(bucket, function(i_e) eq(i_e[1], elem)) ? buckets : _add(buckets, bucket, i_elem, b_idx);
(
is_undef(eq) ?
search([elem], bucket, num_returns_per_match = 1, index_col_num = 1) != [[]] :
some(bucket, function(i_e) eq(i_e[1], elem))
) ? buckets : _add(buckets, bucket, i_elem, b_idx);
function _add(buckets, bucket, i_elem, b_idx) =
let(leng = len(buckets))

View File

@@ -12,7 +12,7 @@ use <../__comm__/_str_hash.scad>;
use <_impl/_dedup_impl.scad>;
use <sort.scad>;
function dedup(lt, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e), number_of_buckets) =
function dedup(lt, eq = undef, hash = function(e) _str_hash(e), number_of_buckets) =
let(leng_lt = len(lt))
leng_lt < 2 ? lt :
let(