Merge pull request #986 from adrianVmariano/master

This commit is contained in:
Revar Desmera 2022-11-09 16:49:21 -08:00 committed by GitHub
commit f464572b77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 197 additions and 138 deletions

View file

@ -465,17 +465,19 @@ module position(from)
module orient(dir, anchor, spin) {
req_children($children);
if (!is_undef(dir)) {
assert(anchor==undef, "Only one of dir= or anchor= may be given to orient()");
assert(is_vector(dir));
spin = default(spin, 0);
assert(is_finite(spin));
check =
assert(anchor==undef, "Only one of dir= or anchor= may be given to orient()")
assert(is_vector(dir))
assert(is_finite(spin));
two_d = _attach_geom_2d($parent_geom);
fromvec = two_d? BACK : UP;
rot(spin, from=fromvec, to=dir) children();
} else {
assert(dir==undef, "Only one of dir= or anchor= may be given to orient()");
assert($parent_geom != undef, "No parent to orient from!");
assert(is_string(anchor) || is_vector(anchor));
check=
assert(dir==undef, "Only one of dir= or anchor= may be given to orient()")
assert($parent_geom != undef, "No parent to orient from!")
assert(is_string(anchor) || is_vector(anchor));
anch = _find_anchor(anchor, $parent_geom);
two_d = _attach_geom_2d($parent_geom);
fromvec = two_d? BACK : UP;
@ -568,8 +570,9 @@ module attach(from, to, overlap, norot=false)
module tag(tag)
{
req_children($children);
assert(is_string(tag),"tag must be a string");
assert(undef==str_find($tag," "),str("Tag string \"",$tag,"\" contains a space, which is not allowed")) ;
check=
assert(is_string(tag),"tag must be a string")
assert(undef==str_find(tag," "),str("Tag string \"",tag,"\" contains a space, which is not allowed"));
$tag = str($tag_prefix,tag);
children();
}
@ -627,7 +630,7 @@ module tag(tag)
module force_tag(tag)
{
req_children($children);
assert(is_undef(tag) || is_string(tag),"tag must be a string");
check1=assert(is_undef(tag) || is_string(tag),"tag must be a string");
$tag = str($tag_prefix,default(tag,$tag));
assert(undef==str_find($tag," "),str("Tag string \"",$tag,"\" contains a space, which is not allowed"));
if(_is_shown())
@ -710,6 +713,7 @@ module tag_scope(scope){
req_children($children);
scope = is_undef(scope) ? rand_str(20) : scope;
assert(is_string(scope), "scope must be a string");
assert(undef==str_find(scope," "),str("Scope string \"",scope,"\" contains a space, which is not allowed"));
$tag_prefix=scope;
children();
}
@ -1206,7 +1210,7 @@ module tag_conv_hull(tag,keep="keep")
module hide(tags)
{
req_children($children);
assert(is_string(tags), "tags must be a string");
dummy=assert(is_string(tags), "tags must be a string");
taglist = [for(s=str_split(tags," ",keep_nulls=false)) str($tag_prefix,s)];
$tags_hidden = concat($tags_hidden,taglist);
children();
@ -1233,7 +1237,7 @@ module hide(tags)
module show_only(tags)
{
req_children($children);
assert(is_string(tags), str("tags must be a string",tags));
dummy=assert(is_string(tags), str("tags must be a string",tags));
taglist = [for(s=str_split(tags," ",keep_nulls=false)) str($tag_prefix,s)];
$tags_shown = taglist;
children();
@ -1270,7 +1274,7 @@ module show_all()
module show_int(tags)
{
req_children($children);
assert(is_string(tags), str("tags must be a string",tags));
dummy=assert(is_string(tags), str("tags must be a string",tags));
taglist = [for(s=str_split(tags," ",keep_nulls=false)) str($tag_prefix,s)];
$tags_shown = $tags_shown == "ALL" ? taglist : set_intersection($tags_shown,taglist);
children();
@ -1321,7 +1325,7 @@ module edge_mask(edges=EDGES_ALL, except=[]) {
];
for (vec = vecs) {
vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0);
assert(vcount == 2, "Not an edge vector!");
dummy=assert(vcount == 2, "Not an edge vector!");
anch = _find_anchor(vec, $parent_geom);
$attach_to = undef;
$attach_anchor = anch;
@ -1369,7 +1373,7 @@ module corner_mask(corners=CORNERS_ALL, except=[]) {
vecs = [for (i = [0:7]) if (corners[i]>0) CORNER_OFFSETS[i]];
for (vec = vecs) {
vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0);
assert(vcount == 3, "Not an edge vector!");
dummy=assert(vcount == 3, "Not an edge vector!");
anch = _find_anchor(vec, $parent_geom);
$attach_to = undef;
$attach_anchor = anch;
@ -1452,7 +1456,7 @@ module edge_profile(edges=EDGES_ALL, except=[], convexity=10) {
];
for (vec = vecs) {
vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0);
assert(vcount == 2, "Not an edge vector!");
dummy=assert(vcount == 2, "Not an edge vector!");
anch = _find_anchor(vec, $parent_geom);
$attach_to = undef;
$attach_anchor = anch;
@ -1509,7 +1513,7 @@ module corner_profile(corners=CORNERS_ALL, except=[], r, d, convexity=10) {
vecs = [for (i = [0:7]) if (corners[i]>0) CORNER_OFFSETS[i]];
for (vec = vecs) {
vcount = (vec.x?1:0) + (vec.y?1:0) + (vec.z?1:0);
assert(vcount == 3, "Not an edge vector!");
dummy=assert(vcount == 3, "Not an edge vector!");
anch = _find_anchor(vec, $parent_geom);
$attach_to = undef;
$attach_anchor = anch;
@ -2705,7 +2709,7 @@ function _standard_anchors(two_d=false) = [
// Example(FlatSpin,VPD=333):
// cube(50, center=true) show_anchors();
module show_anchors(s=10, std=true, custom=true) {
check = assert($parent_geom != undef) 1;
check = assert($parent_geom != undef);
two_d = _attach_geom_2d($parent_geom);
if (std) {
for (anchor=_standard_anchors(two_d=two_d)) {

View file

@ -1424,9 +1424,10 @@ function bezier_patch_normals(patch, u, v) =
// debug_bezier(bez, N=3, width=0.5);
module debug_bezier(bezpath, width=1, N=3) {
no_children($children);
assert(is_path(bezpath));
assert(is_int(N));
assert(len(bezpath)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1."));
check =
assert(is_path(bezpath),"bezpath must be a path")
assert(is_int(N) && N>0, "N must be a positive integer")
assert(len(bezpath)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1."));
$fn=8;
stroke(bezpath_curve(bezpath, N=N), width=width, color="cyan");
color("green")

View file

@ -133,9 +133,10 @@ module cubetruss_support(size, strut, extents=1, anchor=CENTER, spin=0, orient=U
extents = is_num(extents)? [1,1,extents] : extents;
size = is_undef(size)? $cubetruss_size : size;
strut = is_undef(strut)? $cubetruss_strut_size : strut;
assert(is_int(extents.x) && extents.x > 0);
assert(is_int(extents.y) && extents.y > 0);
assert(is_int(extents.z) && extents.z > 0);
check =
assert(is_int(extents.x) && extents.x > 0)
assert(is_int(extents.y) && extents.y > 0)
assert(is_int(extents.z) && extents.z > 0);
w = (size-strut) * extents.x + strut;
l = (size-strut) * extents.y + strut;
h = (size-strut) * extents.z + strut;

View file

@ -409,7 +409,7 @@ module grid2d(spacing, n, size, stagger=false, inside=undef, nonzero)
module grid_copies(spacing, n, size, stagger=false, inside=undef, nonzero)
{
req_children($children);
assert(in_list(stagger, [false, true, "alt"]));
dummy = assert(in_list(stagger, [false, true, "alt"]));
bounds = is_undef(inside)? undef :
is_path(inside)? pointlist_bounds(inside) :
assert(is_region(inside))
@ -1035,8 +1035,8 @@ module path_copies(path, n, spacing, sp=undef, dist, rotate_children=true, dist,
sort([for(entry=ptlist) posmod(entry-listcenter,length)]) :
[for(entry=ptlist) entry + length/2-listcenter ]
);
distOK = is_def(n) || (min(distances)>=0 && max(distances)<=length);
assert(distOK,"Cannot fit all of the copies");
distOK = min(distances)>=0 && max(distances)<=length;
dummy = assert(distOK,"Cannot fit all of the copies");
cutlist = path_cut_points(path, distances, closed, direction=true);
planar = len(path[0])==2;
for(i=[0:1:len(cutlist)-1]) {

View file

@ -220,16 +220,17 @@ module stroke(
) * linewidth;
closed = default(closed, is_region(path));
assert(is_bool(closed));
check1 = assert(is_bool(closed));
dots = dots==true? "dot" : dots;
endcap1 = first_defined([endcap1, endcaps, dots, "round"]);
endcap2 = first_defined([endcap2, endcaps, if (!closed) dots, "round"]);
joints = first_defined([joints, dots, "round"]);
assert(is_bool(endcap1) || is_string(endcap1) || is_path(endcap1));
assert(is_bool(endcap2) || is_string(endcap2) || is_path(endcap2));
assert(is_bool(joints) || is_string(joints) || is_path(joints));
check2 =
assert(is_bool(endcap1) || is_string(endcap1) || is_path(endcap1))
assert(is_bool(endcap2) || is_string(endcap2) || is_path(endcap2))
assert(is_bool(joints) || is_string(joints) || is_path(joints));
endcap1_dflts = _shape_defaults(endcap1);
endcap2_dflts = _shape_defaults(endcap2);
@ -238,47 +239,47 @@ module stroke(
endcap_width1 = first_defined([endcap_width1, endcap_width, dots_width, endcap1_dflts[0]]);
endcap_width2 = first_defined([endcap_width2, endcap_width, dots_width, endcap2_dflts[0]]);
joint_width = first_defined([joint_width, dots_width, joint_dflts[0]]);
assert(is_num(endcap_width1));
assert(is_num(endcap_width2));
assert(is_num(joint_width));
check3 =
assert(is_num(endcap_width1))
assert(is_num(endcap_width2))
assert(is_num(joint_width));
endcap_length1 = first_defined([endcap_length1, endcap_length, dots_length, endcap1_dflts[1]*endcap_width1]);
endcap_length2 = first_defined([endcap_length2, endcap_length, dots_length, endcap2_dflts[1]*endcap_width2]);
joint_length = first_defined([joint_length, dots_length, joint_dflts[1]*joint_width]);
assert(is_num(endcap_length1));
assert(is_num(endcap_length2));
assert(is_num(joint_length));
check4 =
assert(is_num(endcap_length1))
assert(is_num(endcap_length2))
assert(is_num(joint_length));
endcap_extent1 = first_defined([endcap_extent1, endcap_extent, dots_extent, endcap1_dflts[2]*endcap_width1]);
endcap_extent2 = first_defined([endcap_extent2, endcap_extent, dots_extent, endcap2_dflts[2]*endcap_width2]);
joint_extent = first_defined([joint_extent, dots_extent, joint_dflts[2]*joint_width]);
assert(is_num(endcap_extent1));
assert(is_num(endcap_extent2));
assert(is_num(joint_extent));
check5 =
assert(is_num(endcap_extent1))
assert(is_num(endcap_extent2))
assert(is_num(joint_extent));
endcap_angle1 = first_defined([endcap_angle1, endcap_angle, dots_angle]);
endcap_angle2 = first_defined([endcap_angle2, endcap_angle, dots_angle]);
joint_angle = first_defined([joint_angle, dots_angle]);
assert(is_undef(endcap_angle1)||is_num(endcap_angle1));
assert(is_undef(endcap_angle2)||is_num(endcap_angle2));
assert(is_undef(joint_angle)||is_num(joint_angle));
check6 =
assert(is_undef(endcap_angle1)||is_num(endcap_angle1))
assert(is_undef(endcap_angle2)||is_num(endcap_angle2))
assert(is_undef(joint_angle)||is_num(joint_angle));
endcap_color1 = first_defined([endcap_color1, endcap_color, dots_color, color]);
endcap_color2 = first_defined([endcap_color2, endcap_color, dots_color, color]);
joint_color = first_defined([joint_color, dots_color, color]);
paths = force_region(path);
assert(is_region(paths),"The path argument must be a list of 2D or 3D points, or a region.");
for (path = paths) {
assert(is_list(path));
if (len(path) > 1) {
assert(is_path(path,[2,3]), "The path argument must be a list of 2D or 3D points, or a region.");
}
check7 = assert(is_region(paths),"The path argument must be a list of 2D or 3D points, or a region.");
for (path = paths) {
assert(len(path)==1 || is_path(path,[2,3]), "The path argument must be a list of 2D or 3D points, or a region.");
path = deduplicate( closed? close_path(path) : path );
assert(is_num(width) || (is_vector(width) && len(width)==len(path)));
check8 = assert(is_num(width) || (is_vector(width) && len(width)==len(path)));
width = is_num(width)? [for (x=path) width] : width;
assert(all([for (w=width) w>0]));
check9 = assert(all([for (w=width) w>0]));
endcap_shape1 = _shape_path(endcap1, width[0], endcap_width1, endcap_length1, endcap_extent1);
endcap_shape2 = _shape_path(endcap2, last(width), endcap_width2, endcap_length2, endcap_extent2);
@ -289,7 +290,7 @@ module stroke(
(endcap1=="arrow2")? endcap_length1*3/4 :
0
]);
assert(is_num(trim1));
check10 = assert(is_num(trim1));
trim2 = last(width) * first_defined([
trim2, trim,
@ -297,7 +298,7 @@ module stroke(
(endcap2=="arrow2")? endcap_length2*3/4 :
0
]);
assert(is_num(trim2));
check11 = assert(is_num(trim2));
if (len(path) == 1) {

View file

@ -452,7 +452,8 @@ function is_coplanar(points, eps=EPSILON) =
// p2 = The second point on the plane.
// p3 = The third point on the plane.
function plane3pt(p1, p2, p3) =
assert( is_path([p1,p2,p3],dim=3) && len(p1)==3,
is_undef(p2) && is_undef(p3) && is_path(p1,dim=3) ? plane3pt(p1[0],p1[1],p1[2])
: assert( is_path([p1,p2,p3],dim=3) && len(p1)==3,
"Invalid points or incompatible dimensions." )
let(
crx = cross(p3-p1, p2-p1),
@ -476,6 +477,8 @@ function plane3pt(p1, p2, p3) =
// i2 = The index into `points` of the second point on the plane.
// i3 = The index into `points` of the third point on the plane.
function plane3pt_indexed(points, i1, i2, i3) =
is_undef(i3) && is_undef(i2) && is_vector(i1) ? plane3pt_indexed(points, i1[0], i1[1], i1[2])
:
assert( is_vector([i1,i2,i3]) && min(i1,i2,i3)>=0 && is_list(points) && max(i1,i2,i3)<len(points),
"Invalid or out of range indices." )
assert( is_path([points[i1], points[i2], points[i3]],dim=3),
@ -2290,8 +2293,8 @@ function hull(points) =
// hull_points(pts);
module hull_points(points, fast=false) {
no_children($children);
assert(is_path(points))
assert(len(points)>=3, "Point list must contain 3 points")
check = assert(is_path(points))
assert(len(points)>=3, "Point list must contain 3 points");
if (len(points[0])==2)
hull() polygon(points=points);
else {

View file

@ -626,11 +626,12 @@ module dovetail(gender, width, height, slide, h, w, angle, slope, thickness, tap
: gender == "female" ? DOWN
: UP;
count = num_defined([angle,slope]);
assert(count<=1, "Do not specify both angle and slope");
count2 = num_defined([taper,back_width]);
assert(count2<=1, "Do not specify both taper and back_width");
count3 = num_defined([chamfer, radius]);
assert(count3<=1 || (radius==0 && chamfer==0), "Do not specify both chamfer and radius");
dummy =
assert(count<=1, "Do not specify both angle and slope")
assert(count2<=1, "Do not specify both taper and back_width")
assert(count3<=1 || (radius==0 && chamfer==0), "Do not specify both chamfer and radius");
slope = is_def(slope) ? slope :
is_def(angle) ? 1/tan(angle) : 6;
extra_slop = gender == "female" ? 2*get_slop() : 0;
@ -1047,17 +1048,17 @@ function rabbit_clip(type, length, width, snap, thickness, depth, compression=0
module rabbit_clip(type, length, width, snap, thickness, depth, compression=0.1, clearance=.1, lock=false, lock_clearance=0,
splinesteps=8, anchor, orient, spin=0)
{
assert(is_num(width) && width>0,"Width must be a positive value");
assert(is_num(length) && length>0, "Length must be a positive value");
assert(is_num(thickness) && thickness>0, "Thickness must be a positive value");
assert(is_num(snap) && snap>=0, "Snap must be a non-negative value");
assert(is_num(depth) && depth>0, "Depth must be a positive value");
assert(is_num(compression) && compression >= 0, "Compression must be a nonnegative value");
assert(is_bool(lock));
assert(is_num(lock_clearance));
legal_types = ["pin","socket","male","female","double"];
assert(in_list(type,legal_types),str("type must be one of ",legal_types));
check =
assert(is_num(width) && width>0,"Width must be a positive value")
assert(is_num(length) && length>0, "Length must be a positive value")
assert(is_num(thickness) && thickness>0, "Thickness must be a positive value")
assert(is_num(snap) && snap>=0, "Snap must be a non-negative value")
assert(is_num(depth) && depth>0, "Depth must be a positive value")
assert(is_num(compression) && compression >= 0, "Compression must be a nonnegative value")
assert(is_bool(lock))
assert(is_num(lock_clearance))
assert(in_list(type,legal_types),str("type must be one of ",legal_types));
if (type=="double") {
attachable(size=[width+2*compression, depth, 2*length], anchor=default(anchor,BACK), spin=spin, orient=default(orient,BACK)){
union(){
@ -1100,7 +1101,7 @@ module rabbit_clip(type, length, width, snap, thickness, depth, compression=0.1
[bottom_pt],
reverse(apply(xflip(),sidepath))
);
assert(fullpath[4].y < fullpath[3].y, "Pin is too wide for its length");
dummy2 = assert(fullpath[4].y < fullpath[3].y, "Pin is too wide for its length");
snapmargin = -snap + last(sidepath).x;// - compression;
if (is_pin){

View file

@ -471,15 +471,16 @@ module rounding_hole_mask(r, rounding, excess=0.1, d, anchor=CENTER, spin=0, ori
// Module: teardrop_edge_mask()
// Usage:
// teardrop_edge_mask(r|d=, [angle], [excess]);
// teardrop_edge_mask(l, r|d=, [angle], [excess], [anchor], [spin], [orient]) [ATTACHMENTS];
// Description:
// Makes an apropriate 3D corner rounding mask that keeps within `angle` degrees of vertical.
// Arguments:
// l = length of mask
// r = Radius of the mask rounding.
// d = Diameter of the mask rounding.
// angle = Maximum angle from vertical. Default: 45
// excess = Excess mask size. Default: 0.1
// ---
// d = Diameter of the mask rounding.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
@ -496,10 +497,10 @@ module rounding_hole_mask(r, rounding, excess=0.1, d, anchor=CENTER, spin=0, ori
function teardrop_edge_mask(l, r, angle, excess=0.1, d, anchor, spin, orient) = no_function("teardrop_edge_mask");
module teardrop_edge_mask(l, r, angle, excess=0.1, d, anchor=CTR, spin=0, orient=UP)
{
assert(is_num(l));
assert(is_num(angle));
assert(is_num(excess));
assert(angle>0 && angle<90);
check =
assert(is_num(l) && l>0, "Length of mask must be positive")
assert(is_num(angle) && angle>0 && angle<90, "Angle must be a number between 0 and 90")
assert(is_num(excess));
r = get_radius(r=r, d=d, dflt=1);
path = mask2d_teardrop(r=r, angle=angle, excess=excess);
linear_sweep(path, height=l, center=true, atype="bbox", anchor=anchor, spin=spin, orient=orient) children();
@ -508,7 +509,7 @@ module teardrop_edge_mask(l, r, angle, excess=0.1, d, anchor=CTR, spin=0, orient
// Module: teardrop_corner_mask()
// Usage:
// teardrop_corner_mask(r|d=, [angle], [excess]);
// teardrop_corner_mask(r|d=, [angle], [excess], [anchor], [spin], [orient]) [ATTACHMENTS];
// Description:
// Makes an apropriate 3D corner rounding mask that keeps within `angle` degrees of vertical.
// Arguments:

View file

@ -163,7 +163,7 @@ module modular_hose(size, type, clearance=0, waist_len, anchor=BOTTOM, spin=0,or
bigend = move([clearance[1], -bbound[0].y], p=_big_end[ind]);
midlength = first_defined([waist_len, _hose_waist[ind]]);
assert(midlength>=0,"midlength must be nonnegative");
dummy = assert(midlength>=0,"midlength must be nonnegative");
goodtypes = ["small","big","segment","socket","ball"];
shape =

View file

@ -196,13 +196,14 @@ module chain_hull()
// circle(r=1.5);
module path_extrude2d(path, caps=false, closed=false, s, convexity=10) {
extra_ang = 0.1; // Extra angle for overlap of joints
assert(caps==false || closed==false, "Cannot have caps on a closed extrusion");
assert(is_path(path,2));
check =
assert(caps==false || closed==false, "Cannot have caps on a closed extrusion")
assert(is_path(path,2));
path = deduplicate(path);
s = s!=undef? s :
let(b = pointlist_bounds(path))
norm(b[1]-b[0]);
assert(is_finite(s));
check2 = assert(is_finite(s));
L = len(path);
for (i = [0:1:L-(closed?1:2)]) {
seg = select(path, i, i+1);
@ -286,15 +287,15 @@ module path_extrude2d(path, caps=false, closed=false, s, convexity=10) {
// cylindrical_extrude(or=40, ir=35, orient=BACK)
// text(text="Hello World!", size=10, halign="center", valign="center");
module cylindrical_extrude(ir, or, od, id, size=1000, convexity=10, spin=0, orient=UP) {
assert(is_num(size) || is_vector(size,2));
check1 = assert(is_num(size) || is_vector(size,2));
size = is_num(size)? [size,size] : size;
ir = get_radius(r=ir,d=id);
or = get_radius(r=or,d=od);
assert(all_positive([ir,or]), "Must supply positive inner and outer radius or diameter");
check2 = assert(all_positive([ir,or]), "Must supply positive inner and outer radius or diameter");
index_r = or;
circumf = 2 * PI * index_r;
width = min(size.x, circumf);
assert(width <= circumf, "Shape would more than completely wrap around.");
check3 = assert(width <= circumf, "Shape would more than completely wrap around.");
sides = segs(or);
step = circumf / sides;
steps = ceil(width / step);
@ -338,8 +339,9 @@ module cylindrical_extrude(ir, or, od, id, size=1000, convexity=10, spin=0, orie
// xcopies(3) circle(3, $fn=32);
// }
module extrude_from_to(pt1, pt2, convexity, twist, scale, slices) {
assert(is_vector(pt1));
assert(is_vector(pt2));
check =
assert(is_vector(pt1),"First point must be a vector")
assert(is_vector(pt2),"Second point must be a vector");
pt1 = point3d(pt1);
pt2 = point3d(pt2);
rtp = xyz_to_spherical(pt2-pt1);

View file

@ -308,7 +308,7 @@ module regular_polyhedron(
longside=undef, // special parameter for trapezohedron
h=undef // special parameter for trapezohedron
) {
assert(rounding>=0, "'rounding' must be nonnegative");
dummy=assert(is_num(rounding) && rounding>=0, "'rounding' must be nonnegative");
entry = regular_polyhedron_info(
"fullentry", name=name, index=index,
type=type, faces=faces, facetype=facetype,

View file

@ -1850,15 +1850,14 @@ module convex_offset_extrude(
top_height = len(offsets_top)==0 ? 0 : abs(last(offsets_top)[1]) - struct_val(top,"extra");
height = one_defined([l,h,height,length], "l,h,height,length", dflt=u_add(bottom_height,top_height));
assert(height>=0, "Height must be nonnegative");
middle = height-bottom_height-top_height;
assert(
middle>=0, str(
"Specified end treatments (bottom height = ",bottom_height,
" top_height = ",top_height,") are too large for extrusion height (",height,")"
)
);
check =
assert(height>=0, "Height must be nonnegative")
assert(middle>=0, str(
"Specified end treatments (bottom height = ",bottom_height,
" top_height = ",top_height,") are too large for extrusion height (",height,")"
)
);
// The entry r[i] is [radius,z] for a given layer
r = move([0,bottom_height],p=concat(
reverse(offsets_bot), [[0,0], [0,middle]], move([0,middle], p=offsets_top)));
@ -2453,9 +2452,9 @@ module bent_cutout_mask(r, thickness, path, radius, convexity=10)
r = get_radius(r1=r, r2=radius);
dummy1=assert(is_def(r) && r>0,"Radius of the cylinder to bend around must be positive");
path2 = force_path(path);
dummy2=assert(is_path(path2,2),"Input path must be a 2D path");
assert(r-thickness>0, "Thickness too large for radius");
assert(thickness>0, "Thickness must be positive");
dummy2=assert(is_path(path2,2),"Input path must be a 2D path")
assert(r-thickness>0, "Thickness too large for radius")
assert(thickness>0, "Thickness must be positive");
fixpath = clockwise_polygon(path2);
curvepoints = arc(d=thickness, angle = [-180,0]);
profiles = [for(pt=curvepoints) _cyl_hole(r+pt.x,apply(xscale((r+pt.x)/r), offset(fixpath,delta=thickness/2+pt.y,check_valid=false,closed=true)))];
@ -2463,7 +2462,7 @@ module bent_cutout_mask(r, thickness, path, radius, convexity=10)
minangle = (min(pathx)-thickness/2)*360/(2*PI*r);
maxangle = (max(pathx)+thickness/2)*360/(2*PI*r);
mindist = (r+thickness/2)/cos((maxangle-minangle)/2);
assert(maxangle-minangle<180,"Cutout angle span is too large. Must be smaller than 180.");
dummy3 = assert(maxangle-minangle<180,"Cutout angle span is too large. Must be smaller than 180.");
zmean = mean(column(fixpath,1));
innerzero = repeat([0,0,zmean], len(fixpath));
outerpt = repeat( [1.5*mindist*cos((maxangle+minangle)/2),1.5*mindist*sin((maxangle+minangle)/2),zmean], len(fixpath));

View file

@ -1191,12 +1191,16 @@ module jittered_poly(path, dist=1/512) {
// Description:
// Makes a 2D teardrop shape. Useful for extruding into 3D printable holes. Uses "intersect" style anchoring.
// The cap_h parameter truncates the top of the teardrop. If cap_h is taller than the untruncated form then
// the result will be the full, untruncated shape.
// the result will be the full, untruncated shape. The segments of the bottom section of the teardrop are
// calculated to be the same as a circle or cylinder when rotated 90 degrees. (Note that this agreement is poor when `$fn=6` or `$fn=7`.
// If `$fn` is a multiple of four then the teardrop will reach its extremes on all four axes. The circum option
// produces a teardrop that circumscribes the circle; in this case set `realign=true` to get a teardrop that meets its internal extremes
// on the axes.
//
// Usage: As Module
// teardrop2d(r/d=, [ang], [cap_h]) [ATTACHMENTS];
// Usage: As Function
// path = teardrop2d(r/d=, [ang], [cap_h]);
// path = teardrop2d(r|d=, [ang], [cap_h]);
//
// Topics: Shapes (2D), Paths (2D), Path Generators, Attachable
//
@ -1208,6 +1212,8 @@ module jittered_poly(path, dist=1/512) {
// cap_h = if given, height above center where the shape will be truncated.
// ---
// d = diameter of circular portion of bottom. (Use instead of r)
// circum = if true, create a circumscribing teardrop. Default: false
// realign = if true, change whether bottom of teardrop is a point or a flat. Default: false
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
//
@ -1217,9 +1223,9 @@ module jittered_poly(path, dist=1/512) {
// teardrop2d(r=30, ang=30, cap_h=40);
// Example(2D): Close Crop
// teardrop2d(r=30, ang=30, cap_h=20);
module teardrop2d(r, ang=45, cap_h, d, anchor=CENTER, spin=0)
module teardrop2d(r, ang=45, cap_h, d, circum=false, realign=false, anchor=CENTER, spin=0)
{
path = teardrop2d(r=r, d=d, ang=ang, cap_h=cap_h);
path = teardrop2d(r=r, d=d, ang=ang, circum=circum, realign=realign, cap_h=cap_h);
attachable(anchor,spin, two_d=true, path=path, extent=false) {
polygon(path);
children();
@ -1229,20 +1235,56 @@ module teardrop2d(r, ang=45, cap_h, d, anchor=CENTER, spin=0)
// _extrapt = true causes the point to be duplicated so a teardrop with no cap
// has the same point count as one with a cap.
function teardrop2d(r, ang=45, cap_h, d, anchor=CENTER, spin=0, _extrapt=false) =
function teardrop2d(r, ang=45, cap_h, d, circum=false, realign=false, anchor=CENTER, spin=0, _extrapt=false) =
let(
r = get_radius(r=r, d=d, dflt=1),
ang2=90-ang,
minheight = r*sin(ang),
maxheight = r/cos(ang2)
maxheight = r/sin(ang), //cos(90-ang),
pointycap = is_undef(cap_h) || cap_h>=maxheight
)
assert(is_undef(cap_h) || cap_h>=minheight, str("cap_h cannot be less than ",minheight," but it is ",cap_h))
let(
firstpt = is_undef(cap_h) || cap_h>=maxheight ? [[0,maxheight]]
: [[(maxheight-cap_h)*tan(ang), cap_h]],
lastpt = !_extrapt && (is_undef(cap_h) || cap_h>=maxheight) ? [] : [[-firstpt[0].x,firstpt[0].y]],
path = concat(firstpt, arc(angle=[ang, -180-ang], r=r), lastpt)
) reorient(anchor,spin, two_d=true, path=path, p=path, extent=false);
cap = [
pointycap? [0,maxheight] : [(maxheight-cap_h)*tan(ang), cap_h],
r*[cos(ang),sin(ang)]
],
fullcircle = ellipse(r=r, realign=realign, circum=circum,spin=90),
// Chose the point on the circle that is lower than the cap but also creates a segment bigger than
// seglen/skipfactor so we don't have a teeny tiny segment at the end of the cap, except for the hexagoin
// case which is treated specially
skipfactor = len(fullcircle)==6 ? 15 : 3,
path = !circum ?
let(seglen = norm(fullcircle[0]-fullcircle[1]))
[
each cap,
for (p=fullcircle)
if (
p.y<last(cap).y-EPSILON
&& norm([abs(p.x)-last(cap).x,p.y-last(cap.y)])>seglen/skipfactor
) p,
xflip(cap[1]),
if (_extrapt || !pointycap) xflip(cap[0])
]
: let(
isect = [for(i=[0:1:len(fullcircle)/4])
let(p = line_intersection(cap, select(fullcircle,[i,i+1]), bounded1=RAY, bounded2=SEGMENT))
if (p) [i,p]
],
i = last(isect)[0],
p = last(isect)[1],
ff=echo(isect)
)
[
cap[0],
p,
each select(fullcircle,i+1,-i-1-(realign?1:0)),
xflip(p),
if(_extrapt || !pointycap) xflip(cap[0])
]
)
reorient(anchor,spin, two_d=true, path=path, p=path, extent=false);
// Function&Module: egg()

View file

@ -2502,6 +2502,7 @@ function torus(
// ang = Angle of hat walls from the Z axis. Default: 45 degrees
// cap_h = If given, height above center where the shape will be truncated. Default: `undef` (no truncation)
// ---
// circum = produce a circumscribing teardrop shape. Default: false
// r1 = Radius of circular portion of the front end of the teardrop shape.
// r2 = Radius of circular portion of the back end of the teardrop shape.
// d = Diameter of circular portion of the teardrop shape.
@ -2512,6 +2513,7 @@ function torus(
// chamfer = Specifies size of chamfer as distance along the bottom and top faces. Default: 0
// chamfer1 = Specifies size of chamfer on bottom as distance along bottom face. Default: 0
// chamfer2 = Specifies size of chamfer on top as distance along top face. Default: 0
// realign = Passes realign option to teardrop2d, which shifts face alignment. Default: false
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
@ -2541,7 +2543,8 @@ function torus(
// teardrop(d1=20, d2=30, h=20, cap_h1=11, cap_h2=16)
// show_anchors(std=false);
module teardrop(h, r, ang=45, cap_h, r1, r2, d, d1, d2, cap_h1, cap_h2, l, length, height, chamfer, chamfer1, chamfer2,anchor=CENTER, spin=0, orient=UP)
module teardrop(h, r, ang=45, cap_h, r1, r2, d, d1, d2, cap_h1, cap_h2, l, length, height, circum=false, realign=false,
chamfer, chamfer1, chamfer2,anchor=CENTER, spin=0, orient=UP)
{
length = one_defined([l, h, length, height],"l,h,length,height");
r1 = get_radius(r=r, r1=r1, d=d, d1=d1);
@ -2550,7 +2553,6 @@ module teardrop(h, r, ang=45, cap_h, r1, r2, d, d1, d2, cap_h1, cap_h2, l, lengt
tip_y2 = r2/cos(90-ang);
_cap_h1 = min(default(cap_h1, tip_y1), tip_y1);
_cap_h2 = min(default(cap_h2, tip_y2), tip_y2);
f= echo(fff=_cap_h1,_cap_h2);
capvec = unit([0, _cap_h1-_cap_h2, length]);
anchors = [
named_anchor("cap", [0,0,(_cap_h1+_cap_h2)/2], capvec),
@ -2559,14 +2561,14 @@ module teardrop(h, r, ang=45, cap_h, r1, r2, d, d1, d2, cap_h1, cap_h2, l, lengt
];
attachable(anchor,spin,orient, r1=r1, r2=r2, l=length, axis=BACK, anchors=anchors)
{
vnf_polyhedron(teardrop(ang=ang,cap_h=cap_h,r1=r1,r2=r2,cap_h1=cap_h1,cap_h2=cap_h2,
vnf_polyhedron(teardrop(ang=ang,cap_h=cap_h,r1=r1,r2=r2,cap_h1=cap_h1,cap_h2=cap_h2,circum=circum,realign=realign,
length=length, chamfer1=chamfer1,chamfer2=chamfer2,chamfer=chamfer));
children();
}
}
function teardrop(h, r, ang=45, cap_h, r1, r2, d, d1, d2, cap_h1, cap_h2, chamfer, chamfer1, chamfer2,
function teardrop(h, r, ang=45, cap_h, r1, r2, d, d1, d2, cap_h1, cap_h2, chamfer, chamfer1, chamfer2, circum=false, realign=false,
l, length, height, anchor=CENTER, spin=0, orient=UP) =
let(
r1 = get_radius(r=r, r1=r1, d=d, d1=d1, dflt=1),
@ -2577,8 +2579,8 @@ function teardrop(h, r, ang=45, cap_h, r1, r2, d, d1, d2, cap_h1, cap_h2, chamf
chamfer1 = first_defined([chamfer1,chamfer,0]),
chamfer2 = first_defined([chamfer2,chamfer,0]),
sides = segs(max(r1,r2)),
profile1 = teardrop2d(r=r1, ang=ang, cap_h=cap_h1, $fn=sides, _extrapt=true),
profile2 = teardrop2d(r=r2, ang=ang, cap_h=cap_h2, $fn=sides, _extrapt=true),
profile1 = teardrop2d(r=r1, ang=ang, cap_h=cap_h1, $fn=sides, circum=circum, realign=realign,_extrapt=true),
profile2 = teardrop2d(r=r2, ang=ang, cap_h=cap_h2, $fn=sides, circum=circum, realign=realign,_extrapt=true),
tip_y1 = r1/cos(90-ang),
tip_y2 = r2/cos(90-ang),
_cap_h1 = min(default(cap_h1, tip_y1), tip_y1),
@ -2590,10 +2592,9 @@ function teardrop(h, r, ang=45, cap_h, r1, r2, d, d1, d2, cap_h1, cap_h2, chamf
assert(is_undef(cap_h1) || cap_h1-chamfer1 > r1*sin(ang), "chamfer1 is too big to work with the specified cap_h1")
assert(is_undef(cap_h2) || cap_h2-chamfer2 > r2*sin(ang), "chamfer2 is too big to work with the specified cap_h2"),
cprof1 = r1==chamfer1 ? repeat([0,0],len(profile1))
: teardrop2d(r=r1-chamfer1, ang=ang, cap_h=u_add(cap_h1,-chamfer1), $fn=sides, _extrapt=true),
: teardrop2d(r=r1-chamfer1, ang=ang, cap_h=u_add(cap_h1,-chamfer1), $fn=sides, circum=circum, realign=realign,_extrapt=true),
cprof2 = r2==chamfer2 ? repeat([0,0],len(profile2))
: teardrop2d(r=r2-chamfer2, ang=ang, cap_h=u_add(cap_h2,-chamfer2), $fn=sides, _extrapt=true),
fefda= echo(lens=len(cprof1),len(cprof2)),
: teardrop2d(r=r2-chamfer2, ang=ang, cap_h=u_add(cap_h2,-chamfer2), $fn=sides, circum=circum, realign=realign,_extrapt=true),
anchors = [
named_anchor("cap", [0,0,(_cap_h1+_cap_h2)/2], capvec),
named_anchor("cap_fwd", [0,-length/2,_cap_h1], unit((capvec+FWD)/2)),
@ -2617,15 +2618,17 @@ function teardrop(h, r, ang=45, cap_h, r1, r2, d, d1, d2, cap_h1, cap_h2, chamf
// Creates a sphere with a conical hat, to make a 3D teardrop.
//
// Usage: As Module
// onion(r|d=, [ang=], [cap_h=], ...) [ATTACHMENTS];
// onion(r|d=, [ang=], [cap_h=], [circum=], [realign=], ...) [ATTACHMENTS];
// Usage: As Function
// vnf = onion(r|d=, [ang=], [cap_h=], ...);
// vnf = onion(r|d=, [ang=], [cap_h=], [circum=], [realign=], ...);
//
// Arguments:
// r = radius of spherical portion of the bottom. Default: 1
// ang = Angle of cone on top from vertical. Default: 45 degrees
// cap_h = If given, height above sphere center to truncate teardrop shape. Default: `undef` (no truncation)
// ---
// circum = set to true to circumscribe the specified radius/diameter. Default: False
// realign = adjust point alignment to determine if bottom is flat or pointy. Default: False
// d = diameter of spherical portion of bottom.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
@ -2652,10 +2655,10 @@ function teardrop(h, r, ang=45, cap_h, r1, r2, d, d1, d2, cap_h1, cap_h2, chamf
// Example: Standard Connectors
// onion(d=30, ang=30, cap_h=20) show_anchors();
module onion(r, ang=45, cap_h, d, anchor=CENTER, spin=0, orient=UP)
module onion(r, ang=45, cap_h, d, circum=false, realign=false, anchor=CENTER, spin=0, orient=UP)
{
r = get_radius(r=r, d=d, dflt=1);
xyprofile = teardrop2d(r=r, ang=ang, cap_h=cap_h);
xyprofile = teardrop2d(r=r, ang=ang, cap_h=cap_h, circum=circum, realign=realign);
tip_h = max(column(xyprofile,1));
_cap_h = min(default(cap_h,tip_h), tip_h);
anchors = [

View file

@ -3607,7 +3607,7 @@ module _textured_revolution(
convexity=10, counts, samples,
anchor=CENTER, spin=0, orient=UP
) {
assert(in_list(atype, _ANCHOR_TYPES), "Anchor type must be \"hull\" or \"intersect\"");
dummy = assert(in_list(atype, _ANCHOR_TYPES), "Anchor type must be \"hull\" or \"intersect\"");
vnf = _textured_revolution(
shape, texture, tex_size=tex_size,
tex_scale=tex_scale, inset=inset, rot=rot,

View file

@ -90,10 +90,10 @@ test_octagon();
module test_teardrop2d() {
$fn=24;
assert_approx(teardrop2d(r=50),[[0,70.7106781187],[35.3553390593,35.3553390593],[43.6811195323,24.3302239283],[48.671902718,11.4475274975],[49.9466487401,-2.30917293229],[47.4080323795,-15.8895709791],[41.2498737299,-28.2568207211],[31.9423402826,-38.4666985491],[20.1960502436,-45.7396934244],[6.90781774759,-49.5205215438],[-6.90781774759,-49.5205215438],[-20.1960502436,-45.7396934244],[-31.9423402826,-38.4666985491],[-41.2498737299,-28.2568207211],[-47.4080323795,-15.8895709791],[-49.9466487401,-2.30917293229],[-48.671902718,11.4475274975],[-43.6811195323,24.3302239283],[-35.3553390593,35.3553390593]]);
assert_approx(teardrop2d(d=100),[[0,70.7106781187],[35.3553390593,35.3553390593],[43.6811195323,24.3302239283],[48.671902718,11.4475274975],[49.9466487401,-2.30917293229],[47.4080323795,-15.8895709791],[41.2498737299,-28.2568207211],[31.9423402826,-38.4666985491],[20.1960502436,-45.7396934244],[6.90781774759,-49.5205215438],[-6.90781774759,-49.5205215438],[-20.1960502436,-45.7396934244],[-31.9423402826,-38.4666985491],[-41.2498737299,-28.2568207211],[-47.4080323795,-15.8895709791],[-49.9466487401,-2.30917293229],[-48.671902718,11.4475274975],[-43.6811195323,24.3302239283],[-35.3553390593,35.3553390593]]);
assert_approx(teardrop2d(r=50,cap_h=50),[[20.7106781187,50],[35.3553390593,35.3553390593],[43.6811195323,24.3302239283],[48.671902718,11.4475274975],[49.9466487401,-2.30917293229],[47.4080323795,-15.8895709791],[41.2498737299,-28.2568207211],[31.9423402826,-38.4666985491],[20.1960502436,-45.7396934244],[6.90781774759,-49.5205215438],[-6.90781774759,-49.5205215438],[-20.1960502436,-45.7396934244],[-31.9423402826,-38.4666985491],[-41.2498737299,-28.2568207211],[-47.4080323795,-15.8895709791],[-49.9466487401,-2.30917293229],[-48.671902718,11.4475274975],[-43.6811195323,24.3302239283],[-35.3553390593,35.3553390593],[-20.7106781187,50]]);
assert_approx(teardrop2d(r=50,cap_h=50,ang=30),[[28.8675134595,50],[43.3012701892,25],[48.5147863138,12.09609478],[49.969541351,-1.74497483513],[47.5528258148,-15.4508497187],[41.4518786278,-27.9596451735],[32.1393804843,-38.3022221559],[20.3368321538,-45.6772728821],[6.958655048,-49.5134034371],[-6.958655048,-49.5134034371],[-20.3368321538,-45.6772728821],[-32.1393804843,-38.3022221559],[-41.4518786278,-27.9596451735],[-47.5528258148,-15.4508497187],[-49.969541351,-1.74497483513],[-48.5147863138,12.09609478],[-43.3012701892,25],[-28.8675134595,50]]);
assert_approx(teardrop2d(r=50),[[0,70.7106781187],[35.3553390593,35.3553390593],[43.3012701892,25],[48.2962913145,12.9409522551],[50,0],[48.2962913145,-12.9409522551],[43.3012701892,-25],[35.3553390593,-35.3553390593],[25,-43.3012701892],[12.9409522551,-48.2962913145],[0,-50],[-12.9409522551,-48.2962913145],[-25,-43.3012701892],[-35.3553390593,-35.3553390593],[-43.3012701892,-25],[-48.2962913145,-12.9409522551],[-50,0],[-48.2962913145,12.9409522551],[-43.3012701892,25],[-35.3553390593,35.3553390593]]);
assert_approx(teardrop2d(d=100), [[0,70.7106781187],[35.3553390593,35.3553390593],[43.3012701892,25],[48.2962913145,12.9409522551],[50,0],[48.2962913145,-12.9409522551],[43.3012701892,-25],[35.3553390593,-35.3553390593],[25,-43.3012701892],[12.9409522551,-48.2962913145],[0,-50],[-12.9409522551,-48.2962913145],[-25,-43.3012701892],[-35.3553390593,-35.3553390593],[-43.3012701892,-25],[-48.2962913145,-12.9409522551],[-50,0],[-48.2962913145,12.9409522551],[-43.3012701892,25],[-35.3553390593,35.3553390593]]);
assert_approx(teardrop2d(r=50,cap_h=50),[[20.7106781187,50],[35.3553390593,35.3553390593],[43.3012701892,25],[48.2962913145,12.9409522551],[50,0],[48.2962913145,-12.9409522551],[43.3012701892,-25],[35.3553390593,-35.3553390593],[25,-43.3012701892],[12.9409522551,-48.2962913145],[0,-50],[-12.9409522551,-48.2962913145],[-25,-43.3012701892],[-35.3553390593,-35.3553390593],[-43.3012701892,-25],[-48.2962913145,-12.9409522551],[-50,0],[-48.2962913145,12.9409522551],[-43.3012701892,25],[-35.3553390593,35.3553390593],[-20.7106781187,50]]);
assert_approx(teardrop2d(r=50,cap_h=50,ang=30),[[28.8675134595,50],[43.3012701892,25],[48.2962913145,12.9409522551],[50,0],[48.2962913145,-12.9409522551],[43.3012701892,-25],[35.3553390593,-35.3553390593],[25,-43.3012701892],[12.9409522551,-48.2962913145],[0,-50],[-12.9409522551,-48.2962913145],[-25,-43.3012701892],[-35.3553390593,-35.3553390593],[-43.3012701892,-25],[-48.2962913145,-12.9409522551],[-50,0],[-48.2962913145,12.9409522551],[-43.3012701892,25],[-28.8675134595,50]]);
}
test_teardrop2d();

View file

@ -606,12 +606,13 @@ module npt_threaded_rod(
internal=false,
anchor, spin, orient
) {
assert(is_finite(size));
assert(is_bool(left_handed));
assert(is_undef(bevel) || is_bool(bevel));
assert(is_bool(hollow));
assert(is_bool(internal));
assert(!(internal&&hollow), "Cannot created a hollow internal threads mask.");
checks =
assert(is_finite(size))
assert(is_bool(left_handed))
assert(is_undef(bevel) || is_bool(bevel))
assert(is_bool(hollow))
assert(is_bool(internal))
assert(!(internal&&hollow), "Cannot created a hollow internal threads mask.");
info_table = [
// Size len OD TPI
[ 1/16, [ 0.3896, 0.308, 27 ]],

View file

@ -376,7 +376,7 @@ function furthest_point(pt, points) =
// color("blue")stroke(move(queries[i],circle(r=1)), closed=true, width=.08);
// color("red") move_copies(select(points, search_ind[i])) circle(r=.08);
// }
// Example: when a series of search with different radius are needed, its is faster to pre-compute the tree
// Example: when a series of searches with different radius are needed, its is faster to pre-compute the tree
// $fn=32;
// k = 2000;
// points = list_to_matrix(rands(0,10,k*2),2,seed=13333);
@ -419,8 +419,8 @@ function vector_search(query, r, target) =
"The query points should be a list of points compatible with the target point list.")
tgpts
? len(target)<=400
? simple ? [for(i=idx(target)) if(norm(target[i]-query)<r) i ] :
[for(q=query) [for(i=idx(target)) if(norm(target[i]-q)<r) i ] ]
? simple ? [for(i=idx(target)) if(norm(target[i]-query)<=r) i ] :
[for(q=query) [for(i=idx(target)) if(norm(target[i]-q)<=r) i ] ]
: let( tree = _bt_tree(target, count(len(target)), leafsize=25) )
simple ? _bt_search(query, r, target, tree) :
[for(q=query) _bt_search(q, r, target, tree)]