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

refafctor: search in notCollapsedCoords

This commit is contained in:
Justin Lin
2022-04-23 12:13:48 +08:00
parent 79f8495090
commit 4d0c83ddc8
2 changed files with 17 additions and 9 deletions

View File

@@ -73,10 +73,11 @@ function _replaceStatesAt(wf, x, y, states) =
m_replace(wf_eigenstates(wf), x, y, states) m_replace(wf_eigenstates(wf), x, y, states)
]; ];
function wf_not_collapsed_coords(wf) = function wf_not_collapsed_coords(wf, notCollaspedCoords) =
let(eigenstates = wf_eigenstates(wf), we = wf_width(wf) - 1, he = wf_height(wf) - 1, rx = [0:we]) let(eigenstates = wf_eigenstates(wf))
[ [
for(y = [0:he], x = rx) for(coord = notCollaspedCoords)
let(y = coord.y, x = coord.x)
if(len(eigenstates[y][x]) != 1) [x, y] if(len(eigenstates[y][x]) != 1) [x, y]
]; ];
@@ -172,7 +173,7 @@ function generate(nbr_dirs, compatibilities, wf, notCollaspedCoords, collapsing_
weights = coord_weights[2], weights = coord_weights[2],
nwf = propagate(nbr_dirs, compatibilities, wf_collapse(wf, coord_weights.x, coord_weights.y, weights), coord_weights) nwf = propagate(nbr_dirs, compatibilities, wf_collapse(wf, coord_weights.x, coord_weights.y, weights), coord_weights)
) )
generate(nbr_dirs, compatibilities, nwf, wf_not_collapsed_coords(nwf), collapsing_method); generate(nbr_dirs, compatibilities, nwf, wf_not_collapsed_coords(nwf, notCollaspedCoords), collapsing_method);
function neighbor_dirs(x, y, width, height) = [ function neighbor_dirs(x, y, width, height) = [
if(x > 0) [-1, 0], // left if(x > 0) [-1, 0], // left

View File

@@ -7,9 +7,11 @@ function tile_wfc(size, sample, method = "length") =
let( let(
w = size.x, w = size.x,
h = size.y, h = size.y,
rangey = [0:h - 1],
rangex = [0:w - 1],
nbr_dirs = [ nbr_dirs = [
for(y = [0:h - 1]) for(y = rangey)
[for(x = [0:w - 1]) neighbor_dirs(x, y, w, h)] [for(x = rangex) neighbor_dirs(x, y, w, h)]
], ],
// random start // random start
x = floor(rand(w * 0.25, w * 0.75)), x = floor(rand(w * 0.25, w * 0.75)),
@@ -17,15 +19,20 @@ function tile_wfc(size, sample, method = "length") =
compatibilities = compatibilities_of_tiles(sample), compatibilities = compatibilities_of_tiles(sample),
wf = wave_function(w, h, weights_of_tiles(sample)), wf = wave_function(w, h, weights_of_tiles(sample)),
all_weights = wf_weights(wf), all_weights = wf_weights(wf),
states = wf_eigenstates_at(wf, x, y), weights = [for(state = wf_eigenstates_at(wf, x, y)) get_state_weight(all_weights, state)],
weights = [for(state = states) get_state_weight(all_weights, state)],
first_collasped_propagated = propagate( first_collasped_propagated = propagate(
nbr_dirs, nbr_dirs,
compatibilities, compatibilities,
wf_collapse(wf, x, y, weights), wf_collapse(wf, x, y, weights),
[x, y] [x, y]
), ),
notCollapsedCoords = wf_not_collapsed_coords(first_collasped_propagated) fstp_states = wf_eigenstates(wf),
notCollapsedCoords = [
for(y = rangey)
let(y_states = fstp_states[y])
for(x = rangex)
if(len(y_states[x]) != 1) [x, y]
]
) )
generate(nbr_dirs, compatibilities, first_collasped_propagated, notCollapsedCoords, collapsing(method)); generate(nbr_dirs, compatibilities, first_collasped_propagated, notCollapsedCoords, collapsing(method));