Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

System Functions Reference

System functions are pre-defined arrow functions for common CAM outline shapes. They are automatically loaded into every FSL program.

Usage

Call a system function like any other arrow function:

gear = 96
Round()                    // Uses defaults: angle=43, sym=8
Round(45, 6)               // Override parameters
Oval(45, 1.5)              // Override length-width ratio (angle defaults to 45)
-- lua script
gear(96)
Round()                    -- Uses defaults: angle=43, sym=8
Round(45, 6)               -- Override parameters
Oval(45, 1.5)              -- Override length-width ratio (angle defaults to 45)

Available Functions

FunctionParametersDescription
Roundangle=43, sym=8Simple round preform
Hexagonangle=43Hexagonal preform (Round with 6-fold symmetry)
HexTrangle=42, truncation=0.3Hexagon with truncated corners
HexTrMirangle=42, truncation=0.3, offset=2Mirrored hexagon with truncated corners
Ovalangle=45, lwr=1.2, segmentsPerQuad=5Elliptical outline
Rectlwr=1.5, angle=45Rectangular outline
RectTrlwr=1.5, angle=45, truncation=0.3, offset=0Rectangle with truncated corners
RectDblTrlwr=1.5, angle=45, first_truncation=0.3, second_truncation=0.2, offset=0Double-truncated rectangle for octagons
SquareTrangle=42, truncation=0.3Square with truncated corners
SquareTrMirangle=42, truncation=0.5, offset=4Mirrored square with truncated corners
SquareCushTrcushion=1, angle=45, truncation=0.4Cushion square with truncation
PentCushTroffset=1, angle=45, truncation=0.3Pentagon cushion with truncation
Shieldangle=45Shield outline (threefold symmetry)
TriTrtruncation=0.25, angle=42Triangle with truncated corners
TriTrMirtruncation=0.25, angle=42, offset=4Mirrored triangle with truncated corners
TriCushTrtruncation=0.25, angle=42, cushion=1Cushion triangle
TriCurvedangle=45, c1=2, c2=4Curved trilliant

Source Code

The system functions are defined using FSL. Here is the complete source:

// System library - lambda syntax with defaults

Round = (angle = 43, sym = 10) => {

    assert(gear%sym == 0, "Gear must be divisible by symmetry count")
    PF1 0 @ angle : cp() x sym
    G1 0 @ 90 : size
}

Octagon = (angle = 43) => {

    assert(gear%8 == 0, "Gear must be divisible by 8 for Octagon")
    Round(angle, 8)
}

Heptagon = (angle = 43) => {

    assert(gear == 84, "Heptagon should use a gear index of 84")
    Round(angle, 7)
}

Pentagon = (angle = 43) => {

    assert(gear == 120, "Pentagon should use a gear index of 120")
    Round(angle, 5)
}

Hexagon = (angle = 43) => {

    Round(angle, 6)
}

HexTr = (angle = 42, truncation = 0.3) => {

    assert(gear%12 == 0, "Gear must be divisible by 12 for HexTr")
    corner_index = gear / 12
    PF1 0 @ angle : cp() x6
    G1 0 @ 90 : size x6
    PF2 corner_index : cp() : ep(edge(PF1 : 0, G1 : 0), 1 - truncation / 2) x6
    G2 corner_index @ 90 : mp(G1, PF1, PF2) x6
}

HexTrMir = (angle = 42, truncation = 0.3, offset = 2) => {

    // Truncated Hexagon Mirrored using offset

    assert(gear%12 == 0, "Gear must be divisible by 12 for HexTrMir")
    corner_index = gear / 12 - offset
    PF1 0 @ angle : cp() xx6
    G1 0 @ 90 : size
    PF2 corner_index : cp() : ep(edge(PF1 : 0, G1 : 0), 1 - truncation / 2)
    G2 corner_index @ 90 : mp(G1, PF1, PF2)
}

Rect = (lwr = 1.5, angle = 45) => {

    assert(gear%4 == 0, "Gear must be divisible by 4 for Rect")
    cube = 1
    beta = Math.toDegrees(Math.atan(Math.tan(Math.toRadians(angle)) / lwr))
    corner_index = gear / 4
    PF1 corner_index @ beta : cp() xx2
    PF2 0 @ angle : cp()
    G1 corner_index @ 90 : 0.5
    G2 0 @ 90 : mp(G1, PF1, PF2)
}

RectTr = (lwr = 1.5, angle = 45, truncation = 0.3, offset = 0) => {

    assert(gear%8 == 0, "Gear must be divisible by 8 for RectTr")
    cube = 1
    beta = Math.toDegrees(Math.atan(Math.tan(Math.toRadians(angle)) / lwr))
    corner_index = gear / 4
    PF1 corner_index @ beta : cp() xx2
    PF2 0 @ angle : cp()
    G1 corner_index @ 90 : 0.5
    G2 0 @ 90 : mp(G1, PF1, PF2)

    tr_index = gear / 8 + offset
    PF3 tr_index : cp() : ep(edge(PF1 : corner_index, G1 : corner_index), 1 - truncation / 2)
    G3 tr_index @ 90 : mp(G2, PF3, PF2)
}

