From ee30513644db22f36b1e22df8ea932ccfd00a1f7 Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Tue, 3 Mar 2020 19:17:14 -0800 Subject: [PATCH] Bugfix for rot --- shapes2d.scad | 2 +- transforms.scad | 11 ++++++++--- vectors.scad | 8 +++++--- version.scad | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/shapes2d.scad b/shapes2d.scad index d4a1993..d9148f6 100644 --- a/shapes2d.scad +++ b/shapes2d.scad @@ -633,7 +633,7 @@ module regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false, r = get_radius(r1=ir*sc, r2=or, r=r, d1=id*sc, d2=od, d=d, dflt=side/2/sin(180/n)); assert(!is_undef(r), "regular_ngon(): need to specify one of r, d, or, od, ir, id, side."); path = regular_ngon(n=n, r=r, rounding=rounding, realign=realign); - attachable(anchor,spin, two_d=true, path=path) { + attachable(anchor,spin, two_d=true, path=path, extent=false) { polygon(path); children(); } diff --git a/transforms.scad b/transforms.scad index 59de9a8..cbe1e00 100644 --- a/transforms.scad +++ b/transforms.scad @@ -369,7 +369,11 @@ module rot(a=0, v=undef, cp=undef, from=undef, to=undef, reverse=false) function rot(a=0, v=undef, cp=undef, from=undef, to=undef, reverse=false, p=undef, planar=false) = assert(is_undef(from)==is_undef(to), "from and to must be specified together.") - let(rev = reverse? -1 : 1) + let( + rev = reverse? -1 : 1, + from = is_undef(from)? undef : point3d(from), + to = is_undef(to)? undef : point3d(to) + ) is_undef(p)? ( is_undef(cp)? ( planar? ( @@ -416,7 +420,7 @@ function rot(a=0, v=undef, cp=undef, from=undef, to=undef, reverse=false, p=unde (planar || (p!=[] && len(p[0])==2)) && !( (is_vector(a) && norm(point2d(a))>0) || (!is_undef(v) && norm(point2d(v))>0 && !approx(a,0)) || - (!is_undef(from) && !approx(from,to) && !(abs(from.z)>0 || abs(to.z))) || + (!is_undef(from) && !approx(from,to) && !(abs(point3d(from).z)>0 || abs(point3d(to).z))) || (!is_undef(from) && approx(from,to) && norm(point2d(from))>0 && a!=0) ) )? ( @@ -425,7 +429,8 @@ function rot(a=0, v=undef, cp=undef, from=undef, to=undef, reverse=false, p=unde rotate_points2d(p, a=vector_angle(from,to)*sign(vector_axis(from,to)[2])*rev, cp=cp) ) ) : ( - rotate_points3d(p, a=a, v=v, cp=(is_undef(cp)? [0,0,0] : cp), from=from, to=to, reverse=reverse) + let( cp = is_undef(cp)? [0,0,0] : cp ) + rotate_points3d(p, a=a, v=v, cp=cp, from=from, to=to, reverse=reverse) ) ) ); diff --git a/vectors.scad b/vectors.scad index ceeb40d..ed8a848 100644 --- a/vectors.scad +++ b/vectors.scad @@ -140,9 +140,11 @@ function vector_angle(v1,v2=undef,v3=undef) = assert(false, "Bad arguments.") ) : (is_vector(v1) && is_vector(v2) && is_vector(v3))? vector_angle(v1-v2, v3-v2) : - // NOTE: constrain() corrects crazy FP rounding errors that exceed acos()'s domain. - (is_vector(v1) && is_vector(v2) && is_undef(v3))? acos(constrain((v1*v2)/(norm(v1)*norm(v2)), -1, 1)) : - assert(false, "Bad arguments."); + (is_vector(v1) && is_vector(v2) && is_undef(v3))? ( + assert(len(v1)==len(v2)) + // NOTE: constrain() corrects crazy FP rounding errors that exceed acos()'s domain. + acos(constrain((v1*v2)/(norm(v1)*norm(v2)), -1, 1)) + ) : assert(false, "Bad arguments."); // Function: vector_axis() diff --git a/version.scad b/version.scad index 72c8fb1..b60aff5 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,152]; +BOSL_VERSION = [2,0,153]; // Section: BOSL Library Version Functions