Merge pull request #603 from revarbat/revarbat_dev

Bugfix for line_of()
This commit is contained in:
Revar Desmera 2021-07-06 22:45:52 -07:00 committed by GitHub
commit 4aee6f29ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 4 deletions

View file

@ -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 :

View file

@ -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.")

View file

@ -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

View file

@ -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