RectDblTr = (lwr = 1.5, angle = 45, first_truncation = 0.3, second_truncation = 0.2, offset = 0) => {

    // Double-truncated rectangle for octagons.

    assert(lwr > 0, "Length-to-width ratio must be positive.")
    assert(gear%4 == 0, "Gear index should be a multiple of 4.")
    assert(first_truncation >= 0, "First truncation must be non-negative.")
    assert(first_truncation <= 1, "First truncation should stay within 0-1.")
    assert(second_truncation >= 0, "Second truncation must be non-negative.")
    assert(second_truncation <= 1, "Second truncation should stay within 0-1.")
    cube = 1
    corner_index = gear / 4
    split_index = Math.floor(gear / 8) + offset
    outer_ratio = first_truncation / 2
    inner_ratio = second_truncation / 2
    ind1 = corner_index + offset
    PF1 ind1 @ Math.toDegrees(Math.atan(
    Math.tan(Math.toRadians(angle)) / lwr)) : cp() x 2
    PF2 offset @ angle : cp()
    G1 ind1 @ 90 : size
    G2 offset @ 90 : mp(G1, PF1, PF2)
    PF3 split_index
    : cp()
    : ep(edge(PF1 : (corner_index + offset), G1 : (corner_index + offset)), 1 - outer_ratio) xx2
    G3 split_index @ 90 : mp(G2, PF3, PF2)
    ind2 = (Math.floor(3 * gear / 16) + offset)
    PF4 ind2
    : cp()
    : ep(edge(PF3 : split_index, G3 : split_index), inner_ratio)
    ind3 = (Math.floor(gear / 16) + offset)
    PF5 ind3
    : cp()
    : ep(edge(PF3 : split_index, G3 : split_index), 1 - inner_ratio)

    G4 ind3 @ 90 : mp(G3, PF5, PF3)
    G5 ind2 @ 90 : mp(G3, PF4, PF3)
}

SquareTr = (angle = 42, truncation = 0.3) => {

    assert(gear%8 == 0, "Gear must be divisible by 8 for SquareTr")
    cube = 2
    corner_index = gear / 8
    PF1 0 @ angle : cp() x4
    G1 0 @ 90 : size x4
    PF2 corner_index : cp() : ep(edge(PF1 : 0, G1 : 0), 1 - truncation / 2) x4
    G2 corner_index @ 90 : mp(G1, PF1, PF2) x4
}

SquareTrMir = (angle = 42, truncation = 0.5, offset = 4) => {

    // Square Truncated and Mirrored

    assert(gear%8 == 0, "Gear must be divisible by 8 for SquareTr")
    corner_index = gear / 8 - offset
    PF1 0 @ angle : cp() xx4
    G1 0 @ 90 : size
    PF2 corner_index : cp() : ep(edge(PF1 : 0, G1 : 0), 1 - truncation / 2)
    G2 corner_index @ 90 : mp(G1, PF1, PF2)
}

Shield = (angle = 45) => {

    assert(gear%6 == 0, "Gear must be divisible by 6 for Shield")
    PF1 6 @ angle : cp() xx3
    G1 6 @ 90 : size
}

TriTr = (truncation = 0.25, angle = 42) => {

    assert(gear%6 == 0, "Gear must be divisible by 6 for TriTr")
    PF1 0 @ angle : cp() x3
    G1 0 @ 90 : 0.7
    PF2 gear / 6 : cp() : ep(edge(PF1 : 0, G1 : 0), 1 - truncation / 2)
    G2 gear / 6 @ 90 : mp(G1, PF1, PF2)
}

TriTrMir = (truncation = 0.25, angle = 42, offset = 4) => {

    // Truncated Triangle Mirrored using offset

    assert(gear%6 == 0, "Gear must be divisible by 6 for TriTrMir")
    PF1 0 @ angle : cp() x3
    G1 0 @ 90 : 0.7 x3
    PF2 gear / 6 - offset : cp() : ep(edge(PF1 : 0, G1 : 0), 1 - truncation / 2) xx3
    G2 gear / 6 - offset @ 90 : mp(G1, PF1, PF2) xx3
}

Oval = (angle = 45, lwr = 1.2, segmentsPerQuad = 5) => {

    assert(lwr > 0, "Length-to-width ratio must be positive")
    assert(segmentsPerQuad >= 2, "segmentsPerQuad must be at least 2")
    assert(gear%4 == 0, "Gear index should be a multiple of 4")

    width = 1
    length = lwr
    rx = length / 2
    ry = width / 2
    quarter = gear / 4
    steps = segmentsPerQuad
    stepSize = quarter / steps
    h = Math.cos(angle * Math.PI / 90)

    Math.range(1, steps + 1).forEach(k => {

        idx = Math.round(k * stepSize)%gear
        ang = (idx / gear) * 2 * Math.PI
        c = Math.cos(ang)
        s = Math.sin(ang)
        d = Math.sqrt(rx * rx * c * c + ry * ry * s * s)

        prevK = k - 1
        prevIdx = Math.round(prevK * stepSize)%gear

        prevAng = (prevIdx / gear) * 2 * Math.PI
        prevC = Math.cos(prevAng)
        prevS = Math.sin(prevAng)
        prevD = Math.sqrt(rx * rx * prevC * prevC + ry * ry * prevS * prevS)

        det = prevC * s - prevS * c
        x = (prevD * s - d * prevS) / det
        y = (d * prevC - prevD * c) / det

        concat(O, k) prevIdx : Point(x, y,  - h) : cp() xx2

        k == steps ? {

            concat(O, k + 1) quarter : Point(x, y,  - h) : cp() xx2
        }
        : 0
    }
    )

    G1 0 @ 90 : size

    Math.range(2, steps + 1).forEach(k => {

        idx = Math.round((k - 1) * stepSize)%gear
        concat(G, k) idx @ 90 : mp(concat(G, k - 1), concat(O, k - 1))
    }
    )
    concat(G, steps + 1) quarter @ 90 : mp(concat(G, steps), concat(O, steps))
}

