Fixed calls to vmul() with heteerogenous vector sizes.

This commit is contained in:
Garth Minette 2020-08-02 23:23:50 -07:00
parent 59aebd33ce
commit e56f953c1c
8 changed files with 26 additions and 24 deletions

View file

@ -285,7 +285,7 @@ function attach_geom_size(geom) =
) [2*maxxr,2*maxyr,l] ) [2*maxxr,2*maxyr,l]
) : type == "spheroid"? ( //r ) : type == "spheroid"? ( //r
let( r=geom[1] ) let( r=geom[1] )
is_num(r)? [2,2,2]*r : vmul([2,2,2],r) is_num(r)? [2,2,2]*r : vmul([2,2,2],point3d(r))
) : type == "vnf_extent" || type=="vnf_isect"? ( //vnf ) : type == "vnf_extent" || type=="vnf_isect"? ( //vnf
let( let(
mm = pointlist_bounds(geom[1][0]), mm = pointlist_bounds(geom[1][0]),
@ -298,7 +298,7 @@ function attach_geom_size(geom) =
) [maxx, size.y] ) [maxx, size.y]
) : type == "circle"? ( //r ) : type == "circle"? ( //r
let( r=geom[1] ) let( r=geom[1] )
is_num(r)? [2,2]*r : vmul([2,2],r) is_num(r)? [2,2]*r : vmul([2,2],point2d(r))
) : type == "path_isect" || type == "path_extent"? ( //path ) : type == "path_isect" || type == "path_extent"? ( //path
let( let(
mm = pointlist_bounds(geom[1]), mm = pointlist_bounds(geom[1]),
@ -430,8 +430,8 @@ function find_anchor(anchor, geom) =
) : type == "cyl"? ( //r1, r2, l, shift ) : type == "cyl"? ( //r1, r2, l, shift
let( let(
rr1=geom[1], rr2=geom[2], l=geom[3], shift=point2d(geom[4]), rr1=geom[1], rr2=geom[2], l=geom[3], shift=point2d(geom[4]),
r1 = is_num(rr1)? [rr1,rr1] : rr1, r1 = is_num(rr1)? [rr1,rr1] : point2d(rr1),
r2 = is_num(rr2)? [rr2,rr2] : rr2, r2 = is_num(rr2)? [rr2,rr2] : point2d(rr2),
u = (anchor.z+1)/2, u = (anchor.z+1)/2,
axy = unit(point2d(anchor),[0,0]), axy = unit(point2d(anchor),[0,0]),
bot = point3d(vmul(r1,axy), -l/2), bot = point3d(vmul(r1,axy), -l/2),
@ -447,9 +447,9 @@ function find_anchor(anchor, geom) =
) : type == "spheroid"? ( //r ) : type == "spheroid"? ( //r
let( let(
rr = geom[1], rr = geom[1],
r = is_num(rr)? [rr,rr,rr] : rr, r = is_num(rr)? [rr,rr,rr] : point3d(rr),
anchor = unit(point3d(anchor),CENTER), anchor = unit(point3d(anchor),CENTER),
pos = point3d(cp) + vmul(r,anchor) + offset, pos = point3d(cp) + vmul(r,anchor) + point3d(offset),
vec = unit(vmul(r,anchor),UP) vec = unit(vmul(r,anchor),UP)
) [anchor, pos, vec, oang] ) [anchor, pos, vec, oang]
) : type == "vnf_isect"? ( //vnf ) : type == "vnf_isect"? ( //vnf
@ -519,10 +519,10 @@ function find_anchor(anchor, geom) =
) : type == "circle"? ( //r ) : type == "circle"? ( //r
let( let(
rr = geom[1], rr = geom[1],
r = is_num(rr)? [rr,rr] : rr, r = is_num(rr)? [rr,rr] : point2d(rr),
pos = point2d(cp) + vmul(r,anchor) + offset,
anchor = unit(point2d(anchor),[0,0]), anchor = unit(point2d(anchor),[0,0]),
vec = unit(vmul([r.y,r.x],anchor),[0,1]) pos = point2d(cp) + vmul(r,anchor) + point2d(offset),
vec = unit(vmul(r,anchor),[0,1])
) [anchor, pos, vec, 0] ) [anchor, pos, vec, 0]
) : type == "path_isect"? ( //path ) : type == "path_isect"? ( //path
let( let(
@ -970,7 +970,8 @@ module edge_profile(edges=EDGES_ALL, except=[], convexity=10) {
$attach_anchor = anch; $attach_anchor = anch;
$attach_norot = true; $attach_norot = true;
$tags = "mask"; $tags = "mask";
length = sum(vmul($parent_size, [for (x=vec) x?0:1]))+0.1; psize = point3d($parent_size);
length = [for (i=[0:2]) if(!vec[i]) psize[i]][0]+0.1;
rotang = rotang =
vec.z<0? [90,0,180+vang(point2d(vec))] : vec.z<0? [90,0,180+vang(point2d(vec))] :
vec.z==0 && sign(vec.x)==sign(vec.y)? 135+vang(point2d(vec)) : vec.z==0 && sign(vec.x)==sign(vec.y)? 135+vang(point2d(vec)) :

View file

@ -949,7 +949,7 @@ module ovoid_spread(r=undef, d=undef, n=100, cone_ang=90, scale=[1,1,1], perp=tr
for ($idx = idx(theta_phis)) { for ($idx = idx(theta_phis)) {
tp = theta_phis[$idx]; tp = theta_phis[$idx];
xyz = spherical_to_xyz(r, tp[0], tp[1]); xyz = spherical_to_xyz(r, tp[0], tp[1]);
$pos = vmul(xyz,scale); $pos = vmul(xyz,point3d(scale,1));
$theta = tp[0]; $theta = tp[0];
$phi = tp[1]; $phi = tp[1];
$rad = r; $rad = r;

View file

@ -36,7 +36,7 @@ NAN = acos(2); // The value `nan`, useful for comparisons.
function sqr(x) = function sqr(x) =
is_list(x) ? [for(val=x) sqr(val)] : is_list(x) ? [for(val=x) sqr(val)] :
is_finite(x) ? x*x : is_finite(x) ? x*x :
assert(is_finite(x) || is_vector(x), "Input is not neither a number nor a list of numbers."); assert(is_finite(x) || is_vector(x), "Input is not a number nor a list of numbers.");
// Function: log2() // Function: log2()

View file

@ -31,9 +31,13 @@ _partition_cutpaths = [
function _partition_cutpath(l, h, cutsize, cutpath, gap) = function _partition_cutpath(l, h, cutsize, cutpath, gap) =
let( let(
check = assert(is_finite(l))
assert(is_finite(h))
assert(is_finite(gap))
assert(is_finite(cutsize) || is_vector(cutsize,2))
assert(is_string(cutpath) || is_path(cutpath,2)),
cutsize = is_vector(cutsize)? cutsize : [cutsize*2, cutsize], cutsize = is_vector(cutsize)? cutsize : [cutsize*2, cutsize],
cutpath = is_path(cutpath)? cutpath : ( cutpath = is_path(cutpath)? cutpath : (
assert(is_string(cutpath), "cutpath must be a 2D path or a string.")
let(idx = search([cutpath], _partition_cutpaths)) let(idx = search([cutpath], _partition_cutpaths))
idx==[[]]? assert(in_list(cutpath,_partition_cutpaths,idx=0)) : idx==[[]]? assert(in_list(cutpath,_partition_cutpaths,idx=0)) :
_partition_cutpaths[idx.x][1] _partition_cutpaths[idx.x][1]
@ -79,7 +83,7 @@ function _partition_cutpath(l, h, cutsize, cutpath, gap) =
// partition_mask(w=20, cutpath="jigsaw"); // partition_mask(w=20, cutpath="jigsaw");
module partition_mask(l=100, w=100, h=100, cutsize=10, cutpath=undef, gap=0, inverse=false, spin=0, orient=UP) module partition_mask(l=100, w=100, h=100, cutsize=10, cutpath=undef, gap=0, inverse=false, spin=0, orient=UP)
{ {
cutsize = is_vector(cutsize)? cutsize : [cutsize*2, cutsize]; cutsize = is_vector(cutsize)? point2d(cutsize) : [cutsize*2, cutsize];
path = _partition_cutpath(l, h, cutsize, cutpath, gap); path = _partition_cutpath(l, h, cutsize, cutpath, gap);
fullpath = concat(path, [[l/2,w*(inverse?-1:1)], [-l/2,w*(inverse?-1:1)]]); fullpath = concat(path, [[l/2,w*(inverse?-1:1)], [-l/2,w*(inverse?-1:1)]]);
rot(from=UP,to=orient) { rot(from=UP,to=orient) {

View file

@ -785,7 +785,7 @@ function rect(size=1, center, rounding=0, chamfer=0, anchor, spin=0) =
assert(is_num(rounding) || len(rounding)==4) assert(is_num(rounding) || len(rounding)==4)
let( let(
size = is_num(size)? [size,size] : point2d(size), size = is_num(size)? [size,size] : point2d(size),
anchor = get_anchor(anchor, center, FRONT+LEFT, FRONT+LEFT), anchor = point2d(get_anchor(anchor, center, FRONT+LEFT, FRONT+LEFT)),
complex = rounding!=0 || chamfer!=0 complex = rounding!=0 || chamfer!=0
) )
(rounding==0 && chamfer==0)? let( (rounding==0 && chamfer==0)? let(

View file

@ -558,12 +558,12 @@ function scale(v=1, p=undef) =
len(v)==2? affine2d_scale(v) : affine3d_scale(point3d(v)) len(v)==2? affine2d_scale(v) : affine3d_scale(point3d(v))
) : ( ) : (
assert(is_list(p)) assert(is_list(p))
is_num(p.x)? vmul(p,v) : is_vector(p)? ( len(p)==2? vmul(p,point2d(v)) : vmul(p,point3d(v,1)) ) :
is_vnf(p)? let(inv=product([for (x=v) x<0? -1 : 1])) [ is_vnf(p)? let(inv=product([for (x=v) x<0? -1 : 1])) [
scale(v=v,p=p.x), scale(v=v, p=p[0]),
inv>=0? p.y : [for (l=p.y) reverse(l)] inv>=0? p[1] : [for (l=p[1]) reverse(l)]
] : ] :
[for (l=p) is_vector(l)? vmul(l,v) : scale(v=v, p=l)] [ for (pp=p) scale(v=v, p=pp) ]
); );

View file

@ -64,13 +64,10 @@ function vang(v) =
// Example: // Example:
// vmul([3,4,5], [8,7,6]); // Returns [24, 28, 30] // vmul([3,4,5], [8,7,6]); // Returns [24, 28, 30]
function vmul(v1, v2) = function vmul(v1, v2) =
// this thighter check can be done yet because it would break other codes in the library assert( is_vector(v1) && is_vector(v2,len(v1)), "Incompatible vectors")
// assert( is_vector(v1) && is_vector(v2,len(v1)), "Incompatible vectors")
assert( is_vector(v1) && is_vector(v2), "Invalid vector(s)")
[for (i = [0:1:len(v1)-1]) v1[i]*v2[i]]; [for (i = [0:1:len(v1)-1]) v1[i]*v2[i]];
// Function: vdiv() // Function: vdiv()
// Description: // Description:
// Element-wise vector division. Divides each element of vector `v1` by // Element-wise vector division. Divides each element of vector `v1` by

View file

@ -8,7 +8,7 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,401]; BOSL_VERSION = [2,0,402];
// Section: BOSL Library Version Functions // Section: BOSL Library Version Functions