mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-13 18:24:28 +02:00
refactor
This commit is contained in:
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) =
|
function shuffle(lt, seed) =
|
||||||
let(
|
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)]
|
indices = [for(i = is_undef(seed) ? rands(0, leng, leng) : rands(0, leng, leng, seed)) floor(i)]
|
||||||
)
|
)
|
||||||
_shuffle(lt, indices, leng);
|
_shuffle(lt, indices, leng);
|
||||||
|
|
||||||
function _shuffle(lt, indices, leng, i = 0) =
|
|
||||||
i == leng ? lt : _shuffle(swap(lt, i, indices[i]), indices, leng, i + 1);
|
|
Reference in New Issue
Block a user