SquareCushTr = (cushion = 1, angle = 45, truncation = 0.4) => {

    assert(cushion >= 1, "Index offset must be 1 or more")
    assert(gear%4 == 0, "Gear must be multiple of 4")
    side_index = cushion
    corner_index = gear / 8

    G1 side_index @ 90 : size xx4
    PF1 side_index @ angle : cp()

    PF2 corner_index : cp() : ep(edge(PF1 : side_index, G1 : side_index), truncation / 2) x4
    G2 corner_index @ 90 : mp(G1, PF2, PF1)
}

PentCushTr = (offset = 1, angle = 45, truncation = 0.3) => {

    assert(offset >= 1, "Offset >= 1")
    assert(truncation >= 0)
    assert(truncation <= 1)
    assert(gear%10 == 0)

    side_index = offset
    corner_index = gear / 10

    G1 side_index @ 90 : size xx5
    PF1 side_index @ angle : cp()

    PF2 corner_index : cp() : ep(edge(PF1 : side_index, G1 : side_index), truncation)
    G2 corner_index @ 90 : mp(G1, PF1, PF2)
}

TriCushTr = (truncation = 0.25, angle = 42, cushion = 1) => {

    assert(truncation >= 0)
    assert(truncation < 2)
    assert(cushion >= 0)
    assert(gear%6 == 0)

    PF1 cushion @ angle : cp() xx3
    G1 cushion @ 90 : 0.7

    PF2 gear / 6 : cp() : ep(edge(PF1 : cushion, G1 : cushion), truncation) x3
    G2 gear / 6 @ 90 : mp(G1, PF1, PF2)
}

TriCurved = (angle = 45, c1 = 2, c2 = 4) => {

    cube = 3.4
    assert(c1 < c2)
    assert(gear%c1 == 0)
    assert(gear%c2 == 0)

    PF1 c1 @ angle : cp() xx3
    G1 c1 @ 90 : size
    PF2 c2 : cp() : ep(edge(PF1 : c1, G1 : c1), 0.5)
    G2 c2 @ 90 : mp(PF1, PF2, G1)
}

TriCushTrMir = (truncation = 0.25, angle = 42, cushion = 1, offset = 2) => {

    assert(truncation >= 0)
    assert(truncation < 2)
    assert(cushion >= 0)
    assert(gear%6 == 0, "Gear must be divisible by 6 for TriCushTrMir")

    PF1 cushion @ angle : cp() xx3
    G1 cushion @ 90 : 0.7 xx3
    PF2 gear / 6 - offset : cp() : ep(edge(PF1 : cushion, G1 : cushion), truncation) xx3
    G2 gear / 6 - offset @ 90 : mp(G1, PF1, PF2) xx3
}

SquareCurved = (angle = 45, c1 = 2, c2 = 4) => {

    cube = 2.5
    assert(c1 < c2)
    assert(gear%c1 == 0)
    assert(gear%c2 == 0)

    PF1 c1 @ angle : cp() xx4
    G1 c1 @ 90 : size
    PF2 c2 : cp() : ep(edge(PF1 : c1, G1 : c1), 0.5)
    G2 c2 @ 90 : mp(PF1, PF2, G1)
}

SquareCushTrMir = (cushion = 1, angle = 45, truncation = 0.4, offset = 2) => {

    assert(cushion >= 1, "Index offset must be 1 or more")
    assert(gear%8 == 0, "Gear must be divisible by 8 for SquareCushTrMir")

    side_index = cushion
    corner_index = gear / 8 - offset

    G1 side_index @ 90 : size xx4
    PF1 side_index @ angle : cp()
    PF2 corner_index : cp() : ep(edge(PF1 : side_index, G1 : side_index), truncation / 2)
    G2 corner_index @ 90 : mp(G1, PF2, PF1)
}

PentTr = (angle = 42, truncation = 0.3) => {

    assert(gear%10 == 0, "Gear must be divisible by 10 for PentTr")
    corner_index = gear / 10
    PF1 0 @ angle : cp() x5
    G1 0 @ 90 : size x5
    PF2 corner_index : cp() : ep(edge(PF1 : 0, G1 : 0), 1 - truncation / 2) x5
    G2 corner_index @ 90 : mp(G1, PF1, PF2) x5
}

PentTrMir = (truncation = 0.25, angle = 42, offset = 4) => {

    assert(gear%10 == 0, "Gear must be divisible by 10 for PentTrMir")
    PF1 0 @ angle : cp() x5
    G1 0 @ 90 : size x5
    PF2 gear / 10 - offset : cp() : ep(edge(PF1 : 0, G1 : 0), 1 - truncation / 2) xx5
    G2 gear / 10 - offset @ 90 : mp(G1, PF1, PF2) xx5
}

PentCurved = (angle = 45, c1 = 2, c2 = 4) => {

    cube = 3
    assert(c1 < c2)
    assert(gear%c1 == 0)
    assert(gear%c2 == 0)

    PF1 c1 @ angle : cp() xx5
    G1 c1 @ 90 : size
    PF2 c2 : cp() : ep(edge(PF1 : c1, G1 : c1), 0.5)
    G2 c2 @ 90 : mp(PF1, PF2, G1)
}

PentCushTrMir = (offset = 1, angle = 45, truncation = 0.3, mir_offset = 2) => {

    assert(offset >= 1, "Offset >= 1")
    assert(truncation >= 0)
    assert(truncation <= 1)
    assert(gear%10 == 0, "Gear must be divisible by 10 for PentCushTrMir")

    side_index = offset
    corner_index = gear / 10 - mir_offset

    G1 side_index @ 90 : size xx5
    PF1 side_index @ angle : cp()
    PF2 corner_index : cp() : ep(edge(PF1 : side_index, G1 : side_index), truncation)
    G2 corner_index @ 90 : mp(G1, PF1, PF2)
}

