mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-28 15:59:45 +00:00
Fix quant docs to point out non-integer quanta are allowed.
This commit is contained in:
parent
0db5d6dd06
commit
ee504540c3
2 changed files with 27 additions and 12 deletions
33
math.scad
33
math.scad
|
@ -308,7 +308,8 @@ function atanh(x) =
|
|||
// num = quant(x, y);
|
||||
// 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.
|
||||
// The value of `y` does NOT have to be an integer. If `x` is a list, then every item
|
||||
// in that list will be recursively quantized.
|
||||
// Arguments:
|
||||
// x = The value to quantize.
|
||||
// y = The non-zero integer quantum of the quantization.
|
||||
|
@ -326,9 +327,11 @@ function atanh(x) =
|
|||
// k = quant(10.5,3); // Returns: 12
|
||||
// l = quant(11,3); // Returns: 12
|
||||
// m = quant(12,3); // Returns: 12
|
||||
// n = quant([12,13,13.1,14,14.1,15,16],4); // Returns: [12,12,12,16,16,16,16]
|
||||
// o = quant([9,10,10.4,10.5,11,12],3); // Returns: [9,9,9,12,12,12]
|
||||
// p = quant([[9,10,10.4],[10.5,11,12]],3); // Returns: [[9,9,9],[12,12,12]]
|
||||
// n = quant(11,2.5); // Returns: 10
|
||||
// o = quant(12,2.5); // Returns: 12.5
|
||||
// p = quant([12,13,13.1,14,14.1,15,16],4); // Returns: [12,12,12,16,16,16,16]
|
||||
// q = quant([9,10,10.4,10.5,11,12],3); // Returns: [9,9,9,12,12,12]
|
||||
// r = quant([[9,10,10.4],[10.5,11,12]],3); // Returns: [[9,9,9],[12,12,12]]
|
||||
function quant(x,y) =
|
||||
assert( is_finite(y) && y>0, "The quantum `y` must be a non zero integer.")
|
||||
is_list(x)
|
||||
|
@ -342,7 +345,8 @@ function quant(x,y) =
|
|||
// num = quantdn(x, y);
|
||||
// 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.
|
||||
// The value of `y` does NOT have to be an integer. If `x` is a list, then every item in that
|
||||
// list will be recursively quantized down.
|
||||
// Arguments:
|
||||
// x = The value to quantize.
|
||||
// y = The non-zero integer quantum of the quantization.
|
||||
|
@ -360,9 +364,11 @@ function quant(x,y) =
|
|||
// k = quantdn(10.5,3); // Returns: 9
|
||||
// l = quantdn(11,3); // Returns: 9
|
||||
// m = quantdn(12,3); // Returns: 12
|
||||
// n = quantdn([12,13,13.1,14,14.1,15,16],4); // Returns: [12,12,12,12,12,12,16]
|
||||
// o = quantdn([9,10,10.4,10.5,11,12],3); // Returns: [9,9,9,9,9,12]
|
||||
// p = quantdn([[9,10,10.4],[10.5,11,12]],3); // Returns: [[9,9,9],[9,9,12]]
|
||||
// n = quantdn(11,2.5); // Returns: 10
|
||||
// o = quantdn(12,2.5); // Returns: 10
|
||||
// p = quantdn([12,13,13.1,14,14.1,15,16],4); // Returns: [12,12,12,12,12,12,16]
|
||||
// q = quantdn([9,10,10.4,10.5,11,12],3); // Returns: [9,9,9,9,9,12]
|
||||
// r = quantdn([[9,10,10.4],[10.5,11,12]],3); // Returns: [[9,9,9],[9,9,12]]
|
||||
function quantdn(x,y) =
|
||||
assert( is_finite(y) && y>0, "The quantum `y` must be a non zero integer.")
|
||||
is_list(x)
|
||||
|
@ -376,7 +382,8 @@ function quantdn(x,y) =
|
|||
// num = quantup(x, y);
|
||||
// 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.
|
||||
// The value of `y` does NOT have to be an integer. If `x` is a list, then every item in
|
||||
// that list will be recursively quantized up.
|
||||
// Arguments:
|
||||
// x = The value to quantize.
|
||||
// y = The non-zero integer quantum of the quantization.
|
||||
|
@ -394,9 +401,11 @@ function quantdn(x,y) =
|
|||
// k = quantup(10.5,3); // Returns: 12
|
||||
// l = quantup(11,3); // Returns: 12
|
||||
// m = quantup(12,3); // Returns: 12
|
||||
// o = quantup([12,13,13.1,14,14.1,15,16],4); // Returns: [12,16,16,16,16,16,16]
|
||||
// p = quantup([9,10,10.4,10.5,11,12],3); // Returns: [9,12,12,12,12,12]
|
||||
// quantup([[9,10,10.4],[10.5,11,12]],3); // Returns: [[9,12,12],[12,12,12]]
|
||||
// n = quantdn(11,2.5); // Returns: 12.5
|
||||
// o = quantdn(12,2.5); // Returns: 12.5
|
||||
// p = quantup([12,13,13.1,14,14.1,15,16],4); // Returns: [12,16,16,16,16,16,16]
|
||||
// q = quantup([9,10,10.4,10.5,11,12],3); // Returns: [9,12,12,12,12,12]
|
||||
// r = quantup([[9,10,10.4],[10.5,11,12]],3); // Returns: [[9,12,12],[12,12,12]]
|
||||
function quantup(x,y) =
|
||||
assert( is_finite(y) && y>0, "The quantum `y` must be a non zero integer.")
|
||||
is_list(x)
|
||||
|
|
|
@ -13,6 +13,8 @@ module test_quant() {
|
|||
assert_equal(quant(3,3), 3);
|
||||
assert_equal(quant(4,3), 3);
|
||||
assert_equal(quant(7,3), 6);
|
||||
assert_equal(quant(12,2.5), 12.5);
|
||||
assert_equal(quant(11,2.5), 10.0);
|
||||
assert_equal(quant([12,13,13.1,14,14.1,15,16],4), [12,12,12,16,16,16,16]);
|
||||
assert_equal(quant([9,10,10.4,10.5,11,12],3), [9,9,9,12,12,12]);
|
||||
assert_equal(quant([[9,10,10.4],[10.5,11,12]],3), [[9,9,9],[12,12,12]]);
|
||||
|
@ -31,6 +33,8 @@ module test_quantdn() {
|
|||
assert_equal(quantdn(3,3), 3);
|
||||
assert_equal(quantdn(4,3), 3);
|
||||
assert_equal(quantdn(7,3), 6);
|
||||
assert_equal(quantdn(12,2.5), 10.0);
|
||||
assert_equal(quantdn(11,2.5), 10.0);
|
||||
assert_equal(quantdn([12,13,13.1,14,14.1,15,16],4), [12,12,12,12,12,12,16]);
|
||||
assert_equal(quantdn([9,10,10.4,10.5,11,12],3), [9,9,9,9,9,12]);
|
||||
assert_equal(quantdn([[9,10,10.4],[10.5,11,12]],3), [[9,9,9],[9,9,12]]);
|
||||
|
@ -49,6 +53,8 @@ module test_quantup() {
|
|||
assert_equal(quantup(3,3), 3);
|
||||
assert_equal(quantup(4,3), 6);
|
||||
assert_equal(quantup(7,3), 9);
|
||||
assert_equal(quantup(12,2.5), 12.5);
|
||||
assert_equal(quantup(11,2.5), 12.5);
|
||||
assert_equal(quantup([12,13,13.1,14,14.1,15,16],4), [12,16,16,16,16,16,16]);
|
||||
assert_equal(quantup([9,10,10.4,10.5,11,12],3), [9,12,12,12,12,12]);
|
||||
assert_equal(quantup([[9,10,10.4],[10.5,11,12]],3), [[9,12,12],[12,12,12]]);
|
||||
|
|
Loading…
Reference in a new issue