1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-06 14:56:47 +02:00

refactor: vector addition

This commit is contained in:
Justin Lin
2022-04-14 10:47:18 +08:00
parent 2b58eb7528
commit 6250cce455
2 changed files with 7 additions and 10 deletions

View File

@@ -11,13 +11,12 @@
module vrn2_space(size, grid_w, seed, spacing = 1, r = 0, delta = 0, chamfer = false, region_type = "square") { module vrn2_space(size, grid_w, seed, spacing = 1, r = 0, delta = 0, chamfer = false, region_type = "square") {
function cell_pt(fcord, seed, x, y, gw, gh) = function cell_pt(fcord, seed, x, y, gw, gh) =
let( let(
nx = fcord.x + x, nv = fcord + [x, y],
ny = fcord.y + y, sd_x = (nv.x + gw) % gw,
sd_x = (nx + gw) % gw, sd_y = (nv.y + gh) % gh,
sd_y = (ny + gh) % gh,
sd_base = abs(sd_x + sd_y * grid_w) sd_base = abs(sd_x + sd_y * grid_w)
) )
([nx, ny] + rands(0.1, 0.9, 2, seed_value = seed + sd_base)) * grid_w; (nv + rands(0.1, 0.9, 2, seed_value = seed + sd_base)) * grid_w;
// 9-nearest-neighbor // 9-nearest-neighbor
function _neighbors(fcord, seed, grid_w, gw, gh) = function _neighbors(fcord, seed, grid_w, gw, gh) =

View File

@@ -16,12 +16,10 @@ module vrn3_space(size, grid_w, seed, spacing = 1) {
let(range = [-1:1]) let(range = [-1:1])
for(z = range, y = range, x = range) for(z = range, y = range, x = range)
let( let(
nx = fcord.x + x, nv = fcord + [x, y, z],
ny = fcord.y + y, sd_base = abs(nv * [1, grid_w, grid_w ^ 2])
nz = fcord.z + z,
sd_base = abs(nx + ny * grid_w + nz * grid_w * grid_w)
) )
([nx, ny, nz] + rands(0.1, 0.9, 3, seed_value = seed + sd_base)) * grid_w (nv + rands(0.1, 0.9, 3, seed_value = seed + sd_base)) * grid_w
]; ];
space_size = grid_w * 3; space_size = grid_w * 3;