HexCurved = (angle = 45, c1 = 2, c2 = 4) => {

    cube = 3.2
    assert(c1 < c2)
    assert(gear%c1 == 0)
    assert(gear%c2 == 0)

    PF1 c1 @ angle : cp() xx6
    G1 c1 @ 90 : size
    PF2 c2 : cp() : ep(edge(PF1 : c1, G1 : c1), 0.5)
    G2 c2 @ 90 : mp(PF1, PF2, G1)
}

HexCushTr = (offset = 1, angle = 45, truncation = 0.3) => {

    assert(offset >= 1, "Offset >= 1")
    assert(truncation >= 0)
    assert(truncation <= 1)
    assert(gear%12 == 0, "Gear must be divisible by 12 for HexCushTr")

    side_index = offset
    corner_index = gear / 12

    G1 side_index @ 90 : size xx6
    PF1 side_index @ angle : cp()
    PF2 corner_index : cp() : ep(edge(PF1 : side_index, G1 : side_index), truncation)
    G2 corner_index @ 90 : mp(G1, PF1, PF2)
}

HexCushTrMir = (offset = 1, angle = 45, truncation = 0.3, mir_offset = 2) => {

    assert(offset >= 1, "Offset >= 1")
    assert(truncation >= 0)
    assert(truncation <= 1)
    assert(gear%12 == 0, "Gear must be divisible by 12 for HexCushTrMir")

    side_index = offset
    corner_index = gear / 12 - mir_offset

    G1 side_index @ 90 : size xx6
    PF1 side_index @ angle : cp()
    PF2 corner_index : cp() : ep(edge(PF1 : side_index, G1 : side_index), truncation)
    G2 corner_index @ 90 : mp(G1, PF1, PF2)
}

HeptTr = (angle = 42, truncation = 0.3) => {

    assert(gear%14 == 0, "Gear must be divisible by 14 for HeptTr")
    corner_index = gear / 14
    PF1 0 @ angle : cp() x7
    G1 0 @ 90 : size x7
    PF2 corner_index : cp() : ep(edge(PF1 : 0, G1 : 0), 1 - truncation / 2) x7
    G2 corner_index @ 90 : mp(G1, PF1, PF2) x7
}

HeptTrMir = (truncation = 0.25, angle = 42, offset = 2) => {

    assert(gear%14 == 0, "Gear must be divisible by 14 for HeptTrMir")
    PF1 0 @ angle : cp() x7
    G1 0 @ 90 : size x7
    PF2 gear / 14 - offset : cp() : ep(edge(PF1 : 0, G1 : 0), 1 - truncation / 2) xx7
    G2 gear / 14 - offset @ 90 : mp(G1, PF1, PF2) xx7
}

HeptCurved = (angle = 45, c1 = 2, c2 = 4) => {

    cube = 3.4
    assert(c1 < c2)
    assert(gear%c1 == 0)
    assert(gear%c2 == 0)

    PF1 c1 @ angle : cp() xx7
    G1 c1 @ 90 : size
    PF2 c2 : cp() : ep(edge(PF1 : c1, G1 : c1), 0.5)
    G2 c2 @ 90 : mp(PF1, PF2, G1)
}

HeptCushTr = (offset = 1, angle = 45, truncation = 0.3) => {

    assert(offset >= 1, "Offset >= 1")
    assert(truncation >= 0)
    assert(truncation <= 1)
    assert(gear%14 == 0, "Gear must be divisible by 14 for HeptCushTr")

    side_index = offset
    corner_index = gear / 14

    G1 side_index @ 90 : size xx7
    PF1 side_index @ angle : cp()
    PF2 corner_index : cp() : ep(edge(PF1 : side_index, G1 : side_index), truncation)
    G2 corner_index @ 90 : mp(G1, PF1, PF2)
}

HeptCushTrMir = (offset = 1, angle = 45, truncation = 0.3, mir_offset = 1) => {

    assert(offset >= 1, "Offset >= 1")
    assert(truncation >= 0)
    assert(truncation <= 1)
    assert(gear%14 == 0, "Gear must be divisible by 14 for HeptCushTrMir")

    side_index = offset
    corner_index = gear / 14 - mir_offset

    G1 side_index @ 90 : size xx7
    PF1 side_index @ angle : cp()
    PF2 corner_index : cp() : ep(edge(PF1 : side_index, G1 : side_index), truncation)
    G2 corner_index @ 90 : mp(G1, PF1, PF2)
}

OctTr = (angle = 42, truncation = 0.3) => {

    assert(gear%16 == 0, "Gear must be divisible by 16 for OctTr")
    corner_index = gear / 16
    PF1 0 @ angle : cp() x8
    G1 0 @ 90 : size x8
    PF2 corner_index : cp() : ep(edge(PF1 : 0, G1 : 0), 1 - truncation / 2) x8
    G2 corner_index @ 90 : mp(G1, PF1, PF2) x8
}

OctTrMir = (angle = 42, truncation = 0.3, offset = 2) => {

    assert(gear%16 == 0, "Gear must be divisible by 16 for OctTrMir")
    corner_index = gear / 16 - offset
    PF1 0 @ angle : cp() xx8
    G1 0 @ 90 : size
    PF2 corner_index : cp() : ep(edge(PF1 : 0, G1 : 0), 1 - truncation / 2)
    G2 corner_index @ 90 : mp(G1, PF1, PF2)
}

