mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-06 14:56:47 +02:00
sum up totalWeights directly
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
use <util/flat.scad>;
|
use <util/flat.scad>;
|
||||||
use <util/has.scad>;
|
use <util/has.scad>;
|
||||||
use <util/sum.scad>;
|
|
||||||
use <util/rand.scad>;
|
use <util/rand.scad>;
|
||||||
use <util/slice.scad>;
|
use <util/slice.scad>;
|
||||||
use <util/some.scad>;
|
use <util/some.scad>;
|
||||||
@@ -83,12 +82,16 @@ function wf_collapse(wf, x, y) =
|
|||||||
if(w != undef)
|
if(w != undef)
|
||||||
[state, w]
|
[state, w]
|
||||||
],
|
],
|
||||||
totalWeights = sum([for(w = weights_xy) w[1]]),
|
totalWeights = _totalWeights(weights_xy, len(weights_xy)),
|
||||||
threshold = rand() * totalWeights,
|
threshold = rand() * totalWeights,
|
||||||
states_weights = weights_xy
|
states_weights = weights_xy
|
||||||
)
|
)
|
||||||
_wf_collapse(wf, x, y, states_weights, len(states_weights), threshold);
|
_wf_collapse(wf, x, y, states_weights, len(states_weights), threshold);
|
||||||
|
|
||||||
|
function _totalWeights(weights_xy, leng, i = 0) =
|
||||||
|
i == leng ? 0 :
|
||||||
|
weights_xy[i][1] + _totalWeights(weights_xy, leng, i + 1);
|
||||||
|
|
||||||
function _wf_collapse(wf, x, y, states_weights, leng, threshold, i = 0) =
|
function _wf_collapse(wf, x, y, states_weights, leng, threshold, i = 0) =
|
||||||
i == leng ? wf :
|
i == leng ? wf :
|
||||||
let(
|
let(
|
||||||
|
Reference in New Issue
Block a user