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

Expressions

Note: Most designs never touch custom expressions. Skip this page unless you are building CAM outline macros or a highly specialised cut that needs custom math.

Expressions are the pieces that fit inside statements: numbers, point helpers, comparisons, and function calls.

Numbers, booleans, and strings

  • Numbers accept decimals and scientific notation (42, 0.18, 1.5e-2).
  • Booleans are just true and false.
  • Strings live inside double quotes and support escapes like \" and \n. You will mostly see them in set name or macro bodies.

Optimizable numbers use square brackets—[41.8, 38, 44]—to record a starting value and optional minimum/maximum bounds.

Arrays and indexing

Braces ({ and }) create an array literal that captures a list of numeric expressions evaluated right away. Example: let tiers = { 41.8, 32.5, [28.0] }. Arrays are zero-based, so tiers[0] returns the first entry, tiers[1] the next, and so on. Every access is bounds-checked—tiers[3] would halt the interpreter if the array only stored three items—so you get fast feedback when a loop walks too far.

Handy functions

Call functions by name with parentheses. The most common helpers are:

  • sin, cos, tan, asin, acos, atan, atan2
  • deg2rad, rad2deg
  • sqrt, abs, log, log10, floor, round

Geometry Functions

These functions return geometric properties of the stone as it currently exists. They are useful for optimization targets or conditional logic.

  • crownHeightPercentage(): Returns the crown height as a percentage of width.
  • pavilionDepthPercentage(): Returns the pavilion depth as a percentage of width.
  • girdleThicknessPercentage(): Returns the average girdle thickness as a percentage of width.
  • lengthWidthRatio(): Returns the length-to-width ratio of the stone.
  • facetCount(): Returns the total number of facets cut so far.

Conditionals

Use if <expression> { ... } else { ... } to branch inside macros or loops. Any non-zero, finite value counts as true. The else block is optional.

Point helpers

Point helpers return locations in space and slot neatly into facet commands or variables. Store them with let point = mp(G1) and reuse as often as you like. The edge(...) helper is the lone exception: it returns two points, so you must destructure it (let left, right = edge(P1:0, P1:12)) instead of assigning the whole edge to a single identifier. When you need deeper explanations or syntax variations, head to the dedicated Point Helper Reference for cp, gp, gpl, mp, ep, fred, prz, pt, edge, and the at attachment clause.

Everything in motion

Paste this snippet into the studio to see several expression types working together:

set name "Expression Tour"
set gear 96

P1 0 @ 41.8 : cp x8
P3 1 @ (43 - 1.2) : cp  // a parenthesized expression is needed here.

G1 0 @ 90 : size x16
C1 0 @ deg2rad(rad2deg(32.0) + 0.2) : mp(G1,P1)+ girdle
C2 0 @ 28.0 : ep(edge(C1:0, C1:6), 0.5)

let shoulder = mp(P1, P3, G1) at (12, 39)
show shoulder green
mp() examples