mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +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()
|
// Function: quant()
|
||||||
// Description:
|
// Description:
|
||||||
// Quantize a value `x` to an integer multiple of `y`, rounding to the nearest multiple.
|
// 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:
|
// Arguments:
|
||||||
// x = The value to quantize.
|
// x = The value to quantize.
|
||||||
// y = The multiple to quantize to.
|
// 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()
|
// Function: quantdn()
|
||||||
// Description:
|
// Description:
|
||||||
// Quantize a value `x` to an integer multiple of `y`, rounding down to the previous multiple.
|
// 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:
|
// Arguments:
|
||||||
// x = The value to quantize.
|
// x = The value to quantize.
|
||||||
// y = The multiple to quantize to.
|
// 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()
|
// Function: quantup()
|
||||||
// Description:
|
// Description:
|
||||||
// Quantize a value `x` to an integer multiple of `y`, rounding up to the next multiple.
|
// 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:
|
// Arguments:
|
||||||
// x = The value to quantize.
|
// x = The value to quantize.
|
||||||
// y = The multiple to quantize to.
|
// 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()
|
// Function: constrain()
|
||||||
|
|
Loading…
Reference in a new issue