System macros source
These CAM-related macros are compiled directly into the interpreter. The listing below is the literal define ... { ... } block the runtime parses.
define Round(angle=43, sym=8) {
// Simple round preform with adjustable symmetry.
// Parameters:
// angle: Pavilion angle for the round preform.
// sym: Symmetry count for the girdle loop.
assert ${sym} > 2 "Symmetry must be greater than 2."
assert GEAR % ${sym} == 0 "Gear index should be a multiple of the symmetry count."
G1 0 @ 90 : size x ${sym}
P1 0 @ ${angle} : cp
}
define Oval(angle=45, lwr=1.2, segmentsPerQuad=5) {
assert ${lwr} >= 1 "Length-to-width ratio must be >= 1."
assert ${segmentsPerQuad} >= 2 "segmentsPerQuad must be at least 2."
assert GEAR % 4 == 0 "Gear index should be a multiple of 4."
let width = 1
let length = ${lwr}
let rx = length / 2
let ry = width / 2
let quarter = GEAR / 4
let steps = ${segmentsPerQuad}
let stepSize = quarter / steps
let prevIdx = -1
let prevC = 0
let prevS = 0
let prevD = 0
let h = cos(${angle} * 3.14 / 90)
for k in 0..=steps {
let idx = round(k * stepSize) % GEAR
let ang = (idx / GEAR) * 2 * 3.14
let c = cos(ang)
let s = sin(ang)
let d = sqrt(rx * rx * c * c + ry * ry * s * s)
if prevIdx != -1 {
let det = prevC * s - prevS * c
let x = (prevD * s - d * prevS) / det
let y = (d * prevC - prevD * c) / det
concat(O,k) prevIdx : pt(x, y, -h) : cp xx 2 "Cut to center point"
if k == steps {
concat(O,k+1) (GEAR / 4) : pt(x, y, -h) : cp xx 2 "Cut to center point"
}
}
prevIdx = idx
prevC = c
prevS = s
prevD = d
}
G1 0 @ 90 : size "Cut to stone length"
for k in 2..=steps {
let idx = round((k - 1) * stepSize) % GEAR
concat(G,k) idx @ 90 : mp(concat(G,k-1), concat(O,k-1)) "Level girdle"
}
concat(G,steps+1) (GEAR / 4) @ 90 : mp(concat(G,steps), concat(O,steps)) "Level girdle"
}
define Rect(lwr=1.5, angle=45) {
// Creates a rectangular girdle shape
assert ${lwr} >= 1.0 "Length-to-width ratio must be >= 1."
assert GEAR % 4 == 0 "Gear index should be a multiple of 4."
let beta = rad2deg(atan(tan(deg2rad(${angle})) / ${lwr}))
let corner_index = GEAR / 4
PF1 corner_index @ beta : cp x 2
PF2 0 @ ${angle} : cp
G1 corner_index @ 90 : 0.5
G2 0 @ 90 : mp(G1, PF1, PF2)
}
define RectTr(lwr=1.4, angle=45, truncation=0.3, offset=0) {
// Rectangular girdle with truncated corners.
assert ${lwr} >= 1.0 "Length-to-width ratio must be >= 1."
assert ${truncation} > 0 "Truncation must be > 0."
assert ${truncation} <= 1 "Truncation should stay within 0-1."
assert GEAR % 4 == 0 "Gear index should be a multiple of 4."
let beta = rad2deg(atan(tan(deg2rad(${angle})) / ${lwr}))
let corner_index = GEAR / 4
PF1 corner_index @beta : cp xx 2
PF2 0 @ ${angle} : cp
G1 corner_index @ 90 : 0.5
G2 0 @ 90 : mp(G1, PF1, PF2)
PF3 (GEAR / 8 + ${offset})
: cp
: ep(edge(PF1:corner_index, G1:corner_index), ${truncation} / 2.0)
G3 (floor(GEAR / 8) + ${offset}) @ 90 : mp(G2, PF3, PF2)
}
define RectDblTr(lwr, angle, 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} <= 2 "Second truncation should stay within 0-2."
let corner_index = GEAR / 4
let split_index = floor(GEAR / 8) + ${offset}
let outer_ratio = ${first_truncation} / 2.0
let inner_ratio = ${second_truncation} / 2.0
PF1 (corner_index + ${offset}) @ rad2deg(atan(tan(deg2rad(${angle})) / ${lwr})) : cp x 2
PF2 ${offset} @ ${angle} : cp x 2
G1 (corner_index + ${offset}) @ 90 : size x 2
G2 ${offset} @ 90 : mp(G1, PF1, PF2) x 2
PF3 (GEAR / 8 + ${offset})
: cp
: ep(edge(PF1:(corner_index + ${offset}), G1:(corner_index + ${offset})), outer_ratio) xx2
G3 (floor(GEAR / 8) + ${offset}) @ 90 : mp(G2, PF3, PF2)
PF4 (floor(3 * GEAR / 16) + ${offset})
: cp
: ep(edge(PF3:split_index, G3:split_index), inner_ratio) xx2
PF5 (floor(GEAR / 16) + ${offset})
: cp
: ep(edge(PF3:split_index, G3:split_index), 1.0 - inner_ratio) xx2
G4 (floor(GEAR / 16) + ${offset}) @ 90 : mp(G3, PF5) xx2
G5 (floor(3 * GEAR / 16) + ${offset}) @ 90 : mp(G3, PF4) xx2
}
define SquareTr(angle, truncation=0.3, offset=0) {
assert ${truncation} >= 0 "Truncation must be non-negative."
assert ${truncation} <= 2 "Truncation should stay within 0-2."
assert GEAR % 4 == 0 "Gear index should be a multiple of 4."
let side_index = ${offset}
let corner_index = side_index + GEAR / 8
PF1 side_index @ ${angle} : cp x 4
G1 side_index @ 90 : size x 4
PF2 corner_index
: cp
: ep(edge(PF1:side_index, G1:side_index), 1.0 - ${truncation} / 2.0) x 4
G2 corner_index @ 90 : mp(G1, PF2) x 4
}
define SquareCushTr(cushion=1, angle, truncation=0.4) {
assert ${cushion} >= 1 "Index offset must be 1 or more."
assert GEAR % 4 == 0 "Gear index should be a multiple of 4."
let side_index = ${cushion}
let corner_index = GEAR / 8
G1 side_index @ 90 : size xx4
PF1 side_index @ ${angle} : cp xx4
PF2 corner_index
: cp
: ep(edge(PF1:side_index, G1:side_index), 1 - ${truncation} / 2.0) x4
G2 corner_index @ 90 : mp(G1,PF2,PF1)
}
define PentCushTr(offset=1, angle, truncation=0.3) {
assert ${offset} >= 1 "Index offset must be at least 1."
assert ${truncation} >= 0 "Truncation must be non-negative."
assert ${truncation} <= 1 "Truncation should stay within 0-1."
assert GEAR % 10 == 0 "Gear index should be a multiple of 10."
let side_index = ${offset}
let corner_index = GEAR / 10
G1 side_index @ 90 : size xx5
PF1 side_index @ ${angle} : cp xx5
PF2 corner_index
: cp
: ep(edge(PF1:side_index, G1:side_index), 1.0 - ${truncation}) xx5
G2 corner_index @ 90 : mp(G1, PF2) xx5
}
define Shield(angle=45) {
// Mirrored shield outline with threefold symmetry.
// Parameters:
// angle: Pavilion angle for the shield facets.
assert GEAR % 6 == 0 "Gear index should be a multiple of 6."
P1 6 @ ${angle} : cp xx 3
G1 6 @ 90 : size xx 3
}
define TriTr(truncation=0.25, angle) {
assert ${truncation} >= 0 "Truncation must be non-negative."
assert ${truncation} < 2 "Truncation must stay below 2."
assert GEAR % 6 == 0 "Gear index should be a multiple of 6."
PF1 0 @ ${angle} : cp x 3
G1 0 @ 90 : 0.7 x 3
PF2 GEAR / 6
: cp
: ep(edge(PF1:0, G1:0), 1 - ${truncation} / 2) x 3
G2 GEAR / 6 @ 90 : mp(G1, PF1, PF2)
}
define TriCushTr(truncation=0.25, angle, cushion=1) {
assert ${truncation} >= 0 "Truncation must be non-negative."
assert ${truncation} < 2 "Truncation must stay below 2."
assert ${cushion} >= 0 "Cushion offset must be non-negative."
assert GEAR % 6 == 0 "Gear index should be a multiple of 6."
PF1 ${cushion} @ ${angle} : cp xx3
G1 ${cushion} @ 90 : 0.7 xx3
PF2 GEAR / 6
: cp
: ep(edge(PF1:${cushion}, G1:${cushion}), 1 - ${truncation} ) x 3
G2 GEAR / 6 @ 90 : mp(G1, PF1, PF2)
}
define TriCurved(angle=45, c1=2,c2=4) {
// Trilliant Cut curved by amount c1 and c2.
set cube 3.4
let i1 = ${c1}
let i2 = ${c2}
assert i1 < i2 "c1 < c2"
assert GEAR % i1 == 0 "c1 must be divisible by gear"
assert GEAR % i2 == 0 "c2 must be divisible by gear"
PF1 i1 @${angle}: cp xx3
G1 i1 @90 : size
PF2 i2 : cp : ep(edge(PF1:i1,G1:i1),0.5) "Cut to centerpoint"
G2 i2 @90 : mp(PF1,PF2,G1)
}