OctCurved = (angle = 45, c1 = 2, c2 = 4) => {

    cube = 3.4
    assert(c1 < c2)
    assert(gear%c1 == 0)
    assert(gear%c2 == 0)

    PF1 c1 @ angle : cp() xx8
    G1 c1 @ 90 : size
    PF2 c2 : cp() : ep(edge(PF1 : c1, G1 : c1), 0.5)
    G2 c2 @ 90 : mp(PF1, PF2, G1)
}

OctCushTr = (offset = 1, angle = 45, truncation = 0.3) => {

    assert(offset >= 1, "Offset >= 1")
    assert(truncation >= 0)
    assert(truncation <= 1)
    assert(gear%16 == 0, "Gear must be divisible by 16 for OctCushTr")

    side_index = offset
    corner_index = gear / 16

    G1 side_index @ 90 : size xx8
    PF1 side_index @ angle : cp()
    PF2 corner_index : cp() : ep(edge(PF1 : side_index, G1 : side_index), truncation)
    G2 corner_index @ 90 : mp(G1, PF1, PF2)
}

OctCushTrMir = (offset = 1, angle = 45, truncation = 0.3, mir_offset = 1) => {

    assert(offset >= 1, "Offset >= 1")
    assert(truncation >= 0)
    assert(truncation <= 1)
    assert(gear%16 == 0, "Gear must be divisible by 16 for OctCushTrMir")

    side_index = offset
    corner_index = gear / 16 - mir_offset

    G1 side_index @ 90 : size xx8
    PF1 side_index @ angle : cp()
    PF2 corner_index : cp() : ep(edge(PF1 : side_index, G1 : side_index), truncation)
    G2 corner_index @ 90 : mp(G1, PF1, PF2)
}

Lozenge = (angle = 43, lwr = 1.6) => {

    assert(lwr >= 1.05, "Length-to-width ratio must be at least 1.05")
    assert(lwr <= 2.6, "Length-to-width ratio must be at most 2.60")
    assert(gear%4 == 0, "Gear must be divisible by 4 for Lozenge")

    cube = 3
    quarter = gear / 4
    ry = 0.65 * size
    raw_idx = Math.round(Math.atan(lwr) / (2 * Math.PI) * gear)
    idx1 = Math.max(4, Math.min(quarter - 4, raw_idx))
    theta1 = idx1 / gear * 2 * Math.PI
    d1 = ry * Math.sin(theta1)

    PF1 idx1 @ angle : cp() xx2
    G1 idx1 @ 90 : d1 xx2
}

Kite = (angle = 43, lwr = 1.55, headRatio = 0.34) => {

    assert(lwr >= 1.15, "Length-to-width ratio must be at least 1.15")
    assert(lwr <= 2.4, "Length-to-width ratio must be at most 2.40")
    assert(headRatio >= 0.2, "headRatio must be at least 0.20")
    assert(headRatio <= 0.44, "headRatio must be at most 0.44")
    assert(gear%4 == 0, "Gear must be divisible by 4 for Kite")

    cube = 3
    quarter = gear / 4
    half = gear / 2
    ry = 0.65 * size
    total_len = 2 * ry * lwr
    front_len = total_len * (1 - headRatio)
    back_len = total_len * headRatio

    raw_idx1 = Math.round(Math.atan(front_len / ry) / (2 * Math.PI) * gear)
    idx1 = Math.max(4, Math.min(quarter - 3, raw_idx1))
    theta1 = idx1 / gear * 2 * Math.PI
    d1 = ry * Math.sin(theta1)

    back_phi = Math.atan(back_len / ry)
    raw_idx2 = Math.round((Math.PI - back_phi) / (2 * Math.PI) * gear)
    idx2 = Math.max(quarter + 3, Math.min(half - 4, raw_idx2))
    theta2 = idx2 / gear * 2 * Math.PI
    d2 = ry * Math.sin(theta2)

    tan_base = Math.tan(Math.toRadians(angle))
    pf2_ang = Math.toDegrees(Math.atan(d1 / d2 * tan_base))

    PF1 idx1 @ angle : cp() xx1
    PF2 idx2 @ pf2_ang : cp() xx1
    G1 idx1 @ 90 : d1 xx1
    G2 idx2 @ 90 : d2 xx1
}

Marquise = (angle = 43, lwr = 1.8, segmentsPerQuad = 4) => {

    assert(lwr >= 1.25, "Length-to-width ratio must be at least 1.25")
    assert(lwr <= 2.5, "Length-to-width ratio must be at most 2.50")
    assert(segmentsPerQuad >= 2, "segmentsPerQuad must be at least 2")
    assert(segmentsPerQuad <= 7, "segmentsPerQuad must be at most 7")
    assert(gear%4 == 0, "Gear must be divisible by 4 for Marquise")

    cube = 3
    quarter = gear / 4
    ry = 0.6 * size
    rx = ry * lwr
    arc_c = 0.5 * (rx * rx - ry * ry) / ry
    arc_r = 0.5 * (rx * rx + ry * ry) / ry
    theta_tip = Math.atan2(arc_c, rx)
    steps = segmentsPerQuad
    raw_start = Math.ceil(theta_tip / (2 * Math.PI) * gear)
    idx_start = Math.min(quarter - steps + 1, Math.max(3, raw_start))
    tan_base = Math.tan(Math.toRadians(angle))

    Math.range(1, steps + 1).forEach(k => {

        frac = 1 * (k - 1) / Math.max(1, steps - 1)
        idx = Math.round(idx_start + frac * (quarter - idx_start))
        ang_rad = idx / gear * 2 * Math.PI
        dk = arc_r - arc_c * Math.sin(ang_rad)
        pf_ang = Math.toDegrees(Math.atan(ry / dk * tan_base))

        concat(PF, k) idx @ pf_ang : cp() xx2
        concat(G, k) idx @ 90 : dk xx2
    }
    )
}

