From c465a5b746746b79ff2dad405ddb92221fd55ad8 Mon Sep 17 00:00:00 2001
From: Garth Minette <gminette@gmail.com>
Date: Sun, 16 Aug 2020 23:09:59 -0700
Subject: [PATCH 1/2] cuboid() with negative chamfer had mispositioned
 anti-chamfers.

---
 shapes.scad  | 4 ++--
 version.scad | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/shapes.scad b/shapes.scad
index cb6d4e5..d612b0a 100644
--- a/shapes.scad
+++ b/shapes.scad
@@ -102,8 +102,8 @@ module cuboid(
                 if (edges == EDGES_ALL && trimcorners) {
                     if (chamfer<0) {
                         cube(size, center=true) {
-                            attach(TOP) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP);
-                            attach(BOT) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP);
+                            attach(TOP,overlap=0) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP);
+                            attach(BOT,overlap=0) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP);
                         }
                     } else {
                         isize = [for (v = size) max(0.001, v-2*chamfer)];
diff --git a/version.scad b/version.scad
index e6ba60b..21ab73b 100644
--- a/version.scad
+++ b/version.scad
@@ -8,7 +8,7 @@
 //////////////////////////////////////////////////////////////////////
 
 
-BOSL_VERSION = [2,0,402];
+BOSL_VERSION = [2,0,403];
 
 
 // Section: BOSL Library Version Functions

From 25841bda7328edcaf0f82387131bfd84149cf5b2 Mon Sep 17 00:00:00 2001
From: Garth Minette <gminette@gmail.com>
Date: Sun, 16 Aug 2020 23:10:43 -0700
Subject: [PATCH 2/2] Fixed attachable() anchors for vnf's with extent=false.

---
 attachments.scad | 35 +++++++++++++----------------------
 version.scad     |  2 +-
 2 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/attachments.scad b/attachments.scad
index 6004e29..2ac4367 100644
--- a/attachments.scad
+++ b/attachments.scad
@@ -458,10 +458,9 @@ function find_anchor(anchor, geom) =
             eps = 1/2048,
             points = vnf[0],
             faces = vnf[1],
-            rpts = rot(from=anchor, to=RIGHT, p=move(point3d(-cp), p=points)),
+            rpts = apply(rot(from=anchor, to=RIGHT) * move(point3d(-cp)), points),
             hits = [
-                for (i = idx(faces)) let(
-                    face = faces[i],
+                for (face = faces) let(
                     verts = select(rpts, face)
                 ) if (
                     max(subindex(verts,0)) >= -eps &&
@@ -470,35 +469,27 @@ function find_anchor(anchor, geom) =
                     min(subindex(verts,1)) <=  eps &&
                     min(subindex(verts,2)) <=  eps
                 ) let(
-                    pt = polygon_line_intersection(
-                        select(points, face),
-                        [CENTER,anchor], eps=eps
-                    )
-                ) if (!is_undef(pt)) [norm(pt), i, pt]
+                    poly = select(points, face),
+                    pt = polygon_line_intersection(poly, [cp,cp+anchor], bounded=[true,false], eps=eps)
+                ) if (!is_undef(pt)) let(
+                    plane = plane_from_polygon(poly),
+                    n = plane_normal(plane)
+                )
+                [norm(pt-cp), n, pt]
             ]
         )
         assert(len(hits)>0, "Anchor vector does not intersect with the shape.  Attachment failed.")
         let(
             furthest = max_index(subindex(hits,0)),
-            pos = point3d(cp) + hits[furthest][2],
             dist = hits[furthest][0],
-            nfaces = [for (hit = hits) if(approx(hit[0],dist,eps=eps)) hit[1]],
-            n = unit(
-                sum([
-                    for (i = nfaces) let(
-                        faceverts = select(points, faces[i]),
-                        faceplane = plane_from_points(faceverts),
-                        nrm = plane_normal(faceplane)
-                    ) nrm
-                ]) / len(nfaces),
-                UP
-            )
+            pos = hits[furthest][2],
+            n = unit(sum([for (hit = hits) if (approx(hit[0],dist,eps=eps)) hit[1]]))
         )
         [anchor, pos, n, oang]
     ) : type == "vnf_extent"? ( //vnf
         let(
             vnf=geom[1],
-            rpts = rot(from=anchor, to=RIGHT, p=move(point3d(-cp), p=vnf[0])),
+            rpts = apply(rot(from=anchor, to=RIGHT) * move(point3d(-cp)), vnf[0]),
             maxx = max(subindex(rpts,0)),
             idxs = [for (i = idx(rpts)) if (approx(rpts[i].x, maxx)) i],
             mm = pointlist_bounds(select(rpts,idxs)),
@@ -849,7 +840,7 @@ module attachable(
 
 // Module: position()
 // Usage:
-//   position(from, [overlap]) ...
+//   position(from) ...
 // Description:
 //   Attaches children to a parent object at an anchor point.
 // Arguments:
diff --git a/version.scad b/version.scad
index 21ab73b..85cad34 100644
--- a/version.scad
+++ b/version.scad
@@ -8,7 +8,7 @@
 //////////////////////////////////////////////////////////////////////
 
 
-BOSL_VERSION = [2,0,403];
+BOSL_VERSION = [2,0,404];
 
 
 // Section: BOSL Library Version Functions