Merge pull request #292 from revarbat/revarbat_dev

Bugfixes for looping helpers.
This commit is contained in:
Revar Desmera 2020-10-07 16:57:12 -07:00 committed by GitHub
commit 33d713522b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 142 additions and 56 deletions

View file

@ -471,7 +471,7 @@ module shape_compare(eps=1/1024) {
// variables, that means that only the NEXT phase can be used for iterative calculations.
// Unfortunately, the NEXT phase runs *after* the RETVAL expression, which means that you need
// to run the loop one extra time to return the final value. This tends to make the loop code
// look rather ugly. The `looping()`, `loop_next()` and `loop_done()` functions
// look rather ugly. The `looping()`, `loop_while()` and `loop_done()` functions
// can make this somewhat more legible.
// ```openscad
// function flat_sum(l) = [
@ -482,9 +482,9 @@ module shape_compare(eps=1/1024) {
//
// looping(state);
//
// state = loop_next(state, i < len(l)),
// state = loop_while(state, i < len(l)),
// total = total +
// !looping(state) ? 0 :
// loop_done(state) ? 0 :
// let( x = l[i] )
// is_list(x) ? flat_sum(x) : x,
// i = i + 1
@ -497,27 +497,28 @@ module shape_compare(eps=1/1024) {
// Usage:
// looping(state)
// Description:
// Returns true if the `state` value indicates the loop is still progressing.
// Returns true if the `state` value indicates the current loop should continue.
// This is useful when using C-style for loops to iteratively calculate a value.
// Used with `loop_next()` and `loop_done()`. See [Looping Helpers](#looping-helpers) for an example.
// Used with `loop_while()` and `loop_done()`. See [Looping Helpers](#5-looping-helpers) for an example.
// Arguments:
// state = The loop state value.
function looping(state) = state<2;
function looping(state) = state < 2;
// Function: loop_next()
// Function: loop_while()
// Usage:
// state = loop_next(state, continue)
// state = loop_while(state, continue)
// Description:
// Given the current `state`, and a boolean `continue` that indicates if the loop should still be
// continuing, returns the updated state value for the the next loop.
// This is useful when using C-style for loops to iteratively calculate a value.
// Used with `looping()` and `loop_done()`. See [Looping Helpers](#looping-helpers) for an example.
// Used with `looping()` and `loop_done()`. See [Looping Helpers](#5-looping-helpers) for an example.
// Arguments:
// state = The loop state value.
// continue = A boolean value indicating whether the current loop should progress.
function loop_next(state, continue) =
state>=1? 2 : (continue? 0 : 1);
function loop_while(state, continue) =
state > 0 ? 2 :
continue ? 0 : 1;
// Function: loop_done()
@ -526,10 +527,10 @@ function loop_next(state, continue) =
// Description:
// Returns true if the `state` value indicates the loop is finishing.
// This is useful when using C-style for loops to iteratively calculate a value.
// Used with `looping()` and `loop_next()`. See [Looping Helpers](#looping-helpers) for an example.
// Used with `looping()` and `loop_while()`. See [Looping Helpers](#5-looping-helpers) for an example.
// Arguments:
// state = The loop state value.
function loop_done(state) = state==1;
function loop_done(state) = state > 0;
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View file

@ -909,6 +909,8 @@ function oval(r, d, realign=false, circum=false, anchor=CENTER, spin=0) =
// side = Length of each side.
// rounding = Radius of rounding for the tips of the polygon. Default: 0 (no rounding)
// realign = If false, a tip is aligned with the Y+ axis. If true, the midpoint of a side is aligned with the Y+ axis. Default: false
// align_tip = If given as a 2D vector, rotates the whole shape so that the first vertex points in that direction. This occurs before spin.
// align_side = If given as a 2D vector, rotates the whole shape so that the normal of side0 points in that direction. This occurs before spin.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// Extra Anchors:
@ -924,11 +926,22 @@ function oval(r, d, realign=false, circum=false, anchor=CENTER, spin=0) =
// regular_ngon(n=8, side=20);
// Example(2D): Realigned
// regular_ngon(n=8, side=20, realign=true);
// Example(2D): Alignment by Tip
// regular_ngon(n=5, r=30, align_tip=BACK+RIGHT)
// attach("tip0", FWD) color("blue")
// stroke([[0,0],[0,7]], endcap2="arrow2");
// Example(2D): Alignment by Side
// regular_ngon(n=5, r=30, align_side=BACK+RIGHT)
// attach("side0", FWD) color("blue")
// stroke([[0,0],[0,7]], endcap2="arrow2");
// Example(2D): Rounded
// regular_ngon(n=5, od=100, rounding=20, $fn=20);
// Example(2D): Called as Function
// stroke(closed=true, regular_ngon(n=6, or=30));
function regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0) =
function regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false, align_tip, align_side, anchor=CENTER, spin=0, _mat, _anchs) =
assert(is_undef(align_tip) || is_vector(align_tip))
assert(is_undef(align_side) || is_vector(align_side))
assert(is_undef(align_tip) || is_undef(align_side), "Can only specify one of align_tip and align-side")
let(
sc = 1/cos(180/n),
ir = is_finite(ir)? ir*sc : undef,
@ -939,13 +952,19 @@ function regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false
assert(!is_undef(r), "regular_ngon(): need to specify one of r, d, or, od, ir, id, side.")
let(
inset = opp_ang_to_hyp(rounding, (180-360/n)/2),
path = rounding==0? oval(r=r, realign=realign, $fn=n) : (
mat = !is_undef(_mat) ? _mat :
( realign? rot(-180/n, planar=true) : affine2d_identity() ) * (
!is_undef(align_tip)? rot(from=RIGHT, to=point2d(align_tip), planar=true) :
!is_undef(align_side)? rot(from=RIGHT, to=point2d(align_side), planar=true) * rot(180/n, planar=true) :
affine2d_identity()
),
path4 = rounding==0? oval(r=r, $fn=n) : (
let(
steps = floor(segs(r)/n),
step = 360/n/steps,
path2 = [
for (i = [0:1:n-1]) let(
a = 360 - i*360/n - (realign? 180/n : 0),
a = 360 - i*360/n,
p = polar_to_xy(r-inset, a)
)
each arc(N=steps, cp=p, r=rounding, start=a+180/n, angle=-360/n)
@ -954,13 +973,15 @@ function regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false
path3 = polygon_shift(path2,maxx_idx)
) path3
),
anchors = !is_string(anchor)? [] : [
path = apply(mat, path4),
anchors = !is_undef(_anchs) ? _anchs :
!is_string(anchor)? [] : [
for (i = [0:1:n-1]) let(
a1 = 360 - i*360/n - (realign? 180/n : 0),
a1 = 360 - i*360/n,
a2 = a1 - 360/n,
p1 = polar_to_xy(r,a1),
p2 = polar_to_xy(r,a2),
tipp = polar_to_xy(r-inset+rounding,a1),
p1 = apply(mat, polar_to_xy(r,a1)),
p2 = apply(mat, polar_to_xy(r,a2)),
tipp = apply(mat, polar_to_xy(r-inset+rounding,a1)),
pos = (p1+p2)/2
) each [
anchorpt(str("tip",i), tipp, unit(tipp,BACK), 0),
@ -970,28 +991,33 @@ function regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false
) reorient(anchor,spin, two_d=true, path=path, extent=false, p=path, anchors=anchors);
module regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0) {
module regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false, align_tip, align_side, anchor=CENTER, spin=0) {
sc = 1/cos(180/n);
ir = is_finite(ir)? ir*sc : undef;
id = is_finite(id)? id*sc : undef;
side = is_finite(side)? side/2/sin(180/n) : undef;
r = get_radius(r1=ir, r2=or, r=r, d1=id, d2=od, d=d, dflt=side);
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);
mat = ( realign? rot(-180/n, planar=true) : affine2d_identity() ) * (
!is_undef(align_tip)? rot(from=RIGHT, to=point2d(align_tip), planar=true) :
!is_undef(align_side)? rot(from=RIGHT, to=point2d(align_side), planar=true) * rot(180/n, planar=true) :
affine2d_identity()
);
inset = opp_ang_to_hyp(rounding, (180-360/n)/2);
anchors = [
for (i = [0:1:n-1]) let(
a1 = 360 - i*360/n - (realign? 180/n : 0),
a1 = 360 - i*360/n,
a2 = a1 - 360/n,
p1 = polar_to_xy(r,a1),
p2 = polar_to_xy(r,a2),
tipp = polar_to_xy(r-inset+rounding,a1),
p1 = apply(mat, polar_to_xy(r,a1)),
p2 = apply(mat, polar_to_xy(r,a2)),
tipp = apply(mat, polar_to_xy(r-inset+rounding,a1)),
pos = (p1+p2)/2
) each [
anchorpt(str("tip",i), tipp, unit(tipp,BACK), 0),
anchorpt(str("side",i), pos, unit(pos,BACK), 0),
]
];
path = regular_ngon(n=n, r=r, rounding=rounding, _mat=mat, _anchs=anchors);
attachable(anchor,spin, two_d=true, path=path, extent=false, anchors=anchors) {
polygon(path);
children();
@ -1017,6 +1043,8 @@ module regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false,
// side = Length of each side.
// rounding = Radius of rounding for the tips of the polygon. Default: 0 (no rounding)
// realign = If false, a tip is aligned with the Y+ axis. If true, the midpoint of a side is aligned with the Y+ axis. Default: false
// align_tip = If given as a 2D vector, rotates the whole shape so that the first vertex points in that direction. This occurs before spin.
// align_side = If given as a 2D vector, rotates the whole shape so that the normal of side0 points in that direction. This occurs before spin.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// Extra Anchors:
@ -1032,16 +1060,24 @@ module regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false,
// pentagon(side=20);
// Example(2D): Realigned
// pentagon(side=20, realign=true);
// Example(2D): Alignment by Tip
// pentagon(r=30, align_tip=BACK+RIGHT)
// attach("tip0", FWD) color("blue")
// stroke([[0,0],[0,7]], endcap2="arrow2");
// Example(2D): Alignment by Side
// pentagon(r=30, align_side=BACK+RIGHT)
// attach("side0", FWD) color("blue")
// stroke([[0,0],[0,7]], endcap2="arrow2");
// Example(2D): Rounded
// pentagon(od=100, rounding=20, $fn=20);
// Example(2D): Called as Function
// stroke(closed=true, pentagon(or=30));
function pentagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0) =
regular_ngon(n=5, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, anchor=anchor, spin=spin);
function pentagon(r, d, or, od, ir, id, side, rounding=0, realign=false, align_tip, align_side, anchor=CENTER, spin=0) =
regular_ngon(n=5, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, align_tip=align_tip, align_side=align_side, anchor=anchor, spin=spin);
module pentagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0)
regular_ngon(n=5, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, anchor=anchor, spin=spin) children();
module pentagon(r, d, or, od, ir, id, side, rounding=0, realign=false, align_tip, align_side, anchor=CENTER, spin=0)
regular_ngon(n=5, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, align_tip=align_tip, align_side=align_side, anchor=anchor, spin=spin) children();
// Function&Module: hexagon()
@ -1060,6 +1096,8 @@ module pentagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CE
// side = Length of each side.
// rounding = Radius of rounding for the tips of the polygon. Default: 0 (no rounding)
// realign = If false, a tip is aligned with the Y+ axis. If true, the midpoint of a side is aligned with the Y+ axis. Default: false
// align_tip = If given as a 2D vector, rotates the whole shape so that the first vertex points in that direction. This occurs before spin.
// align_side = If given as a 2D vector, rotates the whole shape so that the normal of side0 points in that direction. This occurs before spin.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// Extra Anchors:
@ -1075,16 +1113,24 @@ module pentagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CE
// hexagon(side=20);
// Example(2D): Realigned
// hexagon(side=20, realign=true);
// Example(2D): Alignment by Tip
// hexagon(r=30, align_tip=BACK+RIGHT)
// attach("tip0", FWD) color("blue")
// stroke([[0,0],[0,7]], endcap2="arrow2");
// Example(2D): Alignment by Side
// hexagon(r=30, align_side=BACK+RIGHT)
// attach("side0", FWD) color("blue")
// stroke([[0,0],[0,7]], endcap2="arrow2");
// Example(2D): Rounded
// hexagon(od=100, rounding=20, $fn=20);
// Example(2D): Called as Function
// stroke(closed=true, hexagon(or=30));
function hexagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0) =
regular_ngon(n=6, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, anchor=anchor, spin=spin);
function hexagon(r, d, or, od, ir, id, side, rounding=0, realign=false, align_tip, align_side, anchor=CENTER, spin=0) =
regular_ngon(n=6, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, align_tip=align_tip, align_side=align_side, anchor=anchor, spin=spin);
module hexagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0)
regular_ngon(n=6, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, anchor=anchor, spin=spin) children();
module hexagon(r, d, or, od, ir, id, side, rounding=0, realign=false, align_tip, align_side, anchor=CENTER, spin=0)
regular_ngon(n=6, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, align_tip=align_tip, align_side=align_side, anchor=anchor, spin=spin) children();
// Function&Module: octagon()
@ -1103,6 +1149,8 @@ module hexagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CEN
// side = Length of each side.
// rounding = Radius of rounding for the tips of the polygon. Default: 0 (no rounding)
// realign = If false, a tip is aligned with the Y+ axis. If true, the midpoint of a side is aligned with the Y+ axis. Default: false
// align_tip = If given as a 2D vector, rotates the whole shape so that the first vertex points in that direction. This occurs before spin.
// align_side = If given as a 2D vector, rotates the whole shape so that the normal of side0 points in that direction. This occurs before spin.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// Extra Anchors:
@ -1118,16 +1166,24 @@ module hexagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CEN
// octagon(side=20);
// Example(2D): Realigned
// octagon(side=20, realign=true);
// Example(2D): Alignment by Tip
// octagon(r=30, align_tip=BACK+RIGHT)
// attach("tip0", FWD) color("blue")
// stroke([[0,0],[0,7]], endcap2="arrow2");
// Example(2D): Alignment by Side
// octagon(r=30, align_side=BACK+RIGHT)
// attach("side0", FWD) color("blue")
// stroke([[0,0],[0,7]], endcap2="arrow2");
// Example(2D): Rounded
// octagon(od=100, rounding=20, $fn=20);
// Example(2D): Called as Function
// stroke(closed=true, octagon(or=30));
function octagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0) =
regular_ngon(n=8, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, anchor=anchor, spin=spin);
function octagon(r, d, or, od, ir, id, side, rounding=0, realign=false, align_tip, align_side, anchor=CENTER, spin=0) =
regular_ngon(n=8, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, align_tip=align_tip, align_side=align_side, anchor=anchor, spin=spin);
module octagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0)
regular_ngon(n=8, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, anchor=anchor, spin=spin) children();
module octagon(r, d, or, od, ir, id, side, rounding=0, realign=false, align_tip, align_side, anchor=CENTER, spin=0)
regular_ngon(n=8, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, align_tip=align_tip, align_side=align_side, anchor=anchor, spin=spin) children();
@ -1298,12 +1354,14 @@ module glued_circles(r, d, spread=10, tangent=30, anchor=CENTER, spin=0) {
// id = The diameter to the inner corners of the star.
// step = Calculates the radius of the inner star corners by virtually drawing a straight line `step` tips around the star. 2 <= step < n/2
// realign = If false, a tip is aligned with the Y+ axis. If true, an inner corner is aligned with the Y+ axis. Default: false
// align_tip = If given as a 2D vector, rotates the whole shape so that the first star tip points in that direction. This occurs before spin.
// align_pit = If given as a 2D vector, rotates the whole shape so that the first inner corner is pointed towards that direction. This occurs before spin.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// Extra Anchors:
// "tip0" ... "tip4" = Each tip has an anchor, pointing outwards.
// "corner0" ... "corner4" = The inside corner between each tip has an anchor, pointing outwards.
// "midpt0" ... "midpt4" = The center-point between each pair or tips has an anchor, pointing outwards.
// "pit0" ... "pit4" = The inside corner between each tip has an anchor, pointing outwards.
// "midpt0" ... "midpt4" = The center-point between each pair of tips has an anchor, pointing outwards.
// Examples(2D):
// star(n=5, r=50, ir=25);
// star(n=5, r=50, step=2);
@ -1311,9 +1369,20 @@ module glued_circles(r, d, spread=10, tangent=30, anchor=CENTER, spin=0) {
// star(n=7, r=50, step=3);
// Example(2D): Realigned
// star(n=7, r=50, step=3, realign=true);
// Example(2D): Alignment by Tip
// star(n=5, ir=15, or=30, align_tip=BACK+RIGHT)
// attach("tip0", FWD) color("blue")
// stroke([[0,0],[0,7]], endcap2="arrow2");
// Example(2D): Alignment by Pit
// star(n=5, ir=15, or=30, align_pit=BACK+RIGHT)
// attach("pit0", FWD) color("blue")
// stroke([[0,0],[0,7]], endcap2="arrow2");
// Example(2D): Called as Function
// stroke(closed=true, star(n=5, r=50, ir=25));
function star(n, r, d, or, od, ir, id, step, realign=false, anchor=CENTER, spin=0) =
function star(n, r, d, or, od, ir, id, step, realign=false, align_tip, align_pit, anchor=CENTER, spin=0, _mat, _anchs) =
assert(is_undef(align_tip) || is_vector(align_tip))
assert(is_undef(align_pit) || is_vector(align_pit))
assert(is_undef(align_tip) || is_undef(align_pit), "Can only specify one of align_tip and align_pit")
let(
r = get_radius(r1=or, d1=od, r=r, d=d),
count = num_defined([ir,id,step]),
@ -1323,48 +1392,64 @@ function star(n, r, d, or, od, ir, id, step, realign=false, anchor=CENTER, spin=
assert(count==1, "Must specify exactly one of ir, id, step")
assert(stepOK, str("Parameter 'step' must be between 2 and ",floor(n/2)," for ",n," point star"))
let(
mat = !is_undef(_mat) ? _mat :
( realign? rot(-180/n, planar=true) : affine2d_identity() ) * (
!is_undef(align_tip)? rot(from=RIGHT, to=point2d(align_tip), planar=true) :
!is_undef(align_pit)? rot(from=RIGHT, to=point2d(align_pit), planar=true) * rot(180/n, planar=true) :
affine2d_identity()
),
stepr = is_undef(step)? r : r*cos(180*step/n)/cos(180*(step-1)/n),
ir = get_radius(r=ir, d=id, dflt=stepr),
offset = realign? 180/n : 0,
path = [for(i=[2*n:-1:1]) let(theta=180*i/n+offset, radius=(i%2)?ir:r) radius*[cos(theta), sin(theta)]],
anchors = !is_string(anchor)? [] : [
path1 = [for(i=[2*n:-1:1]) let(theta=180*i/n, radius=(i%2)?ir:r) radius*[cos(theta), sin(theta)]],
path = apply(mat, path1),
anchors = !is_undef(_anchs) ? _anchs :
!is_string(anchor)? [] : [
for (i = [0:1:n-1]) let(
a1 = 360 - i*360/n - (realign? 180/n : 0),
a1 = 360 - i*360/n,
a2 = a1 - 180/n,
a3 = a1 - 360/n,
p1 = polar_to_xy(r,a1),
p2 = polar_to_xy(ir,a2),
p3 = polar_to_xy(r,a3),
p1 = apply(mat, polar_to_xy(r,a1)),
p2 = apply(mat, polar_to_xy(ir,a2)),
p3 = apply(mat, polar_to_xy(r,a3)),
pos = (p1+p3)/2
) each [
anchorpt(str("tip",i), p1, unit(p1,BACK), 0),
anchorpt(str("corner",i), p2, unit(p2,BACK), 0),
anchorpt(str("pit",i), p2, unit(p2,BACK), 0),
anchorpt(str("midpt",i), pos, unit(pos,BACK), 0),
]
]
) reorient(anchor,spin, two_d=true, path=path, p=path, anchors=anchors);
module star(n, r, d, or, od, ir, id, step, realign=false, anchor=CENTER, spin=0) {
module star(n, r, d, or, od, ir, id, step, realign=false, align_tip, align_pit, anchor=CENTER, spin=0) {
assert(is_undef(align_tip) || is_vector(align_tip));
assert(is_undef(align_pit) || is_vector(align_pit));
assert(is_undef(align_tip) || is_undef(align_pit), "Can only specify one of align_tip and align_pit");
r = get_radius(r1=or, d1=od, r=r, d=d, dflt=undef);
stepr = is_undef(step)? r : r*cos(180*step/n)/cos(180*(step-1)/n);
ir = get_radius(r=ir, d=id, dflt=stepr);
path = star(n=n, r=r, ir=ir, realign=realign);
mat = ( realign? rot(-180/n, planar=true) : affine2d_identity() ) * (
!is_undef(align_tip)? rot(from=RIGHT, to=point2d(align_tip), planar=true) :
!is_undef(align_pit)? rot(from=RIGHT, to=point2d(align_pit), planar=true) * rot(180/n, planar=true) :
affine2d_identity()
);
anchors = [
for (i = [0:1:n-1]) let(
a1 = 360 - i*360/n - (realign? 180/n : 0),
a2 = a1 - 180/n,
a3 = a1 - 360/n,
p1 = polar_to_xy(r,a1),
p2 = polar_to_xy(ir,a2),
p3 = polar_to_xy(r,a3),
p1 = apply(mat, polar_to_xy(r,a1)),
p2 = apply(mat, polar_to_xy(ir,a2)),
p3 = apply(mat, polar_to_xy(r,a3)),
pos = (p1+p3)/2
) each [
anchorpt(str("tip",i), p1, unit(p1,BACK), 0),
anchorpt(str("corner",i), p2, unit(p2,BACK), 0),
anchorpt(str("pit",i), p2, unit(p2,BACK), 0),
anchorpt(str("midpt",i), pos, unit(pos,BACK), 0),
]
];
path = star(n=n, r=r, ir=ir, realign=realign, _mat=mat, _anchs=anchors);
attachable(anchor,spin, two_d=true, path=path, anchors=anchors) {
polygon(path);
children();

View file

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