mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-03-14 19:19:47 +01:00
refactor
This commit is contained in:
parent
ac8ffb31df
commit
9da95c39bc
4
src/util/_impl/_shuffle_impl.scad
Normal file
4
src/util/_impl/_shuffle_impl.scad
Normal file
@ -0,0 +1,4 @@
|
||||
use <../swap.scad>;
|
||||
|
||||
function _shuffle(lt, indices, leng, i = 0) =
|
||||
i == leng ? lt : _shuffle(swap(lt, i, indices[i]), indices, leng, i + 1);
|
@ -1,4 +1,14 @@
|
||||
use <swap.scad>;
|
||||
/**
|
||||
* shuffle.scad
|
||||
*
|
||||
* @copyright Justin Lin, 2021
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-shuffle.html
|
||||
*
|
||||
**/
|
||||
|
||||
use <_impl/_shuffle_impl.scad>;
|
||||
|
||||
function shuffle(lt, seed) =
|
||||
let(
|
||||
@ -6,6 +16,3 @@ function shuffle(lt, seed) =
|
||||
indices = [for(i = is_undef(seed) ? rands(0, leng, leng) : rands(0, leng, leng, seed)) floor(i)]
|
||||
)
|
||||
_shuffle(lt, indices, leng);
|
||||
|
||||
function _shuffle(lt, indices, leng, i = 0) =
|
||||
i == leng ? lt : _shuffle(swap(lt, i, indices[i]), indices, leng, i + 1);
|
Loading…
x
Reference in New Issue
Block a user