1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-07 23:37:13 +02:00

start accept a list of points

This commit is contained in:
Justin Lin
2022-07-10 11:39:57 +08:00
parent 160d2e67ac
commit c63d5c0d47

View File

@@ -1,17 +1,27 @@
use <../../matrix/m_replace.scad> use <../../matrix/m_replace.scad>
use <../../util/every.scad> use <../../util/every.scad>
use <../../util/find_index.scad>
function sampling(size, r, start, k, sd) = function sampling(size, r, start, k, sd) =
let( let(
w = r / sqrt(2), w = r / sqrt(2),
rows = floor(size.y / w), rows = floor(size.y / w),
columns = floor(size.x / w), columns = floor(size.x / w),
pt = is_undef(start) ? [rands(0, size.x, 1, sd)[0], rands(0, size.y, 1, sd + 1)[0]] : start, pts = is_undef(start) ? [[rands(0, size.x, 1, sd)[0], rands(0, size.y, 1, sd + 1)[0]]] :
active = [pt], is_num(start[0]) ? [start] : start,
px = floor(pt.x / w), active = pts,
py = floor(pt.y / w), pij = [for(pt = pts) [floor(pt.x / w), floor(pt.y / w), pt]],
grid_row = [for(i = [0:columns - 1]) undef], grid = [
grid = m_replace([for(j = [0:rows - 1]) grid_row], px, py, pt) for(j = [0:rows - 1])
[
for(i = [0:columns - 1])
let(found = find_index(pij, function(ij) ij[0] == i && ij[1] == j))
if(found != -1)
found[2]
else
undef
]
]
) )
[r, k, w, active, grid, rows, columns, []]; [r, k, w, active, grid, rows, columns, []];