diff --git a/distributors.scad b/distributors.scad index db34690..387b88b 100644 --- a/distributors.scad +++ b/distributors.scad @@ -130,7 +130,7 @@ function line_of(spacing, n, l, p1, p2) = assert(is_undef(p2) || is_vector(p2)) let( ll = !is_undef(l)? scalar_vec3(l, 0) : - (!is_undef(spacing) && !is_undef(n))? (n * scalar_vec3(spacing, 0)) : + (!is_undef(spacing) && !is_undef(n))? ((n-1) * scalar_vec3(spacing, 0)) : (!is_undef(p1) && !is_undef(p2))? point3d(p2-p1) : undef, cnt = !is_undef(n)? n : diff --git a/math.scad b/math.scad index 45755f5..2885de8 100644 --- a/math.scad +++ b/math.scad @@ -330,7 +330,7 @@ function atanh(x) = // 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]] function quant(x,y) = - assert( is_int(y) && y>0, "The quantum `y` must be a non zero integer.") + assert( is_finite(y) && y>0, "The quantum `y` must be a non zero integer.") is_list(x) ? [for (v=x) quant(v,y)] : assert( is_finite(x), "The input to quantize is not a number nor a list of numbers.") @@ -364,7 +364,7 @@ function quant(x,y) = // 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]] function quantdn(x,y) = - assert( is_int(y) && y>0, "The quantum `y` must be a non zero integer.") + assert( is_finite(y) && y>0, "The quantum `y` must be a non zero integer.") is_list(x) ? [for (v=x) quantdn(v,y)] : assert( is_finite(x), "The input to quantize must be a number or a list of numbers.") @@ -398,7 +398,7 @@ function quantdn(x,y) = // 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]] function quantup(x,y) = - assert( is_int(y) && y>0, "The quantum `y` must be a non zero integer.") + assert( is_finite(y) && y>0, "The quantum `y` must be a non zero integer.") is_list(x) ? [for (v=x) quantup(v,y)] : assert( is_finite(x), "The input to quantize must be a number or a list of numbers.") diff --git a/tests/test_distributors.scad b/tests/test_distributors.scad new file mode 100644 index 0000000..5704c96 --- /dev/null +++ b/tests/test_distributors.scad @@ -0,0 +1,19 @@ +include <../std.scad> + + +module test_line_of() { + assert_equal(line_of(l=100,n=5), [[-50,0,0],[-25,0,0],[0,0,0],[25,0,0],[50,0,0]]); + assert_equal(line_of(20,n=5), [[-40,0,0],[-20,0,0],[0,0,0],[20,0,0],[40,0,0]]); + assert_equal(line_of(spacing=20,n=5), [[-40,0,0],[-20,0,0],[0,0,0],[20,0,0],[40,0,0]]); + assert_equal(line_of(spacing=[0,20],n=5), [[0,-40,0],[0,-20,0],[0,0,0],[0,20,0],[0,40,0]]); + + assert_equal(line_of(p1=[0,0],l=100,n=5), [[0,0,0],[25,0,0],[50,0,0],[75,0,0],[100,0,0]]); + assert_equal(line_of(p1=[0,0],20,n=5), [[0,0,0],[20,0,0],[40,0,0],[60,0,0],[80,0,0]]); + assert_equal(line_of(p1=[0,0],spacing=20,n=5), [[0,0,0],[20,0,0],[40,0,0],[60,0,0],[80,0,0]]); + assert_equal(line_of(p1=[0,0],spacing=[0,20],n=5), [[0,0,0],[0,20,0],[0,40,0],[0,60,0],[0,80,0]]); +} +test_line_of(); + + + +// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap diff --git a/tests/test_shapes2d.scad b/tests/test_shapes2d.scad index aa5c4f6..4c69e25 100644 --- a/tests/test_shapes2d.scad +++ b/tests/test_shapes2d.scad @@ -242,5 +242,11 @@ module test_mask2d_ogee() { test_mask2d_ogee(); +module test_dashed_stroke() { + segs = dashed_stroke([[0,0],[10,0]], dashpat=[3,2], closed=false); + assert_equal(segs,[[[0,0],[3,0]], [[5,0],[8,0]]]); +} +test_dashed_stroke(); + // vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap