mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-28 15:59:45 +00:00
quant\*() now work on vectors and pointlists.
This commit is contained in:
parent
0054754cb0
commit
e4ecb21217
1 changed files with 12 additions and 3 deletions
15
math.scad
15
math.scad
|
@ -20,28 +20,37 @@ EPSILON = 1e-9; // A really small value useful in comparing FP numbers. ie: ab
|
|||
// Function: quant()
|
||||
// Description:
|
||||
// Quantize a value `x` to an integer multiple of `y`, rounding to the nearest multiple.
|
||||
// If `x` is a list, then every item in that list will be recursively quantized.
|
||||
// Arguments:
|
||||
// x = The value to quantize.
|
||||
// y = The multiple to quantize to.
|
||||
function quant(x,y) = floor(x/y+0.5)*y;
|
||||
function quant(x,y) =
|
||||
is_list(x)? [for (v=x) quant(v,y)] :
|
||||
floor(x/y+0.5)*y;
|
||||
|
||||
|
||||
// Function: quantdn()
|
||||
// Description:
|
||||
// Quantize a value `x` to an integer multiple of `y`, rounding down to the previous multiple.
|
||||
// If `x` is a list, then every item in that list will be recursively quantized down.
|
||||
// Arguments:
|
||||
// x = The value to quantize.
|
||||
// y = The multiple to quantize to.
|
||||
function quantdn(x,y) = floor(x/y)*y;
|
||||
function quantdn(x,y) =
|
||||
is_list(x)? [for (v=x) quantdn(v,y)] :
|
||||
floor(x/y)*y;
|
||||
|
||||
|
||||
// Function: quantup()
|
||||
// Description:
|
||||
// Quantize a value `x` to an integer multiple of `y`, rounding up to the next multiple.
|
||||
// If `x` is a list, then every item in that list will be recursively quantized up.
|
||||
// Arguments:
|
||||
// x = The value to quantize.
|
||||
// y = The multiple to quantize to.
|
||||
function quantup(x,y) = ceil(x/y)*y;
|
||||
function quantup(x,y) =
|
||||
is_list(x)? [for (v=x) quantup(v,y)] :
|
||||
ceil(x/y)*y;
|
||||
|
||||
|
||||
// Function: constrain()
|
||||
|
|
Loading…
Reference in a new issue