Pear = (angle = 43, lwr = 1.55, segments = 4) => {

    assert(lwr >= 1.25, "Length-to-width ratio must be at least 1.25")
    assert(lwr <= 2.2, "Length-to-width ratio must be at most 2.20")
    assert(segments >= 3, "segments must be at least 3")
    assert(segments <= 6, "segments must be at most 6")
    assert(gear%4 == 0, "Gear must be divisible by 4 for Pear")

    cube = 3
    quarter = gear / 4
    half = gear / 2
    ry = 0.6 * size
    tip_len = ry * (2 * lwr - 1)
    arc_c = 0.5 * (tip_len * tip_len - ry * ry) / ry
    arc_r = 0.5 * (tip_len * tip_len + ry * ry) / ry
    theta_tip = Math.atan2(arc_c, tip_len)
    front_steps = segments
    back_steps = segments
    raw_start = Math.ceil(theta_tip / (2 * Math.PI) * gear)
    idx_start = Math.min(quarter - front_steps + 1, Math.max(3, raw_start))
    tan_base = Math.tan(Math.toRadians(angle))

    Math.range(1, front_steps + 1).forEach(k => {

        frac = 1 * (k - 1) / Math.max(1, front_steps - 1)
        idx = Math.round(idx_start + frac * (quarter - idx_start))
        ang_rad = idx / gear * 2 * Math.PI
        dk = arc_r - arc_c * Math.sin(ang_rad)
        pf_ang = Math.toDegrees(Math.atan(ry / dk * tan_base))

        concat(PF, k) idx @ pf_ang : cp() xx1
        concat(G, k) idx @ 90 : dk xx1
    }
    )

    Math.range(1, back_steps + 1).forEach(m => {

        tier_num = front_steps + m
        bfrac = 1 * m / back_steps
        bidx = Math.round(quarter + bfrac * (half - quarter))

        concat(PF, tier_num) bidx @ angle : cp() xx1
        concat(G, tier_num) bidx @ 90 : ry xx1
    }
    )
}

DutchMarquise = (angle = 43, lwr = 1.7, tipRatio = 0.32) => {

    assert(lwr >= 1.25, "Length-to-width ratio must be at least 1.25")
    assert(lwr <= 2.4, "Length-to-width ratio must be at most 2.40")
    assert(tipRatio >= 0.2, "Tip ratio must be at least 0.20")
    assert(tipRatio <= 0.45, "Tip ratio must be at most 0.45")
    assert(gear%4 == 0, "Gear must be divisible by 4 for DutchMarquise")

    cube = 3
    quarter = gear / 4
    ry = 0.6 * size
    rx = ry * lwr
    x_sh = (1 - 2 * tipRatio) * rx
    raw_idx1 = Math.round(Math.atan2(rx - x_sh, ry) / (2 * Math.PI) * gear)
    idx1 = Math.max(4, Math.min(quarter - 4, raw_idx1))
    theta1 = idx1 / gear * 2 * Math.PI
    d1 = x_sh * Math.cos(theta1) + ry * Math.sin(theta1)

    tan_base = Math.tan(Math.toRadians(angle))
    pf1_ang = Math.toDegrees(Math.atan(ry / d1 * tan_base))

    PF1 idx1 @ pf1_ang : cp() xx2
    PF2 quarter @ angle : cp() xx1
    G1 idx1 @ 90 : d1 xx2
    G2 quarter @ 90 : ry xx1
}

Tonneau = (angle = 43, lwr = 1.35, barrel = 0.22) => {

    assert(lwr >= 1.1, "Length-to-width ratio must be at least 1.10")
    assert(lwr <= 1.85, "Length-to-width ratio must be at most 1.85")
    assert(barrel >= 0.1, "Barrel curvature must be at least 0.10")
    assert(barrel <= 0.38, "Barrel curvature must be at most 0.38")
    assert(gear%4 == 0, "Gear must be divisible by 4 for Tonneau")

    cube = 3
    quarter = gear / 4
    ry = 0.6 * size
    rx = ry * lwr
    t_barrel = (barrel - 0.1) / 0.28
    ang_mid = Math.atan2(1.35 * barrel, 0.72 * lwr)
    raw_idx2 = quarter - Math.max(1, Math.round(0.65 * ang_mid / (2 * Math.PI) * gear))
    idx2 = Math.max(2, Math.min(quarter - 1, raw_idx2))
    raw_idx1 = quarter - Math.max(2, Math.round(1.95 * ang_mid / (2 * Math.PI) * gear))
    idx1 = Math.max(1, Math.min(idx2 - 1, raw_idx1))

    theta1 = idx1 / gear * 2 * Math.PI
    theta2 = idx2 / gear * 2 * Math.PI
    cot1 = Math.cos(theta1) / Math.sin(theta1)
    cot2 = Math.cos(theta2) / Math.sin(theta2)
    dy_barrel = (0.12 + 0.28 * t_barrel) * ry
    w_barrel = dy_barrel / (0.45 * cot2 + 0.55 * cot1)
    xa = rx - w_barrel
    xb = xa + 0.45 * w_barrel
    d2 = xa * Math.cos(theta2) + ry * Math.sin(theta2)
    yb = ry - (xb - xa) * cot2
    d1 = xb * Math.cos(theta1) + yb * Math.sin(theta1)

    tan_base = Math.tan(Math.toRadians(angle))
    pf1_ang = Math.toDegrees(Math.atan(ry / rx * tan_base))
    pf2_ang = Math.toDegrees(Math.atan(ry / d1 * tan_base))
    pf3_ang = Math.toDegrees(Math.atan(ry / d2 * tan_base))

    PF1 0 @ pf1_ang : cp() x2
    PF2 idx1 @ pf2_ang : cp() xx2
    PF3 idx2 @ pf3_ang : cp() xx2
    PF4 quarter @ angle : cp() xx1
    G1 0 @ 90 : rx x2
    G2 idx1 @ 90 : d1 xx2
    G3 idx2 @ 90 : d2 xx2
    G4 quarter @ 90 : ry xx1
}

