From 6180771cf17137b47bf2890f422aa80fe779a657 Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Sun, 23 Jun 2019 17:42:57 -0700 Subject: [PATCH] Fixed edge case orient_and_align() with 0 height. --- attachments.scad | 4 +++- coords.scad | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/attachments.scad b/attachments.scad index 962a2fa..3b3607f 100644 --- a/attachments.scad +++ b/attachments.scad @@ -153,7 +153,9 @@ function find_anchor(anchor, h, size, size2=undef, shift=[0,0], anchors=[], geom botpt = point3d(vmul(size/2,xyal))+DOWN*h/2, toppt = point3d(vmul(size2/2,xyal)+shift)+UP*h/2, pos = lerp(botpt, toppt, (anchor.z+1)/2), - sidevec = two_d? point3d(xyal) : rotate_points3d([point3d(xyal)], from=UP, to=toppt-botpt)[0], + sidevec = two_d? point3d(xyal) : + approx(norm(xyal),0)? [0,0,0] : + rotate_points3d([point3d(xyal)], from=UP, to=toppt-botpt)[0], vec = ( two_d? sidevec : anchor==CENTER? UP : diff --git a/coords.scad b/coords.scad index 8e29c3f..12a5758 100644 --- a/coords.scad +++ b/coords.scad @@ -135,6 +135,8 @@ function rotate_points3d(pts, a=0, v=undef, cp=[0,0,0], from=undef, to=undef, re let ( mrot = reverse? ( !is_undef(from)? ( + assert(norm(from)>0, "The from argument cannot equal [0,0] or [0,0,0]") + assert(norm(to)>0, "The to argument cannot equal [0,0] or [0,0,0]") let ( ang = vector_angle(from, to), v = vector_axis(from, to) @@ -149,6 +151,8 @@ function rotate_points3d(pts, a=0, v=undef, cp=[0,0,0], from=undef, to=undef, re ) ) : ( !is_undef(from)? ( + assert(norm(from)>0, "The from argument cannot equal [0,0] or [0,0,0]") + assert(norm(to)>0, "The to argument cannot equal [0,0] or [0,0,0]") let ( from = from / norm(from), to = to / norm(from),