From f2b69a9ce0055979b5f8572cfcf734c8c252f13d Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Fri, 23 Apr 2021 07:11:56 +0800 Subject: [PATCH] performance improved --- src/experimental/_impl/_tiles_wfc_impl.scad | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/experimental/_impl/_tiles_wfc_impl.scad b/src/experimental/_impl/_tiles_wfc_impl.scad index f615ee95..8bce69c5 100644 --- a/src/experimental/_impl/_tiles_wfc_impl.scad +++ b/src/experimental/_impl/_tiles_wfc_impl.scad @@ -78,10 +78,11 @@ function wf_collapse(wf, x, y) = weights = wf_weights(wf), states_xy = wf_eigenstates_at(wf, x, y), weights_xy = [ - for(state = hashmap_keys(weights)) - if(has(states_xy, state)) - [state, hashmap_get(weights, state)] - ], + for(state = states_xy) + let(w = hashmap_get(weights, state)) + if(w != undef) + [state, w] + ], totalWeights = sum([for(w = weights_xy) w[1]]), threshold = rand() * totalWeights, states_weights = weights_xy