Trapezoid = (angle = 43, lwr = 1.45, taper = 0.62) => {

    assert(lwr >= 1.1, "Length-to-width ratio must be at least 1.10")
    assert(lwr <= 2.2, "Length-to-width ratio must be at most 2.20")
    assert(taper >= 0.4, "Taper ratio must be at least 0.40")
    assert(taper <= 0.85, "Taper ratio must be at most 0.85")
    assert(gear%4 == 0, "Gear must be divisible by 4 for Trapezoid")

    cube = 3
    quarter = gear / 4
    half = gear / 2
    ry = 0.62 * size
    rx = ry * lwr
    phi2 = 0.5 * Math.PI + Math.atan2(1 - taper, 2 * lwr)
    raw_idx2 = Math.round(phi2 / (2 * Math.PI) * gear)
    max_idx2 = quarter + Math.max(2, Math.floor(Math.atan(0.36 / lwr) / (2 * Math.PI) * gear))
    idx2 = Math.max(quarter + 2, Math.min(max_idx2, raw_idx2))
    theta2 = idx2 / gear * 2 * Math.PI
    y_mid = Math.max(- rx * (Math.cos(theta2) / Math.sin(theta2)) + 0.18 * ry, 0.5 * (1 + taper) * ry)
    d2 = y_mid * Math.sin(theta2)

    tan_base = Math.tan(Math.toRadians(angle))
    pf1_ang = Math.toDegrees(Math.atan(ry / rx * tan_base))
    pf2_ang = Math.toDegrees(Math.atan(ry / d2 * tan_base))

    PF1 0 @ pf1_ang : cp() x1
    PF2 idx2 @ pf2_ang : cp() xx1
    PF3 half @ pf1_ang : cp() x1
    G1 0 @ 90 : rx x1
    G2 idx2 @ 90 : d2 xx1
    G3 half @ 90 : rx x1
}

Bullet = (angle = 43, lwr = 1.6, tipRatio = 0.36) => {

    assert(lwr >= 1.25, "Length-to-width ratio must be at least 1.25")
    assert(lwr <= 2.3, "Length-to-width ratio must be at most 2.30")
    assert(tipRatio >= 0.22, "Tip ratio must be at least 0.22")
    assert(tipRatio <= 0.48, "Tip ratio must be at most 0.48")
    assert(gear%4 == 0, "Gear must be divisible by 4 for Bullet")

    cube = 3
    quarter = gear / 4
    half = gear / 2
    ry = 0.6 * size
    d_back = 0.9 * ry * lwr
    x_sh = (1.1 - 2 * tipRatio) * ry * lwr
    raw_idx1 = Math.round(Math.atan2(2 * tipRatio * lwr, 1) / (2 * Math.PI) * gear)
    idx1 = Math.max(4, Math.min(quarter - 4, raw_idx1))
    theta1 = idx1 / gear * 2 * Math.PI
    d1 = x_sh * Math.cos(theta1) + ry * Math.sin(theta1)

    tan_base = Math.tan(Math.toRadians(angle))
    pf1_ang = Math.toDegrees(Math.atan(ry / d1 * tan_base))
    pf3_ang = Math.toDegrees(Math.atan(ry / d_back * tan_base))

    PF1 idx1 @ pf1_ang : cp() xx1
    PF2 quarter @ angle : cp() xx1
    PF3 half @ pf3_ang : cp() x1
    G1 idx1 @ 90 : d1 xx1
    G2 quarter @ 90 : ry xx1
    G3 half @ 90 : d_back x1
}

Coffin = (angle = 43, lwr = 1.65, shoulderRatio = 0.32) => {

    assert(lwr >= 1.3, "Length-to-width ratio must be at least 1.30")
    assert(lwr <= 2.3, "Length-to-width ratio must be at most 2.30")
    assert(shoulderRatio >= 0.22, "Shoulder ratio must be at least 0.22")
    assert(shoulderRatio <= 0.42, "Shoulder ratio must be at most 0.42")
    assert(gear%4 == 0, "Gear must be divisible by 4 for Coffin")

    cube = 3
    quarter = gear / 4
    half = gear / 2
    ry = 0.6 * size
    rx = ry * lwr
    x_sh = (1 - 2 * shoulderRatio) * rx

    min_idx1 = Math.max(6, Math.ceil(Math.atan2(rx - x_sh, 0.72 * ry) / (2 * Math.PI) * gear))
    raw_idx1 = Math.round(Math.atan2(rx - x_sh, 0.48 * ry) / (2 * Math.PI) * gear)
    idx1 = Math.max(min_idx1, Math.min(quarter - 3, raw_idx1))

    max_idx2 = quarter + Math.max(2, Math.floor(Math.atan2(0.75 * ry, rx + x_sh) / (2 * Math.PI) * gear))
    raw_idx2 = quarter + Math.round(Math.atan2(0.62 * ry, rx + x_sh) / (2 * Math.PI) * gear)
    idx2 = Math.max(quarter + 2, Math.min(max_idx2, raw_idx2))

    theta1 = idx1 / gear * 2 * Math.PI
    theta2 = idx2 / gear * 2 * Math.PI
    d2 = x_sh * Math.cos(theta1) + ry * Math.sin(theta1)
    d3 = x_sh * Math.cos(theta2) + ry * Math.sin(theta2)

    tan_base = Math.tan(Math.toRadians(angle))
    pf1_ang = Math.toDegrees(Math.atan(ry / rx * tan_base))
    pf2_ang = Math.toDegrees(Math.atan(ry / d2 * tan_base))
    pf3_ang = Math.toDegrees(Math.atan(ry / d3 * tan_base))

    PF1 0 @ pf1_ang : cp() x1
    PF2 idx1 @ pf2_ang : cp() xx1
    PF3 idx2 @ pf3_ang : cp() xx1
    PF4 half @ pf1_ang : cp() x1
    G1 0 @ 90 : rx x1
    G2 idx1 @ 90 : d2 xx1
    G3 idx2 @ 90 : d3 xx1
    G4 half @ 90 : rx x1
}

Oviform = (angle = 43, lwr = 1.42, eggTaper = 0.22) => {

    assert(lwr >= 1.15, "Length-to-width ratio must be at least 1.15")
    assert(lwr <= 1.9, "Length-to-width ratio must be at most 1.90")
    assert(eggTaper >= 0.1, "Egg taper must be at least 0.10")
    assert(eggTaper <= 0.32, "Egg taper must be at most 0.32")
    assert(gear%4 == 0, "Gear must be divisible by 4 for Oviform")

    cube = 3
    quarter = gear / 4
    half = gear / 2
    ry = 0.56 * size
    ang_front = Math.atan((1 + eggTaper) * lwr)
    ang_back = Math.atan((1 - eggTaper) * lwr)

    idx2 = Math.max(8, Math.min(quarter - 5, Math.round(ang_front / (2 * Math.PI) * gear)))
    idx1 = Math.max(4, idx2 - 5)
    idx3 = Math.min(quarter - 2, idx2 + 4)

    idx5 = Math.max(quarter + 5, Math.min(half - 8, half - Math.round(ang_back / (2 * Math.PI) * gear)))
    idx4 = Math.max(quarter + 2, idx5 - 4)
    idx6 = Math.min(half - 4, idx5 + 5)

    t1 = idx1 / gear * 2 * Math.PI
    t2 = idx2 / gear * 2 * Math.PI
    t3 = idx3 / gear * 2 * Math.PI
    t4 = idx4 / gear * 2 * Math.PI
    t5 = idx5 / gear * 2 * Math.PI
    t6 = idx6 / gear * 2 * Math.PI

    y1 = (0.41 - 0.24 * eggTaper) * ry
    y2 = (0.76 - 0.16 * eggTaper) * ry
    y3 = ry
    y4 = (0.68 + 0.16 * eggTaper) * ry
    y5 = (0.31 + 0.24 * eggTaper) * ry

    dx1 = y1 * Math.tan(t1)
    dx2 = (y2 - y1) * Math.tan(t2)
    dx3 = (y3 - y2) * Math.tan(t3)
    dx4 = - (y3 - y4) * Math.tan(t4)
    dx5 = - (y4 - y5) * Math.tan(t5)
    dx6 = - y5 * Math.tan(t6)

    x_front = dx1 + dx2 + dx3
    x_back = dx4 + dx5 + dx6
    x0 = 0.5 * (x_front + x_back)

    x1 = x0 - dx1
    x2 = x1 - dx2
    x3 = x2 - dx3
    x4 = x3 - dx4
    x5 = x4 - dx5

    d1 = x1 * Math.cos(t1) + y1 * Math.sin(t1)
    d2 = x2 * Math.cos(t2) + y2 * Math.sin(t2)
    d3 = x3 * Math.cos(t3) + y3 * Math.sin(t3)
    d4 = x4 * Math.cos(t4) + y4 * Math.sin(t4)
    d5 = x5 * Math.cos(t5) + y5 * Math.sin(t5)
    d6 = - x0 * Math.cos(t6)

    tan_base = Math.tan(Math.toRadians(angle))
    pf1_ang = Math.toDegrees(Math.atan(ry / d1 * tan_base))
    pf2_ang = Math.toDegrees(Math.atan(ry / d2 * tan_base))
    pf3_ang = Math.toDegrees(Math.atan(ry / d3 * tan_base))
    pf4_ang = Math.toDegrees(Math.atan(ry / d4 * tan_base))
    pf5_ang = Math.toDegrees(Math.atan(ry / d5 * tan_base))
    pf6_ang = Math.toDegrees(Math.atan(ry / d6 * tan_base))

    PF1 idx1 @ pf1_ang : cp() xx1
    PF2 idx2 @ pf2_ang : cp() xx1
    PF3 idx3 @ pf3_ang : cp() xx1
    PF4 idx4 @ pf4_ang : cp() xx1
    PF5 idx5 @ pf5_ang : cp() xx1
    PF6 idx6 @ pf6_ang : cp() xx1
    G1 idx1 @ 90 : d1 xx1
    G2 idx2 @ 90 : d2 xx1
    G3 idx3 @ 90 : d3 xx1
    G4 idx4 @ 90 : d4 xx1
    G5 idx5 @ 90 : d5 xx1
    G6 idx6 @ 90 : d6